Repository navigation
Rebuild @tailwindcss/turbopack and @tailwindcss/webpack when the input CSS changes - #20582
Conversation
The loader decides between an incremental and a full rebuild only by the mtimes of the input file and its dependencies. After a save, Turbopack can run the loader with the previous version of the CSS file first (the file on disk already has the new mtime), and then again with the new version. The first call rebuilt the compiler from the old source and stored the new mtime, so the second call saw no change and reused that stale compiler. The dev server then kept serving the CSS of the previous edit. Store the source on the cache entry and do a full rebuild when it differs, like `@tailwindcss/postcss` does since #20310. Fixes #20581
The Turbopack loader is a copy of this loader, and it has the same gap: the rebuild check only looks at the mtimes of files on disk. When a loader that runs before it (e.g. `sass-loader`) inlines a partial, an edit of that partial changes the CSS that the loader receives, but not the mtime of the input file. The loader then reused the cached compiler and emitted the CSS of the previous build. Do a full rebuild when the source differs from the last build, like `@tailwindcss/postcss` does since #20310.
The matrix of the integration tests had no `turbopack` entry, so the tests in `integrations/turbopack` never ran in CI.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe Turbopack and webpack loaders now cache the last CSS source and select a full rebuild when the current source differs. New integration tests check CSS updates through both loaders, and the integration-test matrix now includes Turbopack. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to
|
[Medium impact] This PR appears safe to merge. Reviews (1) · Last reviewed commit: "Update changelog" · Reviewed by Greptile |
This PR fixes an issue where
next devwith the@tailwindcss/turbopackloader keeps serving the CSS of the previous edit after you edit the CSS file. Only a restart of the dev server shows the latest version.Fixes #20581
The loader caches a compiler for each CSS file. It only does a full rebuild when the mtime of the input file (or of one of its dependencies) changes. After a save, Turbopack can run the loader two times:
The loader registers the folders that it scans as context dependencies, and the CSS file is in one of them (e.g.
app/). So one save invalidates the loader in two ways, and the first run can still get the previous content of the file.@tailwindcss/postcsshad the same problem with Turbopack (#17554), and it compares the input CSS with the input CSS of the last build since #20310. The loader now does the same: it stores the source on the cache entry, and does a full rebuild when the source changes.@tailwindcss/turbopackis a copy of@tailwindcss/webpack, so the webpack loader gets the same fix. With webpack, the problem shows up when a loader that runs before ours changes the CSS, but not the input file. For example,sass-loaderinlines a partial, and you edit that partial.The matrix of the integration tests in CI had no
turbopackentry, so the tests inintegrations/turbopacknever ran in CI. This PR adds it.Test plan
integrations/turbopack/loader.test.ts. It editsapp/globals.cssthree times duringnext dev, and checks that the served CSS has each edit. Onmain(with Next.js 16.4.1), the served CSS still has.custom-1after the first edit. With this change, it passes.integrations/webpack/loader.test.ts, with a loader before@tailwindcss/webpackthat inlinessrc/partial.css. In watch mode, it edits that partial. Onmain, the output keeps.partial-1. With this change, it passes.main, the second call returns the CSS of the previous version. With this change, each call returns the CSS of the source that it gets.pnpm run buildpasses, and all tests inintegrations/turbopack/loader.test.tsandintegrations/webpack/loader.test.tspass.Sent by an AI assistant on behalf of @RobinMalfait.