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

v4 blows up Next.js with custom distDir #15050

Closed
vladmoroz opened this issue Nov 20, 2024 · 2 comments · Fixed by #15053
Closed

v4 blows up Next.js with custom distDir #15050

vladmoroz opened this issue Nov 20, 2024 · 2 comments · Fixed by #15053
Labels

Comments

@vladmoroz
Copy link

HMR blows up the server when using v4 in a project with a custom distDir in the Next.js config

What version of Tailwind CSS are you using?

"@tailwindcss/postcss": "4.0.0-alpha.34",
"tailwindcss": "4.0.0-alpha.34",

This wasn't an issue in "4.0.0-alpha.30", started happening in "4.0.0-alpha.31"

What build tool (or framework if it abstracts the build tool) are you using?

Next.js 15

What version of Node.js are you using?

Node.js 20

Reproduction URL

https://codesandbox.io/p/devbox/tphzmv?file=%2Fnext.config.js%3A4%2C3

Screen.Recording.2024-11-20.at.09.53.35.mp4
@philipp-spiess
Copy link
Member

philipp-spiess commented Nov 20, 2024

@vladmoroz Thanks for reporting this. I was able to reproduce this very annoying issue and have fix it in #15053. We'll get this out to you soon!

One note from your repro is that you still want to include the custom distDir in your .gitignore list, otherwise there will still be an unexpected loop. I suspect this was already happening in your project though (since you mentioned it worked before alpha 31) and you just omitted it in the repro but I wanted to document it here regardless 👍

@vladmoroz
Copy link
Author

Hey, thanks for such a quick fix.
And yeah, our distDir is already gitignored in the real project.

philipp-spiess added a commit that referenced this issue Nov 21, 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](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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants