Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Invariant: attempted to hard navigate to the same URL #65561

Open
igorwessel opened this issue May 9, 2024 · 0 comments
Open

Error: Invariant: attempted to hard navigate to the same URL #65561

igorwessel opened this issue May 9, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@igorwessel
Copy link

igorwessel commented May 9, 2024

Link to the code that reproduces this issue

https://github.com/igorwessel/next14-canary-hard-navigate-issue

To Reproduce

  1. Run the build command in the project: npm run build
  2. Start the server with npm run start (Production)
  3. Access the localhost:3000, and stay on the route "/"
  4. Repeat steps 1 and 2 to simulate a new deployment
  5. With the previous page still open with the old deployment, click on "Current Page". This will trigger the error.

Current vs. Expected behavior

I expected Next.js to perform a hard-refresh when it receives a 404 status code from the JSON of the dynamic route, similar to what happens when it navigates to another page. However, I observed that the error Error: Invariant: attempted to hard navigate to the same URL is thrown.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 18.20.1
  npm: 10.5.0
  Yarn: 1.22.22
  pnpm: 8.15.7
Relevant Packages:
  next: 14.3.0-canary.51 // Latest available version is detected (14.3.0-canary.51).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: N/A
Next.js Config:
  output: standalone

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

Navigation

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

Other (Deployed)

Additional context

Occurs in next@12.3.4 too

From our understanding of the previous issue, Next.js should perform a hard-refresh when it receives a 404 while trying to perform data-fetching on a dynamic page with some data-fetching method like getServerSideProps. Currently, this error occurs on the same page, but it does not happen if we go to another page.

If this is not a bug, how can we solve this problem/mitigate given that requests to .next/data/{buildId} are dynamic?

Gravacao.de.Tela.2024-05-09.as.07.08.09.mov
@igorwessel igorwessel added the bug Issue was opened via the bug report template. label May 9, 2024
@github-actions github-actions bot added the Navigation Related to Next.js linking (e.g., <Link>) and navigation. label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

No branches or pull requests

1 participant