Ensure custom variants using @scope generate working CSS#20344
Ensure custom variants using @scope generate working CSS#20344UditDewan wants to merge 2 commits into
@scope generate working CSS#20344Conversation
Custom variants defined with an @scope at-rule emitted the @scope block nested inside the generated utility class instead of wrapping it, so the resulting CSS had no effect in browsers. Treat @scope like other conditional at-rules (@media, @supports, @container) when resolving nesting, so it is hoisted above the generated style rules. Fixes tailwindlabs#18961
|
Caution Review failedAn error occurred during the review process. Please try again later. 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. Comment |
Confidence Score: 5/5Safe to merge — the change is a two-line addition to two well-understood constant sets, and the tests cover the key block-form paths end-to-end through Lightning CSS. The fix is minimal and targeted: No files require special attention. The only substantive code change is in Reviews (1): Last reviewed commit: "Add changelog entry" | Re-trigger Greptile |
|
Caution Review failedAn error occurred during the review process. Please try again later. 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. Comment |
Summary
Fixes #18961
Custom variants defined with an
@scopeat-rule currently emit the@scopeblock nested inside the generated utility class instead of wrapping it:Browsers don't apply
@scopein this nested position, so the utility has no effect. Additionally, when the output goes through Lightning CSS the declarations inside the nested@scopeare dropped entirely, leaving an empty@scope (.checkout) {}block.Other conditional at-rules used in custom variants (
@media,@supports,@container,@starting-style) are hoisted above the generated style rule when nesting is resolved. This PR adds@scopeto the set of hoistable at-rules (and to the droppable-if-empty set, since an empty@scopeblock has no effect), so the same custom variant now produces:This works with both the block form (
@custom-variant name { @scope (…) { @slot; } }) and the shorthand form (@custom-variant name (@scope (…));), and preservesto (…)limits.Test plan
index.test.tscovering custom variants using@scope, with and without ato (…)limit (these go through the Lightning CSS optimize step, verifying the output survives minification).ast.test.tsverifying@scopeis hoisted out of style rules during nesting resolution.vitest runinpackages/tailwindcss: 41 test files, 4874 tests passed.