Repository navigation
Reset pending route state on routeChangeError in usePendingRoute - #8756
ShakilUrRehman21 wants to merge 1 commit into
Conversation
Size changesDetails📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 Five Pages Changed SizeThe following pages changed size from the code in this PR compared to its base branch:
DetailsOnly the gzipped size is provided here based on an expert tip. First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If Any third party scripts you have added directly to your app using the Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this. |
Summary
In
src/hooks/usePendingRoute.ts, the hook only subscribed torouteChangeStartandrouteChangeComplete. When a navigation transition is cancelled or encounters an error (for example, clicking a different link before the pending route finishes loading, or navigating back), Next.js firesrouteChangeErrorrather thanrouteChangeComplete.As a result:
setPendingRoute(null)was never invoked, leaving the clicked sidebar link stuck in its loading/pending state (isPending: true).currentRoute.currentremained populated with the aborted URL, preventing subsequent pending route indications to that path.This PR adds a unified
handleRouteChangeEndhandler that listens to bothrouteChangeCompleteandrouteChangeErrorand resets thecurrentRouteref.How was this tested?
tsc --noEmit(passed with 0 errors).src/hooks/usePendingRoute.ts.