Skip to content

perf: prefetch sidebar links on hover, not in viewport - #1976

Draft
marcleblanc2 wants to merge 1 commit into
mainfrom
marc/perf/sidebar-prefetch
Draft

marcleblanc2 wants to merge 1 commit into
mainfrom
marc/perf/sidebar-prefetch

Conversation

@marcleblanc2

Copy link
Copy Markdown
Contributor

Problem

Next prefetches every <Link> that enters the viewport. The sidebar shows dozens at once, so a single page view of /docs/batch-changes/delete-a-batch-change fetched 84 RSC payloads: 377 KB on the wire, 2.4 MB decoded, most of which the reader never clicks.

Fix

New NavigationLink wraps next/link with prefetch={hasIntent ? null : false}, flipping to the default prefetch on onMouseEnter/onFocus. This is the hover-triggered prefetch pattern from the Next docs. Navigation.tsx swaps Link for it at its three link sites; nothing else changes.

Tradeoffs

  • First click on a link the user never hovered (touch devices) is a normal, non-prefetched navigation. Static pages, so still fast.
  • prefetch={false} everywhere was the simpler option but also kills hover prefetch; this keeps it.
  • origin/enrique/sidebar-navigation touches Navigation.tsx; expect a small merge conflict at the import and the three <Link> tags.

Verification

tsc, pnpm lint, pnpm build clean. On the preview, open DevTools → Network, filter ?_rsc=: the page load should fetch a handful, not ~80; hovering a sidebar link should fetch its payload.

@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sourcegraph-docs Ready Ready Preview Sep 17, 2026 2:34am UTC

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

Next prefetches every <Link> that scrolls into view. The sidebar shows
dozens at once, so one page load fetched ~80 RSC payloads (377 KB on the
wire, 2.4 MB decoded). NavigationLink keeps prefetch off until the user
hovers or focuses the link, the pattern Next documents for large lists.
@marcleblanc2

Copy link
Copy Markdown
Contributor Author

From the docs site audit (crawl of all 502 pages).

Crawl numbers for the problem this PR fixes: ~35 RSC requests (/_tree + /__PAGE__) and ~168 KB per docs page from sidebar link prefetch, across all 502 pages.

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