Make @reference emit variable fallbacks instead of CSS variable declarations#16774
Merged
philipp-spiess merged 8 commits intomainfrom Feb 25, 2025
Merged
Make @reference emit variable fallbacks instead of CSS variable declarations#16774philipp-spiess merged 8 commits intomainfrom
@reference emit variable fallbacks instead of CSS variable declarations#16774philipp-spiess merged 8 commits intomainfrom
Conversation
@import "…" theme(reference) in tests@reference emit variable fallbacks instead of CSS variable declarations
philipp-spiess
commented
Feb 24, 2025
85b933b to
5c568c1
Compare
philipp-spiess
commented
Feb 24, 2025
|
|
||
| 50% { | ||
| transform: rotate(3deg); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
I think this was a bug before? Whoopsie
e3be9fc to
ebcd576
Compare
RobinMalfait
approved these changes
Feb 25, 2025
packages/tailwindcss/src/index.ts
Outdated
| @@ -464,10 +468,6 @@ async function parseCss( | |||
| // since the `@theme` rule itself will be removed. | |||
| if (child.kind === 'at-rule' && child.name === '@keyframes') { | |||
| // Do not track/emit `@keyframes`, if they are part of a `@theme reference`. | |||
Member
There was a problem hiding this comment.
I think this comment can go as well?
Contributor
Author
There was a problem hiding this comment.
ah yep good catch :D
|
|
||
| .tab-4 { | ||
| tab-size: var(--tab-size-4); | ||
| tab-size: var(--tab-size-4, 4); |
Member
Contributor
Author
Comment on lines
-619
to
+618
| input, | ||
| opts, | ||
| ) | ||
| let { designSystem, ast, globs, root, utilitiesNode, features } = await parseCss(input, opts) |
Member
There was a problem hiding this comment.
Love that we don't need to pass around this firstThemeRule anymore 😍
fc7fbd2 to
12f4701
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #16725
When using
@reference "tailwindcss";inside a separate CSS root (e.g. Svelte<style>components, CSS modules, etc.), we have no guarantee that the CSS variables will be defined in the main stylesheet (or if there even is one). To work around potential issues with this we decided in #16676 that we would emit all used CSS variables from the@themeinside the@referenceblock.However, this is not only a bit surprising but also unexpected in CSS modules and Next.js that requires CSS module files to only create scope-able declarations. To fix this issue, we decided to not emit CSS variables but instead ensure all
var(…)calls we create for theme values in reference mode will simply have their fallback value added.This ensures styles work as-expected even if the root Tailwind file does not pick up the variable as being used or if you don't add a root at all. Furthermore we do not duplicate any variable declarations across your stylesheets and you still have the ability to change variables at runtime.
Test plan