-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make @reference
emit variable fallbacks instead of CSS variable declarations
#16774
Conversation
@import "…" theme(reference)
in tests@reference
emit variable fallbacks instead of CSS variable declarations
85b933b
to
5c568c1
Compare
50% { | ||
transform: rotate(3deg); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was a bug before? Whoopsie
e3be9fc
to
ebcd576
Compare
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment can go as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yep good catch :D
} | ||
.tab-4 { | ||
tab-size: var(--tab-size-4); | ||
tab-size: var(--tab-size-4, 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let { designSystem, ast, globs, root, utilitiesNode, features, firstThemeRule } = await parseCss( | ||
input, | ||
opts, | ||
) | ||
let { designSystem, ast, globs, root, utilitiesNode, features } = await parseCss(input, opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love that we don't need to pass around this firstThemeRule anymore 😍
fc7fbd2
to
12f4701
Compare
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@theme
inside the@reference
block.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