Verify canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64
Binaries:
Node: 16.13.0
npm: 8.1.0
Yarn: 3.2.0
pnpm: N/A
Relevant packages:
next: 12.1.0
react: 18.0.0-rc.0
react-dom: 18.0.0-rc.0
What browser are you using? (if relevant)
Chrome 101.0.4899.0 same in FF and Safari
How are you deploying your application? (if relevant)
next dev, next start
Describe the Bug
Navigation to anchors should not cause any re-render; however, changing the hash through NextJs building blocks Link and Router does cause a re-render.
Re-rendering an entire app from _app and the respective page with the page's content can get quite substantial.
E.g., in our case, MDX and quite large React components get re-rendered. On the other hand, the re-rendering leads us to identify a hard-to-track problem in loading MDX components, but this is off-topic to the current issue.
Looking at the sources, it seems the function of the router does not lead to a state change, which causes a re-rendering because the operations target Html primitives primarily. Logging the hashChangeStart and hashChangeComplete events seems something is causing a re-render afterward; maybe a new page-props object gets created, but this is just a vague assumption.
Another thing we see is when triggering an identical hash change several times using NextJs Link and Router primitives; the re-rendering occurs multiple times, one for each interaction. In this case, the browser history seems to be intact; a second click on the same link does not cause a push of another state to browser history; the browser's back button works; in any case, a re-render of the app gets executed.
Expected Behavior
Do not perform re-rendering if it is not needed.
To Reproduce
The sources of the reproducer are here. https://github.com/gurkerl83/NextJs-Hash-Bug
- Clone the repo
- Install dependencies
- Run development respectively production
- Follow the instructions in the apps index page and see the console / http://localhost:3000
The link to the deployed version
https://next-js-hash-bug.vercel.app
Thx!
Verify canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64
Binaries:
Node: 16.13.0
npm: 8.1.0
Yarn: 3.2.0
pnpm: N/A
Relevant packages:
next: 12.1.0
react: 18.0.0-rc.0
react-dom: 18.0.0-rc.0
What browser are you using? (if relevant)
Chrome 101.0.4899.0 same in FF and Safari
How are you deploying your application? (if relevant)
next dev, next start
Describe the Bug
Navigation to anchors should not cause any re-render; however, changing the hash through NextJs building blocks Link and Router does cause a re-render.
Re-rendering an entire app from _app and the respective page with the page's content can get quite substantial.
E.g., in our case, MDX and quite large React components get re-rendered. On the other hand, the re-rendering leads us to identify a hard-to-track problem in loading MDX components, but this is off-topic to the current issue.
Looking at the sources, it seems the function of the router does not lead to a state change, which causes a re-rendering because the operations target Html primitives primarily. Logging the hashChangeStart and hashChangeComplete events seems something is causing a re-render afterward; maybe a new page-props object gets created, but this is just a vague assumption.
Another thing we see is when triggering an identical hash change several times using NextJs Link and Router primitives; the re-rendering occurs multiple times, one for each interaction. In this case, the browser history seems to be intact; a second click on the same link does not cause a push of another state to browser history; the browser's back button works; in any case, a re-render of the app gets executed.
Expected Behavior
Do not perform re-rendering if it is not needed.
To Reproduce
The sources of the reproducer are here. https://github.com/gurkerl83/NextJs-Hash-Bug
The link to the deployed version
https://next-js-hash-bug.vercel.app
Thx!