Skip to content

perf(react): re-render only the Links a navigation changes - #1026

Merged
cpojer merged 4 commits into
mainfrom
perf/link-status-url
Dec 4, 2026
Merged

cpojer merged 4 commits into
mainfrom
perf/link-status-url

Conversation

@TheAlexLichter

Copy link
Copy Markdown
Member

During a client navigation, the React Pages app re-rendered the whole current page and its layouts on every navigation state change (idle → loading → idle, plus transition updates).
Every Link also re-ran its status check each time.

On pages with many Links, that work runs right when the user clicks and is harming INP.

This PR:

  • Memoizes the route outlet, so a navigation state change no longer re-renders the page.
  • Has Links read their pending state from a store, so a visit re-renders only the Links whose pending state actually changes. Their current and active state is still worked out when the page changes.
  • Starts Links as not pending during hydration, matching what the server rendered.

There's no public API change and this PR only affects the React part.

Numbers

One navigation state change, on a synthetic page with one <Link> per list item (happy-dom, M-series Mac, median of 100 changes):

Links on page Before After
25 ~1.2 ms 0.20 ms
100 ~2.8 ms 0.26 ms
500 ~15–21 ms 0.60 ms
2000 ~81 ms 4.1 ms

Each visit goes through several of these changes. Memoizing the page alone only brings 500 Links down to ~14 ms, because each Link still subscribed to the navigation context. The gain needs both changes.

@TheAlexLichter
TheAlexLichter requested a review from cpojer December 3, 2026 18:48
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Cloudflare builds and deploys previews for this pull request. Learn more about Cloudflare previews.

Worker Status Deployment Commit
void-cloud Failed Not deployed a5045ae

Updated: Dec 3, 2026, 23:53 UTC

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix!

@cpojer
cpojer merged commit 4210a7c into main Dec 4, 2026
20 of 21 checks passed
@cpojer
cpojer deleted the perf/link-status-url branch December 4, 2026 00:05
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.

2 participants