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

Fix Next.js endless loop when setting a custom distDir #15053

Merged
merged 3 commits into from
Nov 21, 2024

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Nov 20, 2024

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 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:

Screen.Recording.2024-11-20.at.18.41.17.mov

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.

@philipp-spiess philipp-spiess changed the title Fix Nextjs recurison when setting a custom distDir Fix Next.js recurison when setting a custom distDir Nov 20, 2024
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
@philipp-spiess philipp-spiess marked this pull request as ready for review November 20, 2024 17:54
@philipp-spiess philipp-spiess requested a review from a team as a code owner November 20, 2024 17:54
@philipp-spiess philipp-spiess changed the title Fix Next.js recurison when setting a custom distDir Fix Next.js endless loop when setting a custom distDir Nov 20, 2024
// configured to anything other than the default `.next` dir.
if (pattern === '*' && base === globBase) {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like I could've made money on this being a problem in something lol. I'm real happy the fix is this easy.

Copy link
Member

Choose a reason for hiding this comment

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

Before this we explicitly added this kind of pattern for the CLI. 😅

@thecrypticace thecrypticace force-pushed the fix/next-rebuilds-on-custom-distDir branch from 87d207d to 8aaa232 Compare November 20, 2024 22:21
@philipp-spiess philipp-spiess merged commit ae249c7 into next Nov 21, 2024
2 checks passed
@philipp-spiess philipp-spiess deleted the fix/next-rebuilds-on-custom-distDir branch November 21, 2024 09:47
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.

v4 blows up Next.js with custom distDir
4 participants