-
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
Inconsistent CSS assets between client and SSR builds with @tailwindcss/vite #16389
Comments
Forgot to mention, this behavior is identical with |
Hey! The way the Vite extension works is by using the Vite module graph to find out what class names you are actually using and since you're running two separate builds with two separate module graphs, we will also yield two separate CSS files. You can make sure the same CSS files are generated by opting-out of automatic content scanning: https://tailwindcss.com/docs/detecting-classes-in-source-files#disabling-automatic-detection Will have to see what we can do about this, thanks for the report! |
@philipp-spiess Roger. Thanks, I will try that. For what it's worth the client and server bundles, although obviously different, include precisely the same set of files that reference any tailwind classes. So my expectation was that the resulting tailwind CSS file would be deterministic and identical. But this is definitely above my pay grade in terms of how Vite module graphs works :) |
@mkdynamic Yeah, I agree that this is super confusing. We are seeing similar issues across other popular frameworks as well so this is not the end of the story yet. Do you use Vite with a framework like React Router/Astro or just the config you provided as-is? |
@philipp-spiess 👍 We are using a custom framework. But I do observe the same behavior when using the most "vanilla" SSR setup with Vite in the above repos. Our framework does build the client and SSR bundles in the same way. |
@philipp-spiess Thanks for this – doing this solved the issue, I now see consistent builds between client and SSR. This is a fine solution for us, much better than the sketchy Vite plugin I wrote to "fix" the asset paths after the build – very happy to throw that away :) |
Glad it works now! What we're thinking of is a Vite plugin API to disable the module graph based lookups for cases like this. Will report back once we have made some decisions and something for you to test 👍 |
The following settings ensure consistent class names.
export default defineConfig(() => ({
…
css: {
transformer: "lightningcss",
},
…
})); In this repository, the class name outputs correctly with that setting. |
@mkdynamic Hey! We decided to land some changes in the Vite plugin that will ensure that both builds now have access to the same class name list. We plan to release this in a patch very soon (hopefully today!). Thanks for the bug report. 🙇 |
@philipp-spiess Woot! Excited to try once it ships. |
hey! just came across this issue and i have been facing the same problem with tanstack start. any chance we could get that version release so we can update and take advantage of this fix? thanks! tailwind v4 has been great so far otherwise 🥳 |
What version of Tailwind CSS are you using?
4.0.5
What build tool (or framework if it abstracts the build tool) are you using?
Vite 6.1.0
What version of Node.js are you using?
Bun 1.2.2
What browser are you using?
N/A
What operating system are you using?
macOS
Reproduction URL
@tailwindcss/vite
plugin: https://github.com/mkdynamic/vite-tailwind-ssr@tailwindcss/postcss
plugin: https://github.com/mkdynamic/vite-tailwind-postcss-ssrDescribe your issue
When using
@tailwindcss/vite
, and creating an SSR build with Vite, the CSS asset paths differ between the SSR and client builds. This is not true with@tailwindcss/postcss
.The above repos contain a minimal reproduction case, starting from a fresh React Vite project. Here are the reproduction steps below showing the bug:
With the
@tailwindcss/vite
plugin:Note the asset path of the built
App.css
differs between the SSR and client builds (i.e.App-BYq-i2yi.css !== App-DWNkNxeI.css
). This means that SSR rendered responses have the incorrect asset URL (which leads to a hydration error, if you are hydrating – or a missing CSS asset if you are only SSR rendering).With the
@tailwindcss/postcss
based plugin:Note the asset path of the built
App.css
matches the SSR and client builds (i.e.App-BYq-i2yi.css === App-BYq-i2yi.css
).Let me know if I can provide any more information.
The text was updated successfully, but these errors were encountered: