Serve site at a consistent, configurable basePath, for all deployments - #1977
Open
marcleblanc2 wants to merge 6 commits into
Open
marcleblanc2 wants to merge 6 commits into
marcleblanc2 wants to merge 6 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
This comment has been minimized.
This comment has been minimized.
marcleblanc2
force-pushed
the
marc/fix/mark-svg-base-path
branch
from
September 17, 2026 02:32
e1678da to
43372c6
Compare
marcleblanc2
force-pushed
the
marc/fix/mark-svg-base-path
branch
from
September 17, 2026 08:46
f3ed48d to
0e71382
Compare
marcleblanc2
marked this pull request as ready for review
September 17, 2026 09:49
Production serves under /docs. next/link adds the prefix, <img> and next/image do not, so /sourcegraph-mark.svg in the mobile nav and the LinkCards/ProductCards icons, plus a couple of root-relative markdown images, 404 on sourcegraph.com.
Amp-Thread-ID: https://ampcode.com/threads/T-01a0ae6a-1645-702a-a5ed-92f8b9bce33b Co-authored-by: Amp <amp@ampcode.com>
Previews and local dev served at / while production served at /docs, so a root-relative <img src> only 404d after deploy. Use basePath /docs everywhere; the / -> /docs redirect from #1955 now applies to every deployment. Update the tooling that assumed previews had no basePath. Amp-Thread-ID: https://ampcode.com/threads/T-01a0ae6a-1645-702a-a5ed-92f8b9bce33b Co-authored-by: Amp <amp@ampcode.com>
basePath is declared once, in docs.config.js. next.config.js reads it for
routing; everything that builds a URL Next does not prefix (img src, a href,
fetch, metadata, proxy redirects) goes through withBasePath or reads the
constant, instead of nine copies of process.env.NEXT_PUBLIC_DOCS_BASE_PATH
or a hardcoded '/docs'.
proxy.ts: request.nextUrl.pathname already excludes the basePath, so the
path.replace('/docs', '') was a no-op that would have mangled any real
path containing '/docs'. Removed.
Amp-Thread-ID: https://ampcode.com/threads/T-01a0ae6a-1645-702a-a5ed-92f8b9bce33b
Co-authored-by: Amp <amp@ampcode.com>
/v/<latest>/x and /@<latest>/x redirected to https://sourcegraph.com/docs/x even from a preview or local dev, so a reviewer testing those paths on a preview silently landed on production. The current deployment serves the latest version, so redirect to its own origin + DOCS_BASE_PATH instead. Also merges the identical /v/ and /@ branches. Amp-Thread-ID: https://ampcode.com/threads/T-01a0ae6a-1645-702a-a5ed-92f8b9bce33b Co-authored-by: Amp <amp@ampcode.com>
The basePath has moved three times. Next time, change DOCS_BASE_PATH (and DOCS_PROD_ORIGIN if the host moves) in docs.config.js and nothing else: - versions.ts, api/versions, VersionSelector, sitemap, robots, Search and the layout canonical/metadataBase read DOCS_BASE_PATH / DOCS_PROD_URL instead of spelling out /docs or https://sourcegraph.com/docs - check-redirects, check-links (self-link regex) and verify-links-live import docs.config.js - preview-links.yml checks out the PR's docs.config.js to build page URLs - search.ts searchDocumentsPath is root-relative like every public/ path; it is only a flag for writing public/search.json .amp/services.yaml is YAML and keeps its literal path, with a note. Amp-Thread-ID: https://ampcode.com/threads/T-01a0ae6a-1645-702a-a5ed-92f8b9bce33b Co-authored-by: Amp <amp@ampcode.com>
marcleblanc2
force-pushed
the
marc/fix/mark-svg-base-path
branch
from
September 17, 2026 09:50
bead7e1 to
87b9d78
Compare
This was referenced Sep 17, 2026
Contributor
Author
|
From the docs site audit (crawl of all 502 pages). The crawl confirms the three broken-image sources this PR fixes (
|
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.
Problem
The doc site has moved a few times over the years, and will move again in the coming months
The whiplash of these moves has resulted in a hot mess of adaptations
This PR sets a consistent pattern:
The many different adaptations to decipher these have been centralized on these configs
Production serves the site at
sourcegraph.com/docsPreviews and local dev have served it at either
/or/docsat different times in history, most recently/Root-relative URLs which Next.js does not prefix (
<img src>,<a href>,fetch()) therefore only broke in productionChange
Serve every deployment under
/docs/redirects to/docsin dev / preview, so preview URLs andlocalhost:3000still land on the siteFix the broken images with
withBasePath(url)insrc/lib/utils.tsDeclare the basePath once, as
DOCS_BASE_PATHindocs.config.js, replacing nineprocess.env.NEXT_PUBLIC_DOCS_BASE_PATHcopies and a hardcoded/docsinsrc/proxy.tsDeclare the production origin once, as
DOCS_PROD_ORIGINindocs.config.js;sitemap.ts,robots.ts,layout.tsxmetadata,api/versions,Search.tsx, and thedev/check-*.mjsscripts andpreview-links.ymlworkflow all readdocs.config.jsinstead of spellinghttps://sourcegraph.com/docsthemselves/v/<latest>/xredirects to the current deployment's/docs/xinstead of production, so previews can be tested end to endUpdate dev tooling and docs that assumed previews had no basePath
Verification
tscandeslintcleannext dev://docs/docs/self-hosted/deploy<img src>starts with/docs//docs/self-hosted/deploy.md/docs/v/6.0/codyhttps://6.0.sourcegraph.com/cody/docs/v/7.7/cody<same host>/docs/cody/docs/integration/img/disable_extension.png/docs/integration/img/disable-extension.pngOn
main, the same local setup renderssrc="/sourcegraph-mark.svg"and it 404s: this bug would have been caught on a preview.