fix: register destinations only once for wrapped text#3309
Open
XiaoTianFan wants to merge 1 commit intodiegomura:masterfrom
Open
fix: register destinations only once for wrapped text#3309XiaoTianFan wants to merge 1 commit intodiegomura:masterfrom
XiaoTianFan wants to merge 1 commit intodiegomura:masterfrom
Conversation
When text with an `id` wraps across multiple pages, the layout engine creates multiple fragments that all inherit the same `id` prop. Previously, each fragment would call `addNamedDestination`, causing later fragments to overwrite earlier ones. This broke reverse links (endnote → superscript) because the destination would point to the wrong page. Solution: - Track registered destinations using a Set in RenderOptions - Only register the FIRST occurrence of each ID - Subsequent occurrences (from wrapping) are silently skipped This ensures destinations always point to the first page where the content appears, enabling correct bidirectional links in academic documents with endnotes/footnotes. Fixes diegomura#2110, diegomura#2377, diegomura#2700 Co-Authored-By: Claude <noreply@anthropic.com>
|
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.
Problem
When text with an
idprop wraps across multiple pages, the layout engine creates multiple fragments that all inherit the sameid. Each fragment callsaddNamedDestination, causing later fragments to overwrite earlier ones. This breaks reverse links (e.g., endnote → superscript) because the destination points to the wrong page.Solution
Implement "first occurrence wins" semantics:
SetinRenderOptionsThis ensures destinations always point to the first page where the content appears, enabling correct bidirectional links in academic documents with endnotes/footnotes.
Changes
Core Implementation (4 files)
packages/render/src/types.tsregisteredDestinations: Set<string>toRenderOptionspackages/render/src/index.tsregisteredDestinations: new Set<string>()packages/render/src/operations/setDestination.tsaddNamedDestinationpackages/render/src/primitives/renderNode.tsoptionsparameter tosetDestinationTests (1 file)
packages/render/tests/operations/setDestination.test.tsExample (2 files)
packages/examples/vite/src/examples/endnote/index.tsxpackages/examples/vite/src/examples/index.tsExample Structure Requirements
Important: For inline destinations to work correctly:
idmust be on block-level elements (View, Image), not inline ViewsLinkmust wrap content directly for proper clickable areas✅ Correct:
❌ Incorrect:
Breaking Changes
None. This is a pure bug fix with no API changes.
Related Issues
Fixes #2110 (Destinations Undocumented but Functional)
Fixes #2377 (Destinations handling for multiple pages)
Related to #2700 (Bookmarks all link to last page)
Related to PR #746 (Go-to functionality)