Skip to content

Commit ae249c7

Browse files
Fix Next.js endless loop when setting a custom distDir (#15053)
Closes #15050 In Tailwind CSS v4 Alpha 31 we changed how we scan template files. This changes included a new folder-dependency that is emitted for the `base` directory, so we can listen for new files being added as part of the postcss dependency. In our testing, this worked fine with the Next.js integration meaning a new file in the project root would be picked up by Oxide and we could update the CSS files accordingly. This change is now, however, causing an issue. With Next.js 15 **and with a custom `distDir` configured**, the postcss build, that will write into the `distDir`, will cause another postcss run to be triggered, starting an endless loop (regardless of wether or not the `distDir` was also part of your gitignore list). This PR now changes the postcss client to not emit the base directory as a dependency to revert this changes. This does mean that new files and folders created _directly in the project root_ will require a restart of the Next.js server again (just like it did in Alpha 31 and before) for now. ## Test Plan Next 15 does not seem to run in our current integration test setup (for some reason the server does not close correctly and it will fail on the cleanup step), so this change was tested manually: - First, clone the [templates repo](https://github.com/philipp-spiess/tailwindcss-playgrounds) I use for third party frameworks - Then, do a full build in the parent repo `tailwindcss` via `pnpm build` - Now, install the local tarballs in the `tailwindcss-playgrounds` repo via `pnpm install` With this setup I have tested changes to a template file (that causes new utilities to be added) and the CSS file (that will rebuild properly) across both `pnpm dev` and `pnpm dev --turbo`. Furthermore integration tests assert it still works in Next 14 like it did before: https://github.com/user-attachments/assets/b0ccb3dd-d090-4e4c-97c5-74129a2789be One thing to make sure of is to include the new `distDir` into the `.gitignore` file as well, otherwise we will scrape it for changes which inherently causes an endless loop issue again. --------- Co-authored-by: Adam Wathan <[email protected]>
1 parent 0d0ce2c commit ae249c7

File tree

1 file changed

+10
-3
lines changed
  • packages/@tailwindcss-postcss/src

1 file changed

+10
-3
lines changed

packages/@tailwindcss-postcss/src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,26 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
170170
// Register dependencies so changes in `base` cause a rebuild while
171171
// giving tools like Vite or Parcel a glob that can be used to limit
172172
// the files that cause a rebuild to only those that match it.
173-
for (let { base, pattern } of context.scanner.globs) {
173+
for (let { base: globBase, pattern } of context.scanner.globs) {
174+
// Avoid adding a dependency on the base directory itself, since it
175+
// causes Next.js to start an endless recursion if the `distDir` is
176+
// configured to anything other than the default `.next` dir.
177+
if (pattern === '*' && base === globBase) {
178+
continue
179+
}
180+
174181
if (pattern === '') {
175182
result.messages.push({
176183
type: 'dependency',
177184
plugin: '@tailwindcss/postcss',
178-
file: base,
185+
file: globBase,
179186
parent: result.opts.from,
180187
})
181188
} else {
182189
result.messages.push({
183190
type: 'dir-dependency',
184191
plugin: '@tailwindcss/postcss',
185-
dir: base,
192+
dir: globBase,
186193
glob: pattern,
187194
parent: result.opts.from,
188195
})

0 commit comments

Comments
 (0)