fix/site: Strip basePath from 404 page referrer link - #1902
Open
marcleblanc2 wants to merge 2 commits into
Open
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This comment has been minimized.
This comment has been minimized.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
jac
approved these changes
Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.referrerkeeps the/docsbasePath andnext/linkadds 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_PATHfrom 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):/docs/cli/docs/docs/cli/docs/cli/docs/cli?x=1/docs/cli?x=1/pricing(same origin, not docs)/docs/pricing/docs/(root)/docs/docs/"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-existingcontentlayer/generatederrors before a build),next lint, and prettier pass.Amp thread
Co-authored-by: Amp amp@ampcode.com