fix/site: Link search results to current site instead of assuming prod - #1875
Open
marcleblanc2 wants to merge 1 commit into
Open
fix/site: Link search results to current site instead of assuming prod#1875marcleblanc2 wants to merge 1 commit into
marcleblanc2 wants to merge 1 commit into
Conversation
The Algolia crawler indexes production, so every hit URL is absolute (https://sourcegraph.com/docs/...). DocSearch rendered those verbatim, so selecting a result on a Vercel preview (or local dev) always jumped to prod. Pass a transformItems to DocSearch that strips the prod prefix and prepends NEXT_PUBLIC_DOCS_BASE_PATH, so hrefs resolve against the deployment being viewed: /docs/<path> in prod, /<path> on previews. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a07e6c-cddd-72b1-b3bf-98ad32f9d55a
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
marcleblanc2
marked this pull request as ready for review
September 8, 2026 01:35
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
On a Vercel preview deployment (or local dev), selecting a search result always navigates to production (
https://sourcegraph.com/docs/...) instead of the matching page on the deployment you're viewing.Cause: the Algolia crawler indexes prod, so every hit's
urlis an absolute prod URL. The vendored DocSearch renders it verbatim inHit.tsx(<a href={hit.url}>) and returns it fromgetItemUrl(Enter-key navigation), so nothing ever makes it relative to the current origin.Fix
Pass a
transformItemstoDocSearchinsrc/components/search/Search.tsxthat rewriteshttps://sourcegraph.com/docs/<path>→${NEXT_PUBLIC_DOCS_BASE_PATH}/<path>.NEXT_PUBLIC_DOCS_BASE_PATHis already/docsin production and''elsewhere (seenext.config.js), so:/docs/batch-changes/view-batch-changes#viewing-batch-changes(same target as today)/batch-changes/view-batch-changes#viewing-batch-changes, resolved against the current origintransformItemsruns beforesaveRecentSearch, so recent/favorite searches persisted in localStorage get the rewritten URL too. URLs that don't start with the prod prefix are left untouched.Not changed
Verification
Ran locally (
pnpm dev, empty base path, same as preview):href="/batch-changes/..."and resolve tohttp://localhost:<port>/batch-changes/....http://localhost:<port>/batch-changes/view-batch-changes#viewing-batch-changes.localStorage.__DOCSEARCH_RECENT_SEARCHES__sourcegraphstored the relative URL.npx tsc --noEmitpasses.Vercel preview (this PR)
Tested on the preview deployment
https://sourcegraph-docs-c9sonegt9-sourcegraph-f8c71130.vercel.app:/batch-changes/view-batch-changes#viewing-batch-changes→https://sourcegraph-docs-c9sonegt9-sourcegraph-f8c71130.vercel.app/batch-changes/view-batch-changes#viewing-batch-changes.<h1>"Viewing Batch Changes"), not tosourcegraph.com/docs./batch-changes/view-batch-changes#viewing-batch-changes.Production behavior (
/docs/<path>prefix) is unchanged by design but can only be confirmed after merge.Amp threads