Replies: 6 comments 25 replies
-
If you do something like: // _app.tsx
import Router from 'next/router';
Router.events.on("routeChangeError", (err, url, { shallow }) => {
console.log("Navigating to: " + "url: " + url, {cancelled: err.cancelled} )
}); My guess would be that when I've managed to replicate this, by creating a slow page with In your case it must be that the E2E test clicks so fast that it interrupts the current rendering by moving on to the next step of the test. What do you think? It'd be nice if you could boil it down to a reproduction repository. |
Beta Was this translation helpful? Give feedback.
-
This does not result in a log in the console. I only see the uncaught error.
I'll try and create a create a small demo that recreates the error. Thanks for you time. I'll be back... |
Beta Was this translation helpful? Give feedback.
-
any solution to this error yet ? unable to resolve this issue... It came after I upgraded react to 18 either with next version 12 or 13 error is appearing... there is no hash routing in my app and it is only happening for dynamic routes. |
Beta Was this translation helpful? Give feedback.
-
To all whose ran into this problem after the update to React 18, check first if you are using If turning off strict mode solved your error it's probably related to changes in React 18 - https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-strict-mode - which intentionally leads to race condition. I recommend to taking a look at this thread: facebook/react#24502 |
Beta Was this translation helpful? Give feedback.
-
I'm amazed that this issue is still open and have no solution yet. Where's the NEXT team ? |
Beta Was this translation helpful? Give feedback.
-
This solution solved the issue: #37362 (comment) 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
}
}) |
Beta Was this translation helpful? Give feedback.
-
What does the error Error: cancel rendering route mean? I interpret it as a route is being rendered and before it is completed a new route render is started. Is that correct?
I currently get it, after upgrading to React 18, in our end-to-end tests where a modal (rendered in a portal) is opened and immediately closed using a close button. Click on the modal close button triggers router.push and thats where I get the error.
Beta Was this translation helpful? Give feedback.
All reactions