Skip to content

Add a navigate action to integration block webframes#4362

Merged
gregberge merged 9 commits into
mainfrom
greg/rnd-11604-provide-current-page-pathid-to-webframe-in-integration-block
Jul 10, 2026
Merged

Add a navigate action to integration block webframes#4362
gregberge merged 9 commits into
mainfrom
greg/rnd-11604-provide-current-page-pathid-to-webframe-in-integration-block

Conversation

@gregberge

@gregberge gregberge commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What

Lets an integration block webframe navigate the reader to another page in the site, over the client-only webframe postMessage channel (the same channel as adaptive visitor claims):

  • @webframe.navigate — a webframe posts this action to navigate the reader to another page in the site, addressed by path (with an optional anchor). The path is resolved against the site base path, so a webframe can link to a page in any section or space of the site — and nowhere outside it.

Navigation is resolved entirely client-side (never through the integration render request), so the integration render cache is unchanged, and it drives the standard navigation progress bar.

Usage (from inside a webframe)

The webframe communicates with GitBook over postMessage, exactly like the existing resize/ready protocol. Post a @webframe.navigate action with a site-root-relative path:

// Navigate to another page in the site
window.parent.postMessage(
    { action: { action: '@webframe.navigate', path: 'getting-started/quickstart' } },
    '*'
);

// Optionally scroll to a heading anchor
window.parent.postMessage(
    { action: { action: '@webframe.navigate', path: 'getting-started/quickstart', anchor: 'installation' } },
    '*'
);

Why

RND-11604 — integrations (e.g. harness) need to navigate the reader to other pages within the site from a webframe. Docs: GitbookIO/integrations#1230.

How it's wired

  • The ContentKit client context exposes navigate({ path, anchor? }); ElementWebframe maps the @webframe.navigate message to it.
  • The path is resolved on the client through the (tested) GitBookLinker (toPathInSite), rebuilt from serializable data passed by IntegrationBlock — no duplicated join logic, no server round-trip.

Notes

  • No new integration scope, and no @gitbook/api or backend change — the gitbook-x companion PR was closed.
  • Scope was reduced during review: the earlier state.page current-page context and pageId-based navigation were removed; this PR now only adds @webframe.navigate by path. Pre-existing visitor claims are unchanged.

Test plan

  • bun run typecheck — 27/27
  • bun test on adaptive.test.ts — 3/3
  • biome check on changed files — clean

🤖 Generated with Claude Code

gregberge and others added 2 commits July 3, 2026 14:07
Expose the current page (id, path, title) to integration block webframes via the client-only webframe state, reusing the same postMessage channel as adaptive visitor claims. The page is sourced from the block's server-side content context rather than the integration render request, so the integration render cache is unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Only expose the current page to a webframe when the integration's render output declares it can access page context (canAccessPageContext), mirroring canAccessVisitorClaims. The @gitbook/api type does not yet include the flag, so the read is temporarily annotated with @ts-expect-error.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Jul 3, 2026

Copy link
Copy Markdown

RND-11604

@changeset-bot

changeset-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a5f3b7e

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

This PR includes changesets to release 2 packages
Name Type
@gitbook/react-contentkit Patch
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 Jul 3, 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 Greg Bergé 181 changed, 3 ignored Jul 10, 2026, 8:53 AM
customers-v2-vercel (Inspect) 👍 Approved by Greg Bergé 105 changed, 41 ignored Jul 10, 2026, 8:52 AM
v2-cloudflare (Inspect) 👍 Approved by Greg Bergé 29 changed, 6 ignored Jul 10, 2026, 8:55 AM
v2-vercel (Inspect) 👍 Approved by Greg Bergé 30 changed Jul 10, 2026, 8:53 AM

Per review (avoid another customer-specific integration scope): expose the current page to webframes unconditionally, since path/id/title are non-sensitive (no shareKey or token). Also add a @webframe.navigate action so a webframe can navigate the reader to another page within the space, resolved client-side against the space base path via the router.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Address review: resolve the @webframe.navigate action against the site base path (toPathInSite) rather than the current space, so a webframe can navigate to a page in any section or space of the site.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread packages/react-contentkit/src/context.ts Outdated
Comment thread packages/react-contentkit/src/context.ts
Comment thread packages/react-contentkit/src/context.ts
Give `getPageContext` a concrete `{ page: { id, path, title } }` shape
instead of `Record<string, unknown>`, and split webframe navigation into
`navigateToPath` (sync, resolved against the site base path) and
`navigateToPageId` (async, resolved against the site's page tree via a
server action) so a webframe can address a destination either way.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Route webframe `navigateToPath`/`navigateToPageId` through
`onNavigationClick` before `router.push`, so a reader gets the same
top loading bar feedback as a regular in-app link click (previously
these bypassed the navigation status and showed nothing).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread packages/gitbook/src/components/DocumentView/Integration/server-actions.tsx Outdated
Address review: stop duplicating the linker's path-join logic and drop the
async server action for page-id resolution.

- Rebuild the (tested) `GitBookLinker` on the client from serializable data
  passed by `IntegrationBlock`, and resolve `navigateToPath` via
  `linker.toPathInSite` (removes the hand-rolled `joinPath`).
- Ship a compact `{ pageId: path }` map (built server-side from the current
  revision) so `navigateToPageId` resolves synchronously against real pages,
  removing `resolveWebframePagePath` and its site-context refetch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collapse `navigateToPath`/`navigateToPageId` into one `navigate(target)`
accepting `{ path, anchor? } | { pageId, anchor? }`, branching on the
destination kind internally.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread packages/gitbook/src/components/DocumentView/Integration/adaptive.ts Outdated
Reduce the webframe integration to navigation by path only:

- Remove the current-page context (`state.page` / `getPageContext` /
  `getWebframePageContext`) and its types.
- Remove `pageId` from `@webframe.navigate` and the supporting page-path
  map (`getWebframePagePaths`).

`navigate({ path, anchor? })` resolves client-side via the rebuilt linker;
pre-existing visitor claims are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gregberge gregberge changed the title Provide current page to integration block webframes Add a navigate action to integration block webframes Jul 10, 2026
@gregberge gregberge merged commit cb92754 into main Jul 10, 2026
17 checks passed
@gregberge gregberge deleted the greg/rnd-11604-provide-current-page-pathid-to-webframe-in-integration-block branch July 10, 2026 09:24
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.

2 participants