Skip to content

fix/site: Strip basePath from 404 page referrer link - #1902

Merged
marcleblanc2 merged 2 commits into
mainfrom
fix-404-referrer-base-path
Sep 11, 2026
Merged

fix/site: Strip basePath from 404 page referrer link#1902
marcleblanc2 merged 2 commits into
mainfrom
fix-404-referrer-base-path

Conversation

@marcleblanc2

Copy link
Copy Markdown
Contributor

Follow-up to #1887, found while smoke-testing production after today's merges.

Problem

On production the 404 page's "Go back to" link (built from document.referrer) rendered as Go back to /docs/cli with href /docs/docs/cli. document.referrer keeps the /docs basePath and next/link adds it again. The same code would also link a same-origin non-docs referrer (sourcegraph.com/pricing) into the docs.

Vercel previews serve at the root with an empty basePath, so #1887's preview could not show this.

Fix

Strip NEXT_PUBLIC_DOCS_BASE_PATH from the referrer pathname; ignore referrers outside the docs and the docs root (the home link already covers it).

Verification

Local production build (VERCEL_ENV=production pnpm build && pnpm start, Node 20) checked with headless Chrome on /docs/cli/references/prompts (a removed page):

Referrer Before After
/docs/cli Go back to /docs/cli → /docs/docs/cli Go back to /cli → /docs/cli
/docs/cli?x=1 Go back to /cli → /docs/cli?x=1
/pricing (same origin, not docs) Go back to /pricing → /docs/pricing no back link
/docs/ (root) Go back to /docs/ → /docs/docs/ no back link
none no back link no back link

"Go up to /cli/references" and "Go back home" unchanged in every case. Client-side navigation to a 404 (which uses usePreviousPathname, not the referrer) was already correct on production and is untouched.

npx tsc --noEmit (my file clean; pre-existing contentlayer/generated errors before a build), next lint, and prettier pass.

Amp thread

Co-authored-by: Amp amp@ampcode.com

@vercel

vercel Bot commented Sep 11, 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 11, 2026 2:57pm UTC

Request Review

@github-actions

This comment has been minimized.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Fixed in 2145ecf

marcleblanc2 and others added 2 commits September 11, 2026 08:55
document.referrer keeps the /docs basePath in production, and next/link
adds it again, so the 404 page's "Go back to" link pointed at
/docs/docs/<page>. Strip the basePath and ignore same-origin referrers
outside the docs (for example sourcegraph.com/pricing) or the docs root.

Vercel previews serve at the root with an empty basePath, which is why
the PR preview for #1887 did not show this.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a08e26-0c39-723b-95ad-65455002f541
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@marcleblanc2
marcleblanc2 force-pushed the fix-404-referrer-base-path branch from 2145ecf to 08cb42f Compare September 11, 2026 14:55
@marcleblanc2
marcleblanc2 merged commit d05265c into main Sep 11, 2026
4 checks passed
@marcleblanc2
marcleblanc2 deleted the fix-404-referrer-base-path branch September 11, 2026 14:57
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