-
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
Re-enable: Only expose used CSS variables #16676
Conversation
c772a81
to
b3cb5c3
Compare
b3cb5c3
to
0dce342
Compare
Great work, @philipp-spiess! Am I right to assume that this will be included on v4.0.8? |
@moatorres Yep. We're preparing the release right now so hopefully it's out in a couple of hours 👍 |
Thanks @philipp-spiess ! |
Sorry for hijacking this, but how can I force to output some of the default theme variables even if they are not detected automatically? E.g. how can I always emit all the |
Should 4.0.8 have fixed #16725 ? |
No, I think this PR is what is causing #16725. |
Thanks @wongjn - makes more sense :) I downgraded to 4.0.7 but problem remains. I will try going back to 4.0.6 |
4.0.6 has same problem. 4.0.6 with postcss rolled back to 8.5.2 same problem as well. Now I am perplexed. This should be same as production server is running. Suggestions? |
Try checking you have successfully downgraded, via |
you're correct - 4.0.8 is pulled in and visible in package-lock.json. I deleted node_modules and .next and package-lock.json and package.json has 4.0.6
Yet after doing npm install it shows:
Hmm. My ignorance clearly showing - what is the correct way to get 4.0.6 ? Okay this seems to work:
Now its back to 4.0.6 and builds again. Thank you for your help @wongjn. |
If you're using git, you could revert npm install @tailwindcss/postcss@4.0.6 tailwindcss@4.0.6 |
Thanks @wongjn - yep I'm using git so for sure I can go back to the production tag. |
Does anyone have thoughts on how to fix #16725 ? |
@wenbei thanks for the tip, I tried it but got stuck at how to name the variable to include all colors, e.g. tried this: @theme static {
--color-*: <XXX>;
} with
Or must I copy all the variables from the docs and put them there explicitly? I guess this works in the meantime but then I won't get any update if the theme is changed 🤔 |
... just found out in #16514 how to include all variables: @import "tailwindcss" theme(static); Works for my use case. Though I'd still be interested if you can make only some of the variables static (e.g. only all |
…larations (#16774) 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 - Updated snapshots everywhere (see diff) - New Next.js CSS modules integration test
This PR re-enables the changes necessary to remove unused theme variables and keyframes form your CSS.
This change was initially landed as #16211 and then later reverted in #16403 because we found some unexpected interactions with using
@apply
and CSS variables in multi-root setups like CSS modules or Vue inline<style>
blocks that were no longer seeing their required variables defined.This issue is fixed by now ensuring that theme variables that are defined within an
@reference "…"
boundary will still be emitted in the generated CSS when used (as this would otherwise not generate a valid stylesheet).So given the following input CSS:
We will now compile this to:
This PR also improves the initial implementation to not mark theme variables as used if they are only used to define other theme variables. For example:
This would be reduced to the following now as
--font-mono
is only used to define another variable and never used outside the theme block:Test plan