question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cancel Rendering Route Error when Router Push hash

See original GitHub issue

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.15.0
      npm: 8.5.5
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 12.1.7-canary.26
      react: 18.1.0
      react-dom: 18.1.0

What browser are you using? (if relevant)

Google Chrome Version 102.0.5005.61 (Official Build) (arm64)

How are you deploying your application? (if relevant)

Locally and Vercel

Describe the Bug

Similar to https://github.com/vercel/next.js/issues/36830 (fixed by https://github.com/vercel/next.js/pull/36828)

trying to store more information in hash, getting “Cancel rendering route” error when pushing updated hash to router:

image

Expected Behavior

Pages changes without error.

To Reproduce

git clone https://github.com/michalbundyra/hash-cancel-rendering-route
cd hash-cancel-rendering-route
yarn
yarn dev
  1. Go to http://localhost:3000/
  2. Click “to world”
  3. Error pops!

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
domasrccommented, Jun 21, 2022

Having the same error just by clicking quickly on nav links with hashtag hrefs. Seems that the error is triggered when the hash link is clicked before it fully scrolled up/down to the hash clicked before.

React 18.1 / Next 12.1.6

3reactions
bordeocommented, Oct 19, 2022

I’m using this workaround

router
  .replace( // or push or whatever you want
    {
      pathname: window.location.pathname,
      hash: newHash,
      query: window.location.search,
    },
    null,
    {
      shallow: true,
    }
  )
  .catch((e) => {
    // workaround for https://github.com/vercel/next.js/issues/37362
    if (!e.cancelled) {
      throw e
    }
  })
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix Next.js error "cancel rendering route"?
I'm trying to link to a div id and I get this error: Error: Cancel rendering route. This seems to be a problem...
Read more >
Next.js Error: Cancel rendering route : r/nextjs - Reddit
I'm trying to link to a div id and I get this error: Error: Cancel rendering route This seems to be a problem...
Read more >
Shallow Routing - Next.js
Shallow routing allows you to change the URL without running data fetching methods again, that includes getServerSideProps , getStaticProps , and ...
Read more >
Understanding Next.js routeChangeStart and router events
For example, routing in Next.js is as easy as creating a set of pages for the app and ... The hashChangeStart and hashChangeComplete...
Read more >
errorElement v6.6.1 - React Router
When exceptions are thrown in loaders, actions, or component rendering, instead of the normal render path for your Routes ( <Route element> ),...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found