fix(@tailwindcss/vite): include @variant in feature detection#19966
Conversation
CSS files that only use @variant (without @apply, theme(), or utilities) were silently skipped by the Vite plugin because Features.Variants was not included in the feature detection bitmask. This caused @variant directives to be passed through raw to the browser, which drops them as unknown at-rules. Fixes tailwindlabs#19964
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
WalkthroughThe plugin's early-exit check in Root.generate was adjusted so the compiler features bitmask must include Variants in addition to AtApply, JsPluginCompat, ThemeFunction, and Utilities. Previously the method returned early unless only the prior four flags were present; after the change it will also accept the Variants flag and only returns false when Variants (or any required flag) is missing. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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.
🧹 Nitpick comments (1)
packages/@tailwindcss-vite/src/index.ts (1)
523-530: LGTM — correct fix for the feature-detection gap.Adding
Features.Variantsto the bitmask ensures CSS files that only contain@variant/@custom-variant(without@apply,theme(), or utilities) are no longer early-returned as non-Tailwind files and will be compiled properly. The downstreamFeatures.Utilities-gated scanning/dependency-registration blocks (lines 532-582) are unaffected, which is correct since variant-only files don't need candidate scanning.One optional consideration: it would be worth adding a regression test (e.g., in the Vite plugin integration tests) with a CSS entry that only declares
@custom-variant/@variantto lock in this behavior and prevent future regressions.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/`@tailwindcss-vite/src/index.ts around lines 523 - 530, The early-return conditional is missing Features.Variants so files that only declare `@variant/`@custom-variant get treated as non-Tailwind; update the bitmask check on this.compiler.features to include Features.Variants alongside Features.AtApply, Features.JsPluginCompat, Features.ThemeFunction, Features.Utilities so the if-statement correctly detects variant-only CSS and does not return false; locate the check using the this.compiler.features expression and the Features enum in index.ts and add Features.Variants to the ORed mask.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/`@tailwindcss-vite/src/index.ts:
- Around line 523-530: The early-return conditional is missing Features.Variants
so files that only declare `@variant/`@custom-variant get treated as non-Tailwind;
update the bitmask check on this.compiler.features to include Features.Variants
alongside Features.AtApply, Features.JsPluginCompat, Features.ThemeFunction,
Features.Utilities so the if-statement correctly detects variant-only CSS and
does not return false; locate the check using the this.compiler.features
expression and the Features enum in index.ts and add Features.Variants to the
ORed mask.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4bf147ce-19b1-4407-a0e7-694e971a8685
📒 Files selected for processing (1)
packages/@tailwindcss-vite/src/index.ts
RobinMalfait
left a comment
There was a problem hiding this comment.
Thanks!
This makes sense. Note that we will use the default dark variant implementation not the custom one since you didn't reference the other file.
That said, we already had this behavior if you only used @apply flex; for example (since it's a built-in utility).
Fixes #19964
CSS files imported via JS that only use
@variant(no@apply,theme(), or utility classes) are silently skipped by the Vite plugin. The@variantdirective gets passed through raw to the browser, which drops it as an unknown at-rule.Root cause —
Features.Variantsis missing from the feature detection bitmask:Reproduction — https://github.com/remorses/tailwind-variant-bug