Skip to content

Canonicalization: don't unwrap :is(…) around a selector list in variant signatures - #20737

Open
RobinMalfait wants to merge 1 commit into
mainfrom
robin/fix-is-list-unwrap-in-variant-signatures
Open

RobinMalfait wants to merge 1 commit into
mainfrom
robin/fix-is-list-unwrap-in-variant-signatures

Conversation

@RobinMalfait

Copy link
Copy Markdown
Contributor

This PR fixes a bug where canonicalizeCandidates replaces an arbitrary variant with a custom variant that emits different CSS.

createVariantSignatureCache replaces :is(…) with its child when it has a single child. That child can be a selector list. Then &:is(.foo,.bar) becomes &.foo,.bar. In nesting, that means &.foo, & .bar, so .bar turns into a descendant.

@custom-variant foo (&.foo, .bar);

Before this PR, [&:is(.foo,.bar)]:flex canonicalized to foo:flex, but the two emit different CSS:

.foo\:flex.foo, .foo\:flex .bar { display: flex; }
.\[\&\:is\(\.foo\,\.bar\)\]\:flex:is(.foo, .bar) { display: flex; }

[&:is(.foo,_.bar)]:flex and [&_:is(.foo,.bar)]:flex had the same problem.

Now we keep :is(…) when its single child is a selector list. :is(.foo) → .foo and :is(*:hover) → :hover still unwrap.

With this fix, [&:is(.foo,.bar)]:flex canonicalizes to [.foo,.bar]:flex. Both emit &:is(.foo, .bar).

Test plan

  • Added a regression test in canonicalize-candidates.test.ts. It fails without the fix (expected [ 'foo-or-bar:flex' ] to deeply equal [ '[.foo,.bar]:flex' ]).
  • vitest run in packages/tailwindcss passes.
  • pnpm run build and pnpm changelog check pass.

`createVariantSignatureCache` replaced `:is(…)` with its single child. When
that child is a selector list, `&:is(.foo,.bar)` became `&.foo,.bar`, which
in nesting means `&.foo, & .bar`. So `[&:is(.foo,.bar)]:flex` got the same
signature as a `@custom-variant foo (&.foo, .bar)`, and canonicalized to it,
while the two emit different CSS.

Keep `:is(…)` when its single child is a `list` node. `:is(.foo)` → `.foo`
and `:is(*:hover)` → `:hover` still unwrap.
@RobinMalfait
RobinMalfait requested a review from a team as a code owner November 20, 2026 17:42
@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Reviews (1) · Last reviewed commit: "Don't unwrap `:is(…)` around a selector ..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The canonicalizer now unwraps :is(...) only when it contains a single non-list selector. Selector lists remain inside :is(...). Regression tests cover grouped and whitespace-separated lists, a descendant-selector form, and a single selector. A changelog entry describes the correction.

Severity of issue fixed: Low

Merge Risk: Minimal · up to 84055

Variant canonicalization no longer unwraps :is(...) around selector lists, so [&:is(.foo,.bar)] is no longer replaced with a variant that emits different CSS. Single selectors are still unwrapped. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the specific change: canonicalization no longer unwraps :is(…) when its single child is a selector list. The raw summary and objectives describe the same change in canonicalize-candi…
Description check Passed The description explains the bug (canonicalizeCandidates turning an arbitrary variant into a custom variant that emits different CSS), the cause in createVariantSignatureCache, the fix that keeps :is(…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the specific change: canonicalization no longer unwraps :is(…) when its single child is a selector list. The raw summary and objectives describe the same change in canonicalize-candidates.ts, its test, and the changelog entry. The title is long (84 characters) but it is accurate and specific.

Full details: Description check

Explanation

The description explains the bug (canonicalizeCandidates turning an arbitrary variant into a custom variant that emits different CSS), the cause in createVariantSignatureCache, the fix that keeps :is(…) around selector lists, and the test plan. It matches the changeset and the objectives.

  • 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.

Share

Recent 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: cf3b68f8-bb7d-4572-b694-5467bccc8217
Commits

Reviewing files that changed from the base of the PR and between 511c82a and 8405551.

Files selected for processing: 3

  • .changelog/canonicalize-is-selector-list.md
  • packages/tailwindcss/src/canonicalize-candidates.test.ts
  • packages/tailwindcss/src/canonicalize-candidates.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant