vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.79k stars 26.95k forks source link

Navigating after pushState doesn't reset page #61406

Open Cretezy opened 9 months ago

Cretezy commented 9 months ago

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/vercel-next-js-reproduction-template-go8s7s?file=%2Fapp%2Flayout.tsx%3A5%2C13

To Reproduce

  1. Navigate from / to /other using location.pushState
  2. Try to navigate back to / using Link or router.push

Current vs. Expected behavior

After navigating from / to /other using location.pushState, it still renders to content from / but shows the URL as /other. This is working as expected.

However, when trying to navigate back to / (to reset the page), using Link or router.push changes the URL back to / (as expected) but does not reset the page. This also happens with router.refresh (either before or after navigation).

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 14.1.1-canary.23 // Latest available version is detected (14.1.1-canary.23).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, Routing (next/router, next/navigation, next/link)

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local)

Additional context

No response

zxqx commented 4 months ago

Seeing the same issue. Have tried alot of different workarounds, but none of them have been fruitful so far.