Skip to content

Inconsistent CSS assets between client and SSR builds with @tailwindcss/vite #16389

@mkdynamic

Description

@mkdynamic

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

Describe 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:

$ bun build:client
$ vite build --outDir build/client --manifest
vite v6.1.0 building for production...
✓ 29 modules transformed.
build/client/.vite/manifest.json         0.38 kB │ gzip:  0.21 kB
build/client/index.html                  0.39 kB │ gzip:  0.27 kB
build/client/assets/App-DWNkNxeI.css     6.10 kB │ gzip:  1.79 kB
build/client/assets/index-DO9bOB2u.js  185.88 kB │ gzip: 58.73 kB
✓ built in 463ms

$ bun build:server
$ vite build --outDir build/server --ssr=src/entry-ssr.tsx
vite v6.1.0 building SSR bundle for production...
✓ 4 modules transformed.
build/server/entry-ssr.js  0.46 kB
✓ built in 55ms

$ grep App- build/server/entry-ssr.js
const stylesheet = "/assets/App-DX11wV_z.css";

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:

$ bun build:client
$ vite build --outDir build/client --manifest
vite v6.1.0 building for production...
✓ 29 modules transformed.
build/client/index.html                  0.39 kB │ gzip:  0.27 kB
build/client/.vite/manifest.json         0.40 kB │ gzip:  0.21 kB
build/client/assets/App-BYq-i2yi.css     5.48 kB │ gzip:  1.69 kB
build/client/assets/index-BjxNUz_i.js  185.88 kB │ gzip: 58.73 kB
✓ built in 594ms

$ bun build:server
$ vite build --outDir build/server --ssr=src/entry-ssr.tsx
vite v6.1.0 building SSR bundle for production...
✓ 4 modules transformed.
build/server/entry-ssr.js  0.46 kB
✓ built in 193ms

$ grep App- build/server/entry-ssr.js
const stylesheet = "/assets/App-BYq-i2yi.css";

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions