Do not wrap color-mix in a @supports rule if one already exists#19450
Do not wrap color-mix in a @supports rule if one already exists#19450thecrypticace merged 8 commits intotailwindlabs:mainfrom
color-mix in a @supports rule if one already exists#19450Conversation
When color-mix contains CSS variables that cannot be resolved (e.g., var(--tw-gradient-from)), the polyfill should not create a fallback since the transpiled version would be meaningless. Currently, the polyfill incorrectly attempts to inline these variables, resulting in broken CSS where color-mix calls are replaced with just the variable references.
WalkthroughThe PR updates the Tailwind CSS AST transform to detect Pre-merge checks✅ Passed checks (2 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/tailwindcss/src/ast.ts(2 hunks)packages/tailwindcss/src/index.test.ts(1 hunks)packages/tailwindcss/src/utilities.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/tailwindcss/src/index.test.ts (2)
packages/tailwindcss/src/test-utils/run.ts (1)
compileCss(4-11)integrations/utils.ts (1)
css(519-519)
🔇 Additional comments (4)
packages/tailwindcss/src/ast.ts (2)
296-304: Logic is correct, but depends on the fix for lines 243-253.The condition
!context.supportsColorMixcorrectly prevents collectingcolor-mixdeclarations for polyfill generation when already inside a@supports (color: color-mix(...))block. This avoids the double-wrapping issue described in the PR.However, this change depends on the
supportsColorMixflag being correctly set and propagated. As noted in the previous comment, the implementation at lines 243-253 appears to have an issue that may prevent the@supportsnode from being included in the output.
243-253: No action needed—the implementation is correct.The
@supportsblock is intentionally not preserved from the input. When the transform encounters@supports (color: color-mix(...)), it processes children with thesupportsColorMix: truecontext flag (preventing them from needing individual polyfills since they're already protected by the browser check), then discards the original node. Later, new@supportsblocks are generated (line 622) as part of the polyfill mechanism for declarations that actually need them. Tests confirm the output includes@supportsblocks as expected, generated fresh during the polyfill creation phase.packages/tailwindcss/src/index.test.ts (1)
5816-5836: Test title mismatch: actual title is "should not apply color-mix optimizations when already inside a @supports at-rule that checks for color-mix"The test code is correct and properly verifies that no additional fallback is generated when
color-mixis already nested in an@supportsblock. The existing test suite provides comprehensive coverage of color-mix polyfill behavior across 14 test cases. While additional edge case tests for deeply nested@supportsor multiplecolor-mixcalls within the same block could be valuable, the current test validates the intended behavior correctly.Likely an incorrect or invalid review comment.
packages/tailwindcss/src/utilities.ts (1)
197-205: LGTM! Clean utility functions for optimize comment handling.The regex pattern and helper functions are well-implemented:
- Pattern correctly matches the
/* tw:optimize */comment at the start with proper escapingcontainsOptimizeComment()provides a clean boolean checkremoveOptimizeComment()safely strips the markerThese utilities support the color-mix optimization feature described in the PR.
Note: These functions will only work correctly once the comment prefix is actually added in the
withAlpha()function (see previous comment).
color-mix in @supports again if it already is wrapped
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/tailwindcss/src/index.test.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/tailwindcss/src/index.test.ts (1)
packages/tailwindcss/src/test-utils/run.ts (1)
compileCss(4-11)
color-mix in @supports again if it already is wrappedcolor-mix in a @supports rule if one already exists
Related issue: #19445
Summary
Fixes an issue where tailwindcss wraps
color-mixinside a@supportsblock even if the original code already checks for support.Uncompiled Code:
Compiled code: Current behavior
https://play.tailwindcss.com/KSvR7wefdh?file=css
Compiled code: Fixed behavior
Test plan
I have tested this by writing a new test that was at first failing. Now it passes.