Skip to content
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

chore: upgrade Tailwind CSS to v4 #69

Merged
merged 3 commits into from
Jan 27, 2025
Merged

Conversation

azzzy
Copy link
Contributor

@azzzy azzzy commented Jan 23, 2025

Tailwind CSS 4 was released on January 22nd.
The upgrade guide can be found here.

The steps which were executed for each package in the workspace:

Upgrade Tailwind CSS to v4

pnpm i -D tailwindcss@latest

Install the Tailwind CSS Vite plugin

pnpm i -D @tailwindcss/vite

Remove postcss and autoprefixer

In v4 imports and vendor prefixing are now handled automatically.

pnpm rm postcss autoprefixer

Update vite.config.ts and App.css (see the PR diff for more information)

@brookslybrand
Copy link
Contributor

Awesome, thanks @azzzy! Looks like the tests broken unfortunately. Let me know if you need help debugging

@azzzy
Copy link
Contributor Author

azzzy commented Jan 24, 2025

There is a hydration error, which appears only in production.
Same issue was reported in the Tailwind CSS repo - tailwindlabs/tailwindcss#15422

I wasn't able to find any difference when diffing the server rendered page and the client markup, will dive deeper in it during the weekend.

@brookslybrand
Copy link
Contributor

I would try it as a side effect import and see if that resolves it

-import stylesheet from "./app.css?url";
+import "./app.css";

This is still an issue that should be fixed (not sure if it's us or tailwind)

This resolves a hydration error on production,
due to different app.css resulting build asset url
@azzzy
Copy link
Contributor Author

azzzy commented Jan 24, 2025

@brookslybrand ,

I would try it as a side effect import and see if that resolves it

-import stylesheet from "./app.css?url";
+import "./app.css";

This is still an issue that should be fixed (not sure if it's us or tailwind)

This solves it, thanks. It seems @tailwindcss-vite generates slightly different css files for the server and client entry:

vite v5.4.11 building for production...
✓ 48 modules transformed.
build/client/.vite/manifest.json                  2.08 kB │ gzip:  0.53 kB
build/client/assets/logo-dark-pX2395Y0.svg        6.10 kB │ gzip:  2.40 kB
build/client/assets/logo-light-CVbx2LBR.svg       6.13 kB │ gzip:  2.41 kB
build/client/assets/app-xqat8gf9.css             22.70 kB │ gzip:  6.32 kB  <----
build/client/assets/with-props-DYsm_2E1.js        0.35 kB │ gzip:  0.21 kB
build/client/assets/root-CR7BLDvn.js              1.22 kB │ gzip:  0.68 kB
build/client/assets/home-Cx76ZJ3y.js              3.74 kB │ gzip:  1.72 kB
build/client/assets/chunk-K6AXKMTT-C90Ya4xn.js  105.36 kB │ gzip: 35.65 kB
build/client/assets/entry.client-Dhb33yhI.js    178.81 kB │ gzip: 56.76 kB
✓ built in 557ms
vite v5.4.11 building SSR bundle for production...
✓ 11 modules transformed.
build/server/.vite/manifest.json              0.74 kB
build/server/assets/logo-dark-pX2395Y0.svg    6.10 kB
build/server/assets/logo-light-CVbx2LBR.svg   6.13 kB
build/server/assets/app-C-j-FxCF.css         20.47 kB  <----
build/server/index.js                        10.92 kB

✓ 1 asset moved from React Router server build to client assets.
build/client/assets/app-C-j-FxCF.css

In development mode Vite uses plain file names but for the production build it uses a content-based hashing strategy, so the url of the stylesheet is different for client and server in the prod build.

Vite supports side effect imports out of the box, so this looks like a better default for CSS assets.

Copy link
Contributor

@brookslybrand brookslybrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff @azzzy!

I'm not even sure why the production build has a css file, that seems to get deleted anyway.

Anyway, glad this works, I'm going to merge this in so that our templates are more up to date and simplified

@brookslybrand brookslybrand merged commit 2ac5c0d into remix-run:main Jan 27, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants