You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Canonicalization: don't treat different @scope variants as the same - #20715
Since #20369, variants that generate @scope rules wrap them in context nodes. The canonicalizer computes a variant's signature by printing the @apply result with toCss, which prints context nodes as an empty string. So every @scope variant had the signature .x {}, the same as a variant that generates nothing, and canonicalization replaced it with whichever of those variants came first (e.g. [@scope_(.card)]:flex → in-blue:flex, where in-blue scopes to [data-theme='blue']).
This PR unwraps the context nodes before computing the signature, so it includes the @scope rule again, as in v4.3.3.
Test plan
Added a regression test: [@scope_(.card)]:flex stays as is next to an unrelated @scope custom variant, and the equivalent arbitrary variant still canonicalizes to that custom variant. The first assertion fails without this PR.
vitest run --project tailwindcss passes.
In our design system, which has many @scope variants, @scope-has-nested-focus-visible/tab-set-panel:outline canonicalized to @scope-not-has-first:outline before this PR, and stays as is after.
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
No actionable comments were generated in the recent review.
Walkthrough
Variant signature generation now unwraps context nodes before serialization, so generated @scope rules are included in signatures. At-rule parameter normalization preserves whitespace that distinguishes descendant selectors from compound selectors. Regression tests cover scope matching, selector spacing, escaped characters, and media-query canonicalization. A changelog entry documents the fixes.
Severity of issue fixed: Medium
Merge Risk: Minimal · previous review 4adbc
Canonicalization now keeps different @scope variants and descendant versus compound selectors distinct, and regression tests cover these cases. No concrete merge-blocking risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: canonicalization no longer treats different @scope variants as the same. The raw summary confirms the change unwraps context nodes so @scope rules contribute to …
Description check
The description states the problem (since #20369, context nodes print as empty strings, so every @scope variant gets the signature .x {}), the fix (unwrap context nodes before computing the si…
Linked Issues check
[#20714] requires that variants generating different @scope CSS are not canonicalized as equivalent. The whole-PR diff (merge base bbd48b6 to head 4adbce2) adds a context unwrap in `createVarian…
Out of Scope Changes check
Changed files in the whole-PR diff are packages/tailwindcss/src/canonicalize-candidates.ts, its test file, and .changelog/canonicalize-scope-variants.md. The context unwrap directly implements […
Full details: Title check
Explanation
The title names the main change: canonicalization no longer treats different @scope variants as the same. The raw summary confirms the change unwraps context nodes so @scope rules contribute to variant signatures, and the objectives describe the same fix for issue #20714. The title is specific and concise.
Full details: Description check
Explanation
The description states the problem (since #20369, context nodes print as empty strings, so every @scope variant gets the signature .x {}), the fix (unwrap context nodes before computing the signature), and the test plan. It links issue #20714. It matches the changeset and the objectives.
Full details: Linked Issues check
Explanation
[#20714] requires that variants generating different @scope CSS are not canonicalized as equivalent. The whole-PR diff (merge base bbd48b6 to head 4adbce2) adds a context unwrap in createVariantSignatureCache (packages/tailwindcss/src/canonicalize-candidates.ts). The unwrap runs before toCss, so @scope rules generated inside context nodes enter the variant signature. The PR adds a regression test. The test checks that [@scope_(.card)]:flex stays unchanged next to the in-blue custom variant, and that the equivalent arbitrary variant still canonicalizes to in-blue:flex. The current diff also replaces blanket space removal in at-rule params with normalizeAtRuleParamsWhitespace. This keeps descendant combinators in @scope and @supports selector(...) significant, so .foo .bar and .foo.bar no longer share a signature. The code supports the claimed behavior. The author-reported vitest run --project tailwindcss result was not re-executed in this review. Incremental changes since the previous reviewed heads were assessed through the whole-PR diff, which the previous assessment also used.
Full details: Out of Scope Changes check
Explanation
Changed files in the whole-PR diff are packages/tailwindcss/src/canonicalize-candidates.ts, its test file, and .changelog/canonicalize-scope-variants.md. The context unwrap directly implements [#20714]. The normalizeAtRuleParamsWhitespace change affects signature generation for all at-rule variants. It addresses the same defect class as the issue: distinct variants compare as equal. Its descendant-combinator handling is tied to @scope and selector-bearing at-rules. The hex-escape handling in the commit messages is tied to signature mismatches of equivalent selectors, and it has tests. The @media/@container colon rule, which makes (pointer :fine) and (pointer:fine) canonicalize alike, is a related normalizer change with its own test and changelog entry. Residual risk: the normalizer affects every at-rule variant. Its effect on unrelated at-rule canonicalization is verified only through the added tests.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
Major · Preserve descendant combinators in @scope parameters. · canonicalize-candidates.ts:3421-3422
packages/tailwindcss/src/canonicalize-candidates.ts:3421-3422 Major · Functional Correctness · Quick win
Preserve descendant combinators in @scope parameters.
The new unwrapping path exposes custom @scope rules to this whitespace removal. A custom variant using @scope (.card.title) now shares a signature with [@scope_(.card_.title)]:flex, because .card .title becomes .card.title. Canonicalization can therefore replace the arbitrary variant with a custom variant that has a different scope.
Preserve meaningful whitespace in @scope parameters. Add a regression test that distinguishes these two selectors.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 00098583-352f-4b1e-b8eb-638a105c762c
Commits
Reviewing files that changed from the base of the PR and between bbd48b6 and ea49ac9.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Files skipped from review as they are similar to previous changes: 1
.changelog/canonicalize-scope-variants.md
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
A hex escape like `\2b` consumes one whitespace character after it. So
`.foo\2b .bar` is a descendant selector, but `.foo\2b .bar` is the
compound `.foo\+.bar`. The whitespace normalization only consumed the
first character after the backslash, then collapsed both spaces into one,
so the two selectors got the same variant signature.
Reported by CodeRabbit on tailwindlabs#20715.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
The whitespace that ends a hex escape is only needed when a hex digit or
another space follows it. Keeping it everywhere meant that
`.foo\2b>.bar` and `.foo\2b >.bar` got different variant signatures,
so `[@scope_(.foo\2b_>.bar)]:flex` was no longer replaced by an
equivalent custom variant.
Reported by Greptile on tailwindlabs#20715.
RobinMalfait
added a commit
to benface/tailwindcss
that referenced
this pull request
Nov 17, 2026
CSS treats CRLF as one newline, so a hex escape consumes both
characters. The whitespace normalization consumed only the CR, and the
LF became a descendant combinator. So a plugin variant like
`@scope (.foo\2b\r\n.bar) to (.limit)` (a compound selector) got the same
signature as `[@scope_(.foo\2b__.bar)_to_(.limit)]:flex` (a descendant
selector).
The stylesheet parser already normalizes CRLF, so only plugin variants
keep it in their params.
Reported by CodeRabbit on tailwindlabs#20715.
A hex escape like `\2b` consumes one whitespace character after it. So
`.foo\2b .bar` is a descendant selector, but `.foo\2b .bar` is the
compound `.foo\+.bar`. The whitespace normalization only consumed the
first character after the backslash, then collapsed both spaces into one,
so the two selectors got the same variant signature.
Reported by CodeRabbit on tailwindlabs#20715.
RobinMalfait
added a commit
to benface/tailwindcss
that referenced
this pull request
Nov 17, 2026
The whitespace that ends a hex escape is only needed when a hex digit or
another space follows it. Keeping it everywhere meant that
`.foo\2b>.bar` and `.foo\2b >.bar` got different variant signatures,
so `[@scope_(.foo\2b_>.bar)]:flex` was no longer replaced by an
equivalent custom variant.
Reported by Greptile on tailwindlabs#20715.
RobinMalfait
added a commit
to benface/tailwindcss
that referenced
this pull request
Nov 17, 2026
CSS treats CRLF as one newline, so a hex escape consumes both
characters. The whitespace normalization consumed only the CR, and the
LF became a descendant combinator. So a plugin variant like
`@scope (.foo\2b\r\n.bar) to (.limit)` (a compound selector) got the same
signature as `[@scope_(.foo\2b__.bar)_to_(.limit)]:flex` (a descendant
selector).
The stylesheet parser already normalizes CRLF, so only plugin variants
keep it in their params.
Reported by CodeRabbit on tailwindlabs#20715.
Variants that generate `@scope` rules wrap them in `context` nodes since tailwindlabs#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.
Fixestailwindlabs#20714
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The variant signature removed every space from at-rule params, so
`@scope (.foo .bar)` and `@scope (.foo.bar)` got the same signature, and
`[@scope_(.foo_.bar)]:flex` was replaced with a variant for `.foo.bar`.
`@supports selector(…)` had the same problem.
Now only whitespace next to delimiters is removed (e.g. `(width >= 64rem)`
→ `(width>=64rem)`), and other whitespace is collapsed to a single space.
This happens in a single pass that keeps strings and escapes as-is.
In `@scope (.foo\+ .bar)`, the `+` is part of the class name and the space
is a descendant combinator. The whitespace normalization treated the
escaped `+` as a delimiter and dropped the space, so the signature matched
`@scope (.foo\+.bar)`.
Whitespace before a `:` is kept in at-rule params, because it can be a
descendant combinator in a selector (`.foo :hover`). `@media` and
`@container` params can't contain selectors, so `(pointer :fine)` and
`(pointer:fine)` are the same there. This lets `[@media_(pointer_:fine)]:flex`
canonicalize to `pointer-fine:flex` again.
A hex escape like `\2b` consumes one whitespace character after it. So
`.foo\2b .bar` is a descendant selector, but `.foo\2b .bar` is the
compound `.foo\+.bar`. The whitespace normalization only consumed the
first character after the backslash, then collapsed both spaces into one,
so the two selectors got the same variant signature.
Reported by CodeRabbit on tailwindlabs#20715.
The whitespace that ends a hex escape is only needed when a hex digit or
another space follows it. Keeping it everywhere meant that
`.foo\2b>.bar` and `.foo\2b >.bar` got different variant signatures,
so `[@scope_(.foo\2b_>.bar)]:flex` was no longer replaced by an
equivalent custom variant.
Reported by Greptile on tailwindlabs#20715.
CSS treats CRLF as one newline, so a hex escape consumes both
characters. The whitespace normalization consumed only the CR, and the
LF became a descendant combinator. So a plugin variant like
`@scope (.foo\2b\r\n.bar) to (.limit)` (a compound selector) got the same
signature as `[@scope_(.foo\2b__.bar)_to_(.limit)]:flex` (a descendant
selector).
The stylesheet parser already normalizes CRLF, so only plugin variants
keep it in their params.
Reported by CodeRabbit on tailwindlabs#20715.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20714
Summary
Since #20369, variants that generate
@scoperules wrap them incontextnodes. The canonicalizer computes a variant's signature by printing the@applyresult withtoCss, which printscontextnodes as an empty string. So every@scopevariant had the signature.x {}, the same as a variant that generates nothing, and canonicalization replaced it with whichever of those variants came first (e.g.[@scope_(.card)]:flex→in-blue:flex, wherein-bluescopes to[data-theme='blue']).This PR unwraps the
contextnodes before computing the signature, so it includes the@scoperule again, as in v4.3.3.Test plan
[@scope_(.card)]:flexstays as is next to an unrelated@scopecustom variant, and the equivalent arbitrary variant still canonicalizes to that custom variant. The first assertion fails without this PR.vitest run --project tailwindcsspasses.@scopevariants,@scope-has-nested-focus-visible/tab-set-panel:outlinecanonicalized to@scope-not-has-first:outlinebefore this PR, and stays as is after.🤖 Generated with Claude Code