Skip to content

Watch files that a full rebuild adds in @tailwindcss/postcss - #20763

Open
RobinMalfait wants to merge 2 commits into
mainfrom
robin/open-pr-watch-new-dependencies-after-a-full-rebuild-in-tailwindcss/postcss
Open

RobinMalfait wants to merge 2 commits into
mainfrom
robin/open-pr-watch-new-dependencies-after-a-full-rebuild-in-tailwindcss/postcss

Conversation

@RobinMalfait

Copy link
Copy Markdown
Contributor

This PR fixes an issue where @tailwindcss/postcss doesn't watch a file that a full rebuild finds for the first time, like a new @import, @config or @plugin.

On a full rebuild, the plugin reported the dependency messages of the previous compiler, and only then created the new compiler. The new compiler's files were only reported on the next build. Bundlers like webpack (postcss-loader, and Next.js with webpack) reset the dependencies of a module on each build, so a change to such a file didn't cause a rebuild, until something else changed the CSS file.

This only shows for files that the scanner doesn't report already: files outside of source(…), in another workspace package, or ignored by git.

Given this setup, in webpack --watch:

/* styles/index.css */
@import 'tailwindcss/utilities' source('../src');
  1. Add @import './buttons.css'; to styles/index.css. The output now contains the styles of buttons.css.
  2. Change buttons.css. Before this PR, nothing rebuilds. With this PR, the output updates.

The fix reports each dependency as soon as the compiler finds it, once per build. The error path re-reports the same paths, so it uses the same helper and doesn't add duplicates. When a new file makes the compile fail, it was already reported by the error path, and that still works.

#20762 fixes the same bug in @tailwindcss/webpack and @tailwindcss/turbopack.

Test plan

  • Added unit tests in packages/@tailwindcss-postcss/src/index.test.ts for the dependency messages of a full rebuild, on success (once, no duplicates) and on failure.
  • Added an integration test, webpack + PostCSS (watch): rebuilds when a newly imported file changes, in integrations/webpack/index.test.ts.
  • Both the new unit test for the success path and the integration test fail without the fix.

The plugin 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 reported as `dependency` messages of that build.
Bundlers like webpack 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 file.

Report each dependency as soon as the compiler finds it, once per build.
The error path reports the same paths, so it uses the same helper and
does not add duplicates.
@RobinMalfait
RobinMalfait requested a review from a team as a code owner November 25, 2026 14:11
@RobinMalfait RobinMalfait self-assigned this Nov 25, 2026
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.

1 participant