Fix annotation deep-links from corpus-home Table of Contents#1495
Conversation
…ck routing
DocumentAnnotationIndex overloaded a single `embedded` prop for two distinct
purposes: visual layout ("render without an outer container") and click
routing ("we are already on the document page, just rewrite ?ann="). The
corpus-home Table of Contents (DocumentTableOfContents) needed the visual
flavor but is rendered on a /c/... URL — yet handleSectionClick treated the
shared prop as proof we were on a document page and silently rewrote ?ann=
onto the corpus URL, swallowing the deep link.
Split the concern: `embedded` is now purely visual, and a new explicit
`onDocumentPage` prop controls click routing. RightPanelContent (the only
call site actually on a document page) opts in.
Regression test in DocumentAnnotationIndex.test.tsx pins the contract —
verified to fail against the pre-fix code path and pass against the fix.
Code ReviewOverviewThis is a clean, minimal fix for a silent no-op bug in the corpus-home Table of Contents. The root cause — What's Good
Issues / SuggestionsMinor: Verbose comment in
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…-deep-links-ppMBa
corpusForVar is already typed as Parameters<typeof openedCorpus>[0], so the as any cast is unnecessary. Removing it brings the any baseline back to 460 (was 461).
Per CLAUDE.md, source comments should explain non-obvious WHY rather than reference past fixes. The handler is self-documenting via the onDocumentPage prop, and per-branch one-liners already cover intent. Bug context lives in the CHANGELOG and commit history.
Code ReviewOverviewThis PR fixes a real bug: clicking structural sections in the corpus-home Table of Contents silently no-op'd because The fix is clean and minimal. Strengths
Minor Issues1. In the 2. The tests correctly set What is Not Needed Here
SummarySolid, focused bug fix. The prop split is the right design, the tests are correct, and the CHANGELOG entry is thorough. The two items above are minor — the |
Summary
Fixed a bug where clicking structural sections in the corpus-home Table of Contents (e.g., "Subchapter I. Formation, p. 2") would silently fail to navigate to the document. The issue was caused by overloading the
embeddedprop to mean both "render without outer container" AND "we are already on the document page", causing the click handler to take the wrong routing branch.Key Changes
Separated concerns in
DocumentAnnotationIndex: Introduced a newonDocumentPageprop to explicitly indicate whether the component is being rendered inside the document page itself, independent of theembeddedvisual layout propembedded: Controls visual rendering (with/without outer container)onDocumentPage: Controls click routing behavior (update current URL vs. navigate to document)Updated click handler logic: Changed
handleSectionClickto useonDocumentPageinstead ofembeddedto determine routing behavior:onDocumentPage=true: Updates?ann=parameter on current URL (for in-document selection)onDocumentPage=false(default): Navigates to the document URL with?ann=preset (for corpus-level deep-linking)Updated call sites:
RightPanelContent.tsx: AddedonDocumentPage={true}when rendering the index inside the document pageAdded comprehensive regression tests: New test file
DocumentAnnotationIndex.test.tsxwith three test cases covering:embeddedno longer impliesonDocumentPageImplementation Details
The root cause was that the corpus-home Table of Contents call site needed the
embeddedvisual styling but was NOT on a document page. The original code conflated these two concerns, causing clicks to attempt updating?ann=on the corpus URL instead of navigating to the document. The fix makes the routing intent explicit through a dedicated prop while preserving backward compatibility (onDocumentPage defaults to false).https://claude.ai/code/session_01HFfDk339uN1JjJGv7eqQXr