question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fast refresh not working properly due to page reload when compiling middleware

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Reactions:26
  • Comments:50 (13 by maintainers)

github_iconTop GitHub Comments

21reactions
henriqemalheiroscommented, Dec 27, 2021

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:

About to perform a full refresh

Fast Refresh will perform a full reload when you edit a file that is imported by modules outside of the React rendering tree. It is also possible the parent component of the component you edited is a class component, which disables Fast Refresh. Fast Refresh requires at least one parent function component in your React tree.

You can find more information in the related Webpack error below:

Cannot read properties of undefined (reading 'call')

You can read more about Fast Refresh in our documentation.

18reactions
jescalancommented, Feb 1, 2022

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!

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found