Skip to content

Reset pending route state on routeChangeError in usePendingRoute - #8756

Open
ShakilUrRehman21 wants to merge 1 commit into
reactjs:mainfrom
ShakilUrRehman21:fix-pending-route-cancelled
Open

ShakilUrRehman21 wants to merge 1 commit into
reactjs:mainfrom
ShakilUrRehman21:fix-pending-route-cancelled

Conversation

@ShakilUrRehman21

Copy link
Copy Markdown
Contributor

Summary

In src/hooks/usePendingRoute.ts, the hook only subscribed to routeChangeStart and routeChangeComplete. 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 fires routeChangeError rather than routeChangeComplete.

As a result:

  • setPendingRoute(null) was never invoked, leaving the clicked sidebar link stuck in its loading/pending state (isPending: true).
  • currentRoute.current remained populated with the aborted URL, preventing subsequent pending route indications to that path.

This PR adds a unified handleRouteChangeEnd handler that listens to both routeChangeComplete and routeChangeError and resets the currentRoute ref.

How was this tested?

  • Ran tsc --noEmit (passed with 0 errors).
  • Verified Prettier code style on src/hooks/usePendingRoute.ts.

@github-actions

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

Five Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/404 127.63 KB (🟡 +13 B) 242.77 KB
/500 127.63 KB (🟡 +13 B) 242.78 KB
/[[...markdownPath]] 130.12 KB (🟡 +13 B) 245.27 KB
/errors 127.88 KB (🟡 +13 B) 243.03 KB
/errors/[errorCode] 127.85 KB (🟡 +13 B) 243 KB
Details

Only 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 next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

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.

This branch was successfully deployed

1 active deployment
Preview — 433cc2ca Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant