Skip to content

Browser back/foward doesn't rerun component code #91982

@Rc85

Description

@Rc85

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/8sfnt3

To Reproduce

  1. Make sure you are on the "Start Dev Server" terminal so you can see console logs.
  2. 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.
  3. 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.
  4. Then press the back button on your mouse or using alt + left arrow (windows) or cmd + left arrow (mac).
  5. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions