Skip to content

Resolve cross-space repository page URLs when rendering sites - #4619

Merged
taranvohra merged 10 commits into
mainfrom
taran/cross-space-page-resolution
Oct 2, 2026
Merged

taranvohra merged 10 commits into
mainfrom
taran/cross-space-page-resolution

Conversation

@taranvohra

@taranvohra taranvohra commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Proposed changes

Resolve repository URLs left by parallel Git Sync imports to pages in the same published site. API/import companion: https://github.com/GitbookIO/gitbook-x/pull/25900.

  • Match repository/ref and the most specific project directory before reading the target's main revision, with the same matcher as the GitBook editor (@gitbook/app-content-refs). A space syncing from the repository root counts too, and so does a space whose Git Sync was removed, through its remembered project URL. Anchors are decoded; the original URL is kept for ambiguous, missing, draft, or forbidden targets.
  • Links to hosts no site space syncs with skip matching altogether. Asset URLs keep their original URL after the page lookup finds no match.
  • Resolve matching URL refs automatically, with no opt-in flag. Asset URLs without a matching page retain their original URL.
  • Request fresh Git path metadata only for these lookups and attach the target space's purge tag to that cache entry. Existing API caches deduplicate target reads.

Relies on the API's Space.gitSync.installationProjectDirectory (omitted for the repository root) and Space.previousGitSync. Main revisions are intentional for now, with comments for future Site CR selection. Export path repair and published Markdown rewriting are outside this PR.

Validation: 82 focused tests passed, including a 500-space site that reads only one target space/revision, permissions denial, ambiguous matches, and resolving a previously missing target. Package typecheck passed. A production build passed before the final metadata-fetch wiring; the final wiring passed focused tests and typecheck.

# packages/gitbook
bun test src/lib/gitPageURL.test.ts src/lib/references.test.ts --preload ./tests/preload-bun.ts
bun run typecheck

Draft pending browser verification/demo. Includes the required separate changeset commit.

Changelog

  • [Feature] Resolve GitHub and GitLab page links to matching pages in the same published site after parallel Git Sync imports.

@changeset-bot

changeset-bot Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f6f9c48

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
gitbook Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@argos-ci

argos-ci Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
customers-v2-cloudflare (Inspect) 👍 Approved by Taran Vohra 2 changed, 2 ignored Oct 2, 2026, 12:35 PM
customers-v2-vercel (Inspect) ✅ No changes detected 5 ignored Oct 2, 2026, 12:33 PM
v2-cloudflare (Inspect) 👍 Approved by Taran Vohra 5 changed, 3 ignored Oct 2, 2026, 12:38 PM
v2-vercel (Inspect) ✅ No changes detected 2 ignored Oct 2, 2026, 12:36 PM

@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Style invalidation on a large API reference

Elements restyled by opening one popup on the Snyk API reference. A share near or above 100% means the insertion restyles the whole document.

interaction restyled page share budget
openapi-select 7 10,818 0.1% 25% ✅
search 631 10,818 5.8% 125% ✅

… links

Use the matcher the editor uses, which treats an omitted project directory as
the repository root, decodes anchors, accepts the www host and resolves spaces
whose Git Sync was removed. Links to other hosts no longer scan every site
space, and paths that cannot be pages no longer read a revision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
taranvohra and others added 2 commits October 2, 2026 14:25
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jpreynat jpreynat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One remaining issue with links to version folders.

Comment thread packages/gitbook/src/lib/references.tsx Outdated
…ders

Whether a path is a page folder or a file can only be told from the target
revision: guessing from its name skipped folders like `11.8`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@taranvohra

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T12:31:41.256853Z f6f9c48 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6f9c48f25

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/gitbook/src/lib/gitPageURL.ts
Comment thread packages/gitbook/src/lib/gitPageURL.ts
@taranvohra
taranvohra marked this pull request as ready for review October 2, 2026 12:43
Copilot AI balanced review requested due to automatic review settings October 2, 2026 12:43

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

URL-kind loss and inconsistent path normalization can resolve assets or ambiguous encoded paths to incorrect pages.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Resolves repository page URLs to matching pages across spaces in a published site.

Changes:

  • Adds Git repository URL and page-path matching.
  • Fetches revision metadata with space-aware cache invalidation.
  • Renders resolved URLs as internal links with comprehensive tests.
File Description
.changeset/​cross-space-repository-links.md Records the user-facing feature.
packages/​gitbook/​src/​lib/​gitPageURL.ts Implements repository URL matching.
packages/​gitbook/​src/​lib/​gitPageURL.test.ts Tests URL and page-path matching.
packages/​gitbook/​src/​lib/​references.tsx Resolves repository URLs across site spaces.
packages/​gitbook/​src/​lib/​references.test.ts Tests cross-space resolution behavior.
packages/​gitbook/​src/​lib/​data/​types.ts Adds the revision metadata option.
packages/​gitbook/​src/​lib/​data/​api.ts Fetches and caches revision metadata.
packages/​gitbook/​src/​lib/​context.ts Propagates metadata-fetch requests.
packages/​gitbook/​src/​components/​DocumentView/​InlineLink/​InlineLink.tsx Treats resolved URLs as internal links.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/gitbook/src/lib/gitPageURL.ts
Comment thread packages/gitbook/src/lib/gitPageURL.ts
@taranvohra
taranvohra merged commit dff0c79 into main Oct 2, 2026
25 checks passed
@taranvohra
taranvohra deleted the taran/cross-space-page-resolution branch October 2, 2026 13:01

This branch was successfully deployed

2 active deployments
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.

3 participants