Fast refresh not working properly due to page reload when compiling middleware
See original GitHub issueWhat version of Next.js are you using?
12.0.4
What version of Node.js are you using?
16.13.0
What browser are you using?
Chrome, Safari, Edge
What operating system are you using?
macOS
How are you deploying your application?
next dev
Describe the Bug
Since I don’t know the technological background or necessity of the page reload for middleware
, I’m not sure if that’s something that you have to live with when working with middleware
- but any change, like edits made to react components, often trigger a page reload due to the middleware
being compiled:
wait - compiling /_middleware (middleware only)…
This becomes especially frustrating when working with getStaticProps
.
Expected Behavior
No page reload when applying changes (“Fast Refresh”).
To Reproduce
Basic middleware
implementation.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:26
- Comments:50 (13 by maintainers)
Top Results From Across the Web
Basic Features: Fast Refresh - Next.js
Next.js' Fast Refresh is a new hot reloading experience that gives you instantaneous feedback on edits made to your React components.
Read more >NextJS Fast refresh not working as expected - Stack Overflow
The fast refresh feature is working perfectly with other components but has problem with this specific component only.
Read more >Fast Reliable/Hot Reloading in Next.js - Coding Ninjas
This approach refreshes the browser and reloads the component, so the current state should not be lost. What is Fast Refresh? The Fast...
Read more >Fast Refresh | Gatsby
Fast Refresh is an implementation of Hot Reloading with full support from React. ... most often due to an error inside your page...
Read more >Next.js 12.3 Overview: Improved Fast Refresh ... - YouTube
Next.js 12.3 introduces several improvements to your React development workflow, including hot reloading environment and configuration files ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey! I was facing the same issue until I found the problem: something that is imported in the middleware and somewhere in the app. The import could be anything, including an external dependency. Here is the minimal reproduction: henriqemalheiros/middleware-fast-refresh.
To reproduce it, though, you need to wait ~20 seconds after the page is fully loaded or the last change was made. If you make a change before the ~20 seconds interval, the fast refresh works as expected. After that, any change to any part of the app triggers a full refresh.
There is a warning logged to the console, but it’s to fast to actually read it. In
next@canary
, the same warning is shown by the app before the full refresh so we can read it:Hi friends! Just want to say that we are aware of this issue on the next.js core team and are working towards getting a fix out. Really appreciate your patience here, and so sorry to everyone who this has inconvenienced!