Fix: highlight TOC link entry when on the page it points to (RND-11155) - #4476
Draft
zenoachtig wants to merge 2 commits into
Draft
Fix: highlight TOC link entry when on the page it points to (RND-11155)#4476zenoachtig wants to merge 2 commits into
zenoachtig wants to merge 2 commits into
Conversation
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 detectedLatest commit: a9bdbd8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Contributor
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
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.
Proposed changes
In a published site's table of contents, an entry of type
linkthat 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'spathnamesagainst the current page path (inToggleableLinkItemviauseCurrentPagePath), but link entries were rendered byPageLinkItemas a plainLinkwith no active logic and nopathnamesin their encoded payload.This change:
pathnamestoClientTOCPageLinkand populates it inencodeClientTableOfContentswhen a link resolves to a page in the current space. It reuses the samegetPagePaths(rootPages, resolvedPage)helper page entries use, so the two paths stay consistent.PageLinkItemcomputeisActivefrom thosepathnamesagainstuseCurrentPagePath(), and apply the samedata-active/aria-current="page"/ToCLinkItemActiveStylestreatment as page entries.To avoid over-highlighting,
pathnamesare only attached when the target iskind: '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 neededbunx turbo run typecheck --filter=gitbook→ 27/27 tasks successfulChangelog
🌙 Night-shift draft for Zeno (RND-11155) — kept as draft, not merged, no reviewers requested.
Generated by Claude Code