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

NextJS Hot Reload #30791

Closed
mohux opened this issue Nov 2, 2021 · 7 comments · Fixed by #31548
Closed

NextJS Hot Reload #30791

mohux opened this issue Nov 2, 2021 · 7 comments · Fixed by #31548
Assignees
Labels
bug Issue was opened via the bug report template. Middleware Related to Next.js Middleware.

Comments

@mohux
Copy link

mohux commented Nov 2, 2021

What version of Next.js are you using?

12.0.2

What version of Node.js are you using?

14.17.1

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Local

Describe the Bug

NextJS keeps refreshing when code is updated, the log below shows what happens

I've read about the warning in other issues, but didn't have it prior to upgrading to next 12

while
_devMiddlewareManifest
is new

couldn't reproduce due to the fact the project is actually big and was working fine prior to upgrading
any update is causing a refresh

image

Expected Behavior

The page shouldn't be refreshing

To Reproduce

Upgraded to next 12.0.2 and used a middleware in a subfolder (nothing else)

@mohux mohux added the bug Issue was opened via the bug report template. label Nov 2, 2021
@timneutkens timneutkens added the Middleware Related to Next.js Middleware. label Nov 2, 2021
@mohux
Copy link
Author

mohux commented Nov 2, 2021

so far it seems when middleware file is removed the issue doesn't occur (will have to keep debugging more to see any refresh happening again

@zifeo
Copy link
Contributor

zifeo commented Nov 2, 2021

I was about to submit the same issue. There are multiple unexpected behaviours:

  • happens randomly every 4-5 fast refreshes on heavy NextJS apps and every 30-40 on small apps (on my side)
  • seems to happen because one of the middleware was recompiled: full reload seems fair in that case, but there is no reason why the middleware was recompiled while only a page was updated
  • the error message should be updated to include the middleware cause, maybe Feat/14701 full reload notification #28866 will help
wait  - compiling...
event - compiled successfully in 223 ms (193 modules)
wait  - compiling...
event - compiled successfully in 212 ms (193 modules)
wait  - compiling...
event - compiled successfully in 185 ms (193 modules)
wait  - compiling...
event - compiled successfully in 101 ms (193 modules)
wait  - compiling...
event - compiled successfully in 284 ms (193 modules)
wait  - compiling...
event - compiled successfully in 227 ms (166 modules)
wait  - compiling /_middleware (client only)...
event - compiled successfully in 163 ms (188 modules)
wait  - compiling /...
event - compiled successfully in 76 ms (193 modules)
wait  - compiling...

@njarraud
Copy link

njarraud commented Nov 3, 2021

I don't know if it is related, but I have the exact same issue when I include a "_document.tsx" file in my pages directory. Any code modification in my components triggers a full reload of the page. When "_document.tsx" is removed, hot reloads work as intended.

Even the default _document example from the vercel website triggers the same full reload behaviour.

Next.js 12.0.0 & 12.0.2

@judewang
Copy link

I also have the same issue, probably is because of middleware.

@prichodko
Copy link
Contributor

I can confirm that removing _middleware.ts from the root of the /pages fixes hot reloading.

I am using Next.js v12.0.3 and basic auth middleware example.

@predaytor
Copy link

I can confirm that removing _middleware.ts from the root of the /pages fixes hot reloading.

I am using Next.js v12.0.3 and basic auth middleware example.

Same

@javivelasco javivelasco self-assigned this Nov 17, 2021
@kodiakhq kodiakhq bot closed this as completed in #31548 Nov 18, 2021
kodiakhq bot pushed a commit that referenced this issue Nov 18, 2021
Fixes #30791

The issue is that with Middleware we are introducing client compilation on a new layer. When a middleware changes (or is dropped after some time), Webpack reorganizes non-user modules as they are duplicated across different layer. This is currently triggering a full reload.

This also brings tests for HMR:
- Refresh on a Middleware change
- HMR works after a middleware compilation change.

Co-authored-by: Tobias Koppers <[email protected]>
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
Fixes vercel#30791

The issue is that with Middleware we are introducing client compilation on a new layer. When a middleware changes (or is dropped after some time), Webpack reorganizes non-user modules as they are duplicated across different layer. This is currently triggering a full reload.

This also brings tests for HMR:
- Refresh on a Middleware change
- HMR works after a middleware compilation change.

Co-authored-by: Tobias Koppers <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Middleware Related to Next.js Middleware.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants