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 as expected

See original GitHub issue

Bug report

Describe the bug

Fast refresh isn’t working as expected. Running the following code with next ^9.4.0 if I edit any

To Reproduce

	import { useState, useCallback } from 'react'
	
	export default () => {
	  const [counter, setCounter] = useState(0);
	  const incrementCount = useCallback(() => {
	    setCounter(x => x + 1)
	  }, [counter])
	
	  return (
	    <div className="container">
	      <h1>Hello Next!!</h1>
	      <button onClick={incrementCount}>
	        Clicked {counter} times
	      </button>
	    </div>
	  )
	}

(pages/index.tsx)

When I update any piece of code the page fully reload as usual… Am I doing something wrong?

Expected behavior

I expect the page to maintain the state.

System information

  • OS: macOS,
  • Browser (if applies) Firefox developer edition
  • Version of Next.js: 9.4
  • Version of Node.js: 13.1.0

Extra config

  • No next-config.js
  • Postcss and Sass are installed.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

12reactions
elderapocommented, May 21, 2020

It would be nice if next.js automatically generated/set names for defaultly exported arrow function pages.

For example:

// pages/home.ts

export default () => {
   return <div>Hello from the home page!</div>
}

could automatically be named: Home/HomePage.

3reactions
Rawnlycommented, May 14, 2020

Thank you! Resolved by adding displayName to the component.

const Page: NextPage = () => {
  ...
}

Page.displayName = 'MyPage'

export default Page;

Now it’s working as expected. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fast refresh not working properly due to page reload ... - GitHub
Hey! I was facing the same issue until I found the problem: something that is imported in the middleware and somewhere in the...
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 Refresh - React Native
Fast Refresh. Fast Refresh is a React Native feature that allows you to get near-instant feedback for changes in your React components.
Read more >
react-hot-loader - npm
React-Hot-Loader is expected to be replaced by React Fast Refresh. Please remove React-Hot-Loader if Fast Refresh is currently supported on ...
Read more >
7 Refreshing Materialized Views - Oracle Help Center
For materialized views that use the log-based fast refresh method, ... In addition, it helps to avoid potential problems such as materialized view...
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