Router Error Events in Shallow Routing by Skipping cancelHandler Creation #61772
Labels
bug
Issue was opened via the bug report template.
locked
Navigation
Related to Next.js linking (e.g., <Link>) and navigation.
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/elastic-christian-3yqgtv
To Reproduce
Current vs. Expected behavior
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000 Binaries: Node: 20.11.0 npm: 10.2.4 Yarn: 4.0.2 pnpm: 8.15.1 Relevant Packages: next: 14.1.0 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.3.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Routing (next/router, next/navigation, next/link)
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local)
Additional context
Problem
We've identified a bug within Next.js's pages router when utilizing the shallow routing API, specifically when invoking
router.replace
with the{ shallow: true }
option, like so:Shallow routing is designed to update the URL without running data fetching methods such as getServerSideProps, getStaticProps, or getInitialProps. However, a side effect of this process is that it skips the clean-up of the cancelHandler. This leads to router error events being fired erroneously, causing confusion and potential stability issues, as the system behaves as if an error occurred when, in fact, none did.
Solution
This PR addresses the issue by modifying the shallow routing logic to also skip the creation of the cancelHandler. Given that shallow routing operations are synchronous and do not involve data fetching or other asynchronous tasks that might need to be canceled, the cancelHandler is unnecessary in this context.
We have created a PR which would fix this behavior: #61771
The text was updated successfully, but these errors were encountered: