Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/8sfnt3
To Reproduce
- Make sure you are on the "Start Dev Server" terminal so you can see console logs.
- In the preview, you should see the next.js home page. Notice in terminal there will be console log showing
root layout and loading home.
- Add /project to the end of the urls and hit Enter (url should look like https://8sfnt3-3000.csb.app/project). You should see console log showing
root layout and loading project.
- Then press the back button on your mouse or using alt + left arrow (windows) or cmd + left arrow (mac).
- Notice that there are no console logs. If you modify the project/page.tsx file and then go back to /project, it's still showing the previous version.
Current vs. Expected behavior
Current behavior is that component codes do not rerun when directly accessing a url and then using back and forward. I have codes like useEffect that needs to run to initialize the component.
Expected behavior should run the component's code like useEffect and other logic.
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Pro N
Available memory (MB): 32699
Available CPU cores: 16
Binaries:
Node: 22.14.0
npm: 10.9.2
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 16.2.1 // Latest available version is detected (16.2.1).
eslint-config-next: N/A
react: 19.2.4
react-dom: 19.2.4
typescript: N/A
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Loading UI and Streaming
Which stage(s) are affected? (Select all that apply)
next dev (local)
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/8sfnt3
To Reproduce
root layoutandloading home.root layoutandloading project.Current vs. Expected behavior
Current behavior is that component codes do not rerun when directly accessing a url and then using back and forward. I have codes like
useEffectthat needs to run to initialize the component.Expected behavior should run the component's code like
useEffectand other logic.Provide environment information
Which area(s) are affected? (Select all that apply)
Loading UI and Streaming
Which stage(s) are affected? (Select all that apply)
next dev (local)