vercel / next.js

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

v12.2 up to v12.3.2-canary.22 handleHardNavigation Invariant: attempted to hard navigate to the same URL #38171

Closed willemliufdmg closed 2 years ago

willemliufdmg commented 2 years ago

Verify canary release

Provide environment information

Deployed to Vercel

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 16.13.1
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 12.3.2-canary.22
      eslint-config-next: 12.3.1
      react: 18.2.0
      react-dom: 18.2.0

What browser are you using? (if relevant)

Not relevant

How are you deploying your application? (if relevant)

Vercel

Describe the Bug

It seems that since Next.js v12.2 the internal router does an extra fetch for the current page.js. This didn't happen in the older versions of Nextjs (see screenshots below). If the current URL is a dynamic route and is rewritten (our case in Middleware) the extra page.js fetch will result in a 404. This causes an attempt to reload the current page which then runs into the handleHardNavigation error Invariant: attempted to hard navigate to the same URL.

Current production Next.js v12.1: image

Develop Next.js v12.2: image image

Expected Behavior

Should just load the page without errors.

Link to reproduction

https://router-3zllgxvkw-fdmediagroep.vercel.app/nieuws

To Reproduce

Minimal reproduction repo: https://github.com/FDMediagroep/router-bug

Next Middleware rewrite rules:

    ...
    {
      source: /^\/nieuws$/,
      destination: '/nieuws/overview/1',
    },
    {
      source: /^\/nieuws\?page=(?<pageNr>\d+)/gi,
      destination: '/nieuws/overview/$<pageNr>',
    },
    ...

Navigating to /nieuws will result in the error as described in the bug description for Next.js since v12.2. But not on the older version v12.1.

dimitrisdi commented 2 years ago

Just updated to Next 13.0 and i am still facing the same issue. Sentry is getting destroyed by this error.

maria404 commented 2 years ago

Updated to 12.3.2 and still have this issue.

luukdv commented 2 years ago

@shadowgroundz @dimitrisdi @maria404 I don't think the Next team will act on a closed issue, so might be better to open a new one.

ijjk commented 2 years ago

Hi, if you are still seeing this error it appears to be unrelated to the initial issue described here as that is now resolved, please open a fresh issue with reproduction.

shadowgroundz commented 2 years ago

@shadowgroundz @dimitrisdi @maria404 I don't think the Next team will act on a closed issue, so might be better to open a new one.

Must I open a new ticket for same issue while that still exist on newer version?

soren121 commented 2 years ago

@shadowgroundz What they mean is, if you're still getting the error, then it must have a different root cause than the issue in this ticket. For that, you should open a new ticket so the team can examine your issue.

github-actions[bot] commented 1 year ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.