fix/site: Search results link to current instance - #1875
Merged
Conversation
|
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
marcleblanc2
enabled auto-merge (squash)
September 10, 2026 00:50
pjlast
approved these changes
Sep 11, 2026
marcleblanc2
added a commit
that referenced
this pull request
Sep 11, 2026
## Problem - Vercel bot's build preview comment on every docs PR links to the **root** (home page) of the preview deployment - When your PR changes only one page, you still have to click through the preview site to find it (search to be fixed in PR #1875) - Vercel has no setting to link directly at your changed page ## Solution - Adding our own PR comment with links to the pages your PR changes, as shown here #1891 (comment) ## Decisions made, and can be changed - Link list length capped at 40 pages - Deleted files are excluded - Renamed files link to the new path - PRs that change no `docs/` pages get no comment ## Amp threads - [Vercel preview page links](https://ampcode.com/threads/T-01a07e6e-2b53-73cb-be1c-faaf2308d033) - [Address PR 1874 feedback](https://ampcode.com/threads/T-01a08573-3d6c-7491-ac34-61b4800612a8) --------- Co-authored-by: Amp <amp@ampcode.com>
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
marcleblanc2
force-pushed
the
search-results-relative-urls
branch
from
September 11, 2026 01:17
880e095 to
46a88b8
Compare
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), searching for something, then clicking on a search result always takes you to
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
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 unchangedAmp threads