Repository navigation
Watch files that a full rebuild adds in @tailwindcss/webpack and @tailwindcss/turbopack - #20762
Open
RobinMalfait wants to merge 2 commits into
Conversation
…ders The loaders reported the config files, plugins and imported stylesheets of the previous compiler, and only then did a full rebuild. Files that only the new compiler found, like a new `@import`, `@config` or `@plugin`, were not watched after that build. Bundlers reset the dependencies of a module on each build, so a change to such a file did not cause a rebuild until something else changed the CSS module. Report each dependency as soon as the compiler finds it. This also covers a new file that makes the compile fail: a fix in that file now causes a rebuild.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes watch mode in
@tailwindcss/webpackand@tailwindcss/turbopackfor files that a CSS file starts to depend on, like a new@import,@configor@plugin.Problem
The loaders reported the dependencies of the previous compiler to the bundler, and only then did a full rebuild. Files that only the new compiler found were not reported for that build. webpack and Turbopack reset the dependencies of a module on each build, so these files were not watched. A change to such a file did not cause a rebuild, until something else rebuilt the CSS module.
Example, with styles outside of the
source(…)folder:The new
@importworks. But a change tostyles/buttons.cssafter that did nothing.Files that the scanner finds were not affected, because the loaders report those separately. So the bug shows for files outside of the scanned sources, like files outside of
source(…), in another workspace package, or ignored by git.Fix
Report each dependency to the bundler as soon as the compiler finds it, in
onDependency.@tailwindcss/vitealready does this. Each path is reported once per build.This also covers a full rebuild that fails after it found a new file. For example, a new
buttons.csswith@applyof an unknown class: a fix inbuttons.cssnow causes a rebuild.The new files get their mtime on the next build, like before. So that build is still a full rebuild.
Test plan
New integration tests:
@tailwindcss/webpack loader watches files that a full rebuild adds (watch)@tailwindcss/webpack loader watches files that a failed full rebuild adds (watch)@tailwindcss/turbopack loader watches files that a full rebuild adds (dev)All 3 fail on
mainwith the old loaders, and pass with this PR. The other webpack and Turbopack integration tests still pass.Notes
@tailwindcss/postcsshas the same bug when its dependencies go to a bundler (for example webpack withpostcss-loader). Its error path already reports the new files, so it needs a different change. This PR does not change it.