Skip to content

Fix: highlight TOC link entry when on the page it points to (RND-11155) - #4476

Draft
zenoachtig wants to merge 2 commits into
mainfrom
zeno/rnd-11155-toc-link-active-highlight
Draft

Fix: highlight TOC link entry when on the page it points to (RND-11155)#4476
zenoachtig wants to merge 2 commits into
mainfrom
zeno/rnd-11155-toc-link-active-highlight

Conversation

@zenoachtig

Copy link
Copy Markdown
Contributor

Proposed changes

In a published site's table of contents, an entry of type link that points to a page was never highlighted as active, even when the visitor was on that exact page. Page entries (document) compute their active state client-side by comparing the page's pathnames against the current page path (in ToggleableLinkItem via useCurrentPagePath), but link entries were rendered by PageLinkItem as a plain Link with no active logic and no pathnames in their encoded payload.

This change:

  • Adds an optional pathnames to ClientTOCPageLink and populates it in encodeClientTableOfContents when a link resolves to a page in the current space. It reuses the same getPagePaths(rootPages, resolvedPage) helper page entries use, so the two paths stay consistent.
  • Makes PageLinkItem compute isActive from those pathnames against useCurrentPagePath(), and apply the same data-active / aria-current="page" / ToCLinkItemActiveStyles treatment as page entries.

To avoid over-highlighting, pathnames are only attached when the target is kind: 'page' (anchors excluded) and the resolved page is in the current space (resolved.space?.id === context.space.id), so external URLs, anchor links, and cross-space links never highlight.

Repro from the ticket: https://gitbook.com/docs/site-access/authenticated-access — the "link" TOC entry for that page now highlights when you are on it, matching the primary page entry.

Testing

Verified via typecheck. No automated test added: this is client-side rendering/navigation behavior (depends on Next.js routing params via useCurrentPagePath), which per the repo's testing guidance is better covered by a Playwright browser test than a low-signal mocked unit test. The pure path-computation piece (getPagePaths) is unchanged and already exists. Flagging this as a deliberate test gap appropriate for an XS draft — a follow-up Playwright assertion on TOC link active state could be added if desired.

Commands run (in an isolated worktree):

  • bunx @biomejs/biome format --write <changed files> → formatted, no fixes needed
  • bunx turbo run typecheck --filter=gitbook → 27/27 tasks successful

Changelog

  • [Fix] Highlight a table-of-contents link entry as active when it points to the page you are currently viewing.

🌙 Night-shift draft for Zeno (RND-11155) — kept as draft, not merged, no reviewers requested.


Generated by Claude Code

zenoachtig and others added 2 commits August 7, 2026 00:18
A table-of-contents entry of type "link" that resolves to a page in the
current space now computes its active state the same way page entries do,
comparing the target page's paths against the current page path. Anchor
targets and cross-space/external links are intentionally excluded to avoid
over-highlighting.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a9bdbd8

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

@linear-code

linear-code Bot commented Aug 7, 2026

Copy link
Copy Markdown

RND-11155

@argos-ci

argos-ci Bot commented Aug 7, 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) ⚠️ Changes detected (Review) 21 changed, 7 ignored Aug 7, 2026, 12:31 AM
customers-v2-vercel (Inspect) ⚠️ Changes detected (Review) 22 changed, 4 removed, 1 failure, 2 ignored Aug 7, 2026, 12:29 AM
v2-cloudflare (Inspect) ✅ No changes detected 4 ignored Aug 7, 2026, 12:31 AM
v2-vercel (Inspect) ✅ No changes detected 2 ignored Aug 7, 2026, 12:30 AM

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.

1 participant