Skip to content

Commit ea49ac9

Browse files
benfaceclaude
authored andcommitted
Don't treat different @scope variants as the same when canonicalizing
Variants that generate `@scope` rules wrap them in `context` nodes since #20369, and `toCss` prints `context` nodes as an empty string. So every `@scope` variant had the same signature, and canonicalization rewrote them to whichever `@scope` variant came first. Unwrap the `context` nodes before computing the signature. Fixes #20714 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent bbd48b6 commit ea49ac9

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
- Canonicalization: don't replace `@scope` variants with unrelated `@scope` variants (e.g. `[@scope_(.card)]:flex` no longer becomes `in-blue:flex`)

‎packages/tailwindcss/src/canonicalize-candidates.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,29 @@ describe('regressions', () => {
20992099
])
21002100
expect(compare).not.toHaveBeenCalled()
21012101
})
2102+
2103+
test('does not treat different `@scope` variants as the same', async () => {
2104+
let designSystem = await __unstable__loadDesignSystem(
2105+
css`
2106+
@tailwind utilities;
2107+
@custom-variant in-blue {
2108+
@scope ([data-theme='blue']) to ([data-theme]) {
2109+
@slot;
2110+
}
2111+
}
2112+
`,
2113+
{ base: __dirname },
2114+
)
2115+
2116+
expect(designSystem.canonicalizeCandidates(['[@scope_(.card)]:flex'])).toEqual([
2117+
'[@scope_(.card)]:flex',
2118+
])
2119+
expect(
2120+
designSystem.canonicalizeCandidates([
2121+
"[@scope_([data-theme='blue'])_to_([data-theme])]:flex",
2122+
]),
2123+
).toEqual(['in-blue:flex'])
2124+
})
21022125
})
21032126

21042127
describe('normalizeEscapes', () => {

‎packages/tailwindcss/src/canonicalize-candidates.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3402,8 +3402,15 @@ function createVariantSignatureCache(
34023402

34033403
// Canonicalize selectors to their minimal form
34043404
walk(ast, (node) => {
3405+
// Variants that generate `@scope` rules wrap them in `context` nodes,
3406+
// which `toCss` doesn't print. Unwrap them so the signature includes
3407+
// the `@scope` rule.
3408+
if (node.kind === 'context') {
3409+
return WalkAction.Replace(node.nodes)
3410+
}
3411+
34053412
// At-rules
3406-
if (node.kind === 'at-rule') {
3413+
else if (node.kind === 'at-rule') {
34073414
// Normalize dimensions such that equivalent values in different
34083415
// units are considered the same. E.g.: with a root font size of
34093416
// `16px`, `@media (width >= 64rem)` and `@media (width >= 1024px)`

0 commit comments

Comments
 (0)