Skip to content

fix: do not prefetch external sidebar links - #1978

Draft
marcleblanc2 wants to merge 1 commit into
marc/perf/sidebar-prefetchfrom
marc/fix/external-nav-links
Draft

marcleblanc2 wants to merge 1 commit into
marc/perf/sidebar-prefetchfrom
marc/fix/external-nav-links

Conversation

@marcleblanc2

Copy link
Copy Markdown
Contributor

Stacked on #1976 (marc/perf/sidebar-prefetch); retarget to main once that merges.

Problem

navigation.ts has Pricing and Changelog entries with href: 'https://sourcegraph.com/...'. next/link treats an absolute URL on the current origin as an app route, so every page load prefetched the marketing pricing page (65 KB of HTML in the HAR). On versioned docs, prependVersion also turns them into /v/<version>/https://sourcegraph.com/pricing.

Fix

  • NavigationLink renders a plain <a> for any http(s):// href.
  • prependVersion only prefixes paths that start with /.

Verification

tsc, pnpm lint, pnpm build clean. On the preview, the Network tab should show no request to sourcegraph.com/pricing on page load, and the Pricing link should still navigate.

@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

The Pricing and Changelog entries point at https://sourcegraph.com/...,
which next/link treats as an app route on our own origin, so every page
load prefetched the marketing pricing page (65 KB of HTML). Render those
as plain anchors, and stop prependVersion from turning them into
/v/<version>/https://... on versioned docs.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0ac9d-704f-73fe-8211-1b3e5840969f
Co-authored-by: Amp <amp@ampcode.com>
@marcleblanc2
marcleblanc2 force-pushed the marc/perf/sidebar-prefetch branch from e46d73d to 32ea28e Compare September 17, 2026 02:32
@marcleblanc2
marcleblanc2 force-pushed the marc/fix/external-nav-links branch from 4c29c24 to 89821fa Compare September 17, 2026 02:32
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Spell check found 1 issue(s) in this PR

Only findings on lines added by this PR, and in its title and description, are shown.

Pull request description

  • line 1, column 50
    • retargetretarded

Please correct the spelling, or add words which are correct to cspell-allow-list.txt.

Run npx cspell@10 --no-progress --dot '**/*' locally to check the full repository.

@marcleblanc2

Copy link
Copy Markdown
Contributor Author

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

Same root cause, one more instance outside this PR's files: the Changelog link in the desktop header (src/components/Layout.tsx:78) and mobile navigation (src/components/MobileNavigation.tsx:111) is also a next/link to https://sourcegraph.com/changelog. In the crawl that prefetch cost about 61 requests / ~500 KB per docs page and produced 1,155 "resource was preloaded but not used" console warnings. #2002 applies the same plain-<a> treatment to those two links.

marcleblanc2 added a commit that referenced this pull request Sep 18, 2026
#2002)

## Problem

- The Changelog link in the desktop header (`src/components/Layout.tsx`)
and mobile navigation (`src/components/MobileNavigation.tsx`) is a
`next/link` to `https://sourcegraph.com/changelog`

- Because it is same-origin in production, Next treats it as an app
route and prefetches the changelog app

- The audit measured 61 extra requests / ~500 KB on **every docs page
view**

## Fix

- Render both as plain `<a>`, the same approach #1978 takes for external
sidebar links

## Verification

- On a preview, the Network tab should show no `/changelog` chunk
requests after load

- Screenshot showing prod on the left, preview on the right, when
opening the left nav menu, prod has 137 requests, preview has 65

- Broken icon in prod in another PR, coming soon

<img width="2672" height="1521" alt="image"
src="https://github.com/user-attachments/assets/4f9a104f-cacc-4ebf-90fa-776da3b83eb1"
/>

- `npx tsc --noEmit` and `pnpm run lint` clean (0 errors)

Found by the docs site audit in [this Amp
thread](https://ampcode.com/threads/T-01a0ae50-f7f0-779c-aa66-3887c9953e33);
rebuilt locally in [this
one](https://ampcode.com/threads/T-01a0aed2-5fbe-7768-85ea-1378bf98f9ff).

Co-authored-by: Amp <amp@ampcode.com>
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