-
Notifications
You must be signed in to change notification settings - Fork 4.5k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
@apply
Broken in Tailwind CSS v4.0 – No Clear Fix or Docs!
#16346
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
Comments
@JaquesBotha having the same issue. It's a really frustrating experience. |
Right on! Its like the 4.0 shift was rushed. Too many major changes without proper testing |
@JaquesBotha I think going back to V3 is the best choice here. |
We missed the prefix changes in the upgrade guide, will make a note to add that. The automated upgrade tool should handle those changes for you though if you haven't tried it. The main difference is prefixes look like variants now and always go at the beginning: .quickgrid thead th {
- @apply tw-bg-slate-100 dark:tw-bg-slate-800/70 tw-py-4;
+ @apply tw:bg-slate-100 tw:dark:bg-slate-800/70 tw:py-4;
} Here's the general documentation for the prefix option: https://tailwindcss.com/docs/styling-with-utility-classes#using-the-prefix-option I'm not sure how Native Blazor QuickGrid components work but if the CSS for each component is bundled individually the way CSS modules/Svelte/Vue/Astro style blocks are, you may also need to use the https://tailwindcss.com/docs/functions-and-directives#reference-directive Quick search makes me suspect this may be the case because of this CSS isolation functionality, which implies every stylesheet is processed independently with no knowledge of any other stylesheets. |
its also happening with me, without prefixes. Using Svelte |
Response to Tailwind Developer on
|
@JaquesBotha If the CSS is truly one global stylesheet (all of the stylesheets from your components are concatenated into a single stylesheet before being passed to Tailwind for processing) then everything should work exactly as it did before. The key thing to understand is for things like In v4 with configuration moving to CSS, we can't make assumptions about what your CSS file is called or where it lives, so if you have custom configuration in one CSS file that you need available in another CSS file, you need to explicitly import it using So the issue isn't to do with "scoping" it's just whether the CSS is actually processed together as one big stylesheet, or if each stylesheet is being processed one by one without the rules from the other stylesheets being present. Imagine you have these two stylesheets: /* one.css */
@import "tailwindcss";
@theme {
--color-potato: #d2a062;
}
/* two.css */
.foo {
@apply bg-potato;
} If these files are conceptually processed independently, sort of like this:
...you'll get an error when compiling This however of course will work fine: /* everything.css */
@import "tailwindcss";
@theme {
--color-potato: #d2a062;
}
.foo {
@apply bg-potato;
}
...because now Imagine you had one project that had a /* client.css */
@import "tailwindcss";
@theme {
--color-primary: blue;
}
/* admin.css */
@import "tailwindcss";
@theme {
--color-primary: red;
} Now you have some other component CSS file like this: /* foo.css */
.foo {
@apply bg-primary;
} Is that supposed to be blue or red? It's impossible to know because the color isn't defined and we have no way of making any assumption about what it should be. We could in v3 because of the global But you're saying that the CSS is global and they aren't processed independently, so what do you mean exactly when you say " If you can provide a reproduction we can boot up a Windows environment and take a look. It might be a bug if the CSS truly is all concatenated together and processed as one stylesheet but the fact that |
In Rails, with v4, we get a |
I have dozens of Vue components with |
@mohamad68 Can you please provide a reproduction? Here's a Vue + v4 project where it is working as expected: |
@adamwathan That's actually broken, but it's a subtle difference to what you've got here that produces the issue. I'm not sure exactly what the issue is, but if you render a component with the To reproduce the error in your example app, I made the following changes: // in App.vue
<script setup>
import TestComponent from './components/TestComponent.vue'
</script>
<template>
<div>
<TestComponent/>
</div>
</template> // in components/TestComponent.vue
<template>
<h1 class="test">
Test
</h1>
</template>
<style scoped>
@reference '../style.css'
.test {
@apply text-red-500 text-4xl;
}
// or this, which didn't work for me either...
h1 {
@apply text-red-500 text-4xl;
}
</style> The result is that the text in the |
@adamwathan Hmm, I toyed around with this and it's kind of flakey. I played around some more with this and got the applies to work copy-pasting your example applies. I'm not really sure what's going on there, but I can confirm I have seen this both not work and work. I don't know if there's something going on with vite, but when I pulled this down and added the above code, it did not work. At some point I moved some files around and copy-pasted code, and it started working and I was unable to reproduce what I was originally seeing (small, black text instead of 4xl red text) |
I'm not 100% sure what the intended behavior is for My advice would be to take 2 components and add
I can't get it to behave consistently at all, and it definitely feels like |
I can also attest that my website (using Astro) has broken in a re-deployment that installed the latest minor version of Tailwind (worked fine on 4.0.3, has problems on latest). Despite no code changes on my end, variables in non-root stylesheets such as I find it quite impressive that a project as large as Tailwind wasn't able to catch a significant regression in a minor version update (as stated above, it worked fine on 4.0.3, but broke on latest). I am not alone in finding the Tailwind 4.0 "improvements" to be more providing of frustration than anything else, even after consulting the documentation and following the upgrade process correctly. Apparently, my patience in upgrading correctly has been punished with 4.0 minor updates randomly breaking my website if I dare re-deploy. For now, I will mitigate these problems by pinning my dependencies to 3.0 for each of the projects mentioned above. I would consider re-categorizing 4.0 as a beta (again) until it becomes appropriate for production use. |
Response to Adam - Clarifying Blazor Server and
|
Follow-Up on Tailwind v4
|
@JaquesBotha I think the only logical next step here is to provide a minimal reproduction so we can investigate. I know you are producing global CSS at the end of the day but I still really suspect that each CSS file is being processed as a separate entry point, not that they are scoped in the way CSS modules are or anything. If you provide a reproduction we can test this and verify with some basic logging.
This is something I'd be really curious to see a reproduction for. I have not yet seen a case where |
Hey Adam, That makes sense. To ensure we're covering all bases, today I'll be spinning up a completely fresh Next.js project using Tailwind v4 to see if If the issue persists in a brand-new Next.js environment, that would strongly suggest this is a Tailwind v4 regression affecting multiple setups. If everything works fine there, then we can narrow it down to something specific in Blazor/Webpack. I rarely use I'll report back with the findings once the tests are complete and, if needed, provide a minimal reproduction repo for further investigation. Thanks for the patience—I'll get back to you soon! |
@loukamb Thanks for the heads up, we've reverted this for now and pushed out a new patch until we can figure out a solution to this scenario.
Please don't be an asshole — we work very hard to make Tailwind as robust as possible but we're not perfect and sometimes there's a situation we don't manage to anticipate and account for when working on an improvement. When this happens we work quickly to resolve it (about 42 hours for this one). Constructive good-faith feedback that helps the project is appreciated, but passive aggressive stuff like this isn't welcome. |
@JaquesBotha A reproduction using Blazor would be more helpful since that's the issue you are facing. It's not clear to me if you'd tried using |
Hey Adam, I appreciate the follow-up, and I understand why a Blazor-specific reproduction would be helpful. That said, I want to make sure we’re aligned on how my setup actually works, because it seems like there’s a misunderstanding.
That said, I will also look into creating a minimal Blazor-specific reproduction, and I’ll report back with my findings. If the issue persists in that environment as well, that would further suggest a regression in Tailwind v4. Appreciate your patience, I’ll follow up soon. |
@adamwathan I apologize! I made that response wayyy late at night because a team at work called me about this issue (called at 1 am, reply made here at 3 am) when a deployment randomly broke. I subsequently noticed that all two of the projects we are using Tailwind on were broken, which I initially blamed on us until I saw my blog was also broken which frustrated me heavily. When I found out what caused the issues after a couple hours my combined frustration and tiredness wrote that reply. That said, this morning I was able to "fix" (I don't know if this actually a fix/the proper way of achieving this) the issue by changing |
@JaquesBotha Have you proven that the CSS files aren't processed independently? I would love to see a reproduction. Unless you have one stylesheet like In this example for instance both of these CSS files will be run through PostCSS totally separately by webpack: // main.js
import "stylesheet-1.css";
import "stylesheet-2.css";
// ... In order to make webpack process them as one, you need to do this instead: // main.js
import "all-stylesheets.css";
// ... /* all-stylesheets.css */
@import "stylesheet-1.css";
@import "stylesheet-2.css"; Webpack may be producing one bundle at the end of the day but that is orthogonal to how it processes your stylesheets. You can verify this by adding a custom PostCSS plugin to your PostCSS setup that logs the name of the file it's processing: // postcss.config.js
module.exports = {
plugins: [
require('postcss')((root, result) => {
if (result.opts.from) {
console.log(`Processing file: ${result.opts.from}`);
} else {
console.log('Processing unknown file');
}
}),
"@tailwindcss/postcss",
],
}; I did this locally in a Next.js project which proves that PostCSS is running separately for each of those CSS files: ![]() Here's the repo for you to take a look at: https://github.com/adamwathan/postcss-entrypoints This is not something we have any control over with Tailwind, it's just how the bundler works. If you want everything to build in one step, you need a single CSS file that imports your other CSS files. |
Hey Adam, I appreciate your patience on this. I’ve gone through the entire upgrade process step by step and documented everything, including the errors encountered. Below is a structured breakdown of what I did and the results. Upgrade Process:
Key Findings:
Next Steps:I believe this provides enough detail to investigate further. Given that:
This strongly suggests an issue with Tailwind v4’s handling of Let me know what additional information you need to proceed. AND again thanks your time appreciate the efforts! |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Tailwind CSS v4.0
@apply
Bug ReportIntroduction
I'm in the process of upgrading a large project, actually, five Blazor projects that all conjoin into one via components and different backends. Our focus with this project is to deliver an optimal UI experience to the end-user, which is why we use TypeScript, C#, and of course, our favorite, Tailwind CSS. Btw, huge fans!
Now, with that said, we have certain native components where we cannot add CSS classes to the component itself, making
@apply
an essential part of our workflow. However, after upgrading to Tailwind CSS v4.0,@apply
is no longer working as expected, and there seems to be little guidance on how to transition projects that rely on it. This bug report aims to outline the issue clearly and request either a fix or detailed documentation on what exactly we need to do to overcome this.What version of Tailwind CSS are you using?
v4.0.0
What build tool (or framework if it abstracts the build tool) are you using?
Webpack 5.97.1
What version of Node.js are you using?
v20.11.1
What version of npm are you using?
v10.7.0
What IDE are you using?
Rider IDE
What operating system are you using?
macOS
Reproduction URL
There's an active discussion on this issue where many developers are experiencing the same problem but no one has officially reported it yet. Rather than debating, I’d rather get a solution, so here’s the link to the discussion: #13336 (comment)(https://github.com/yourusername/tailwind-v4-apply-issue)
Describe your issue
After upgrading to Tailwind CSS v4.0, I encountered the following issues:
1.
@apply
Directive Not FunctioningThe
@apply
directive, previously used extensively in our CSS for class composition, no longer functions as expected.Example:
2. Lack of Clear Documentation for
@apply
Usage in v4.0@apply
directive in non-Vue projects.@apply
should still work, but this is only relevant for Vue projects.@apply
is heavily used.3. Backward Compatibility with
tailwind.config.js
tailwind.config.js
file appears to be deprecated or its usage has changed in v4.0 without clear documentation.prefix: 'tw-'
are experiencing issues with styles not applying correctly.4.
@apply
is Necessary for Native Blazor QuickGrid Components@apply
with Native Blazor QuickGrid components, where there is no alternative way to apply Tailwind classes.Expected Outcome
@apply
so that it functions as expected in Tailwind CSS v4.0.@apply
.tailwind.config.js
should be updated for v4.0.Thank you for your attention to this issue!
The text was updated successfully, but these errors were encountered: