-
Notifications
You must be signed in to change notification settings - Fork 149
Description
Problem
When an annotation spans multiple blocks (e.g., text selected across two paragraphs), the highlight mark is not visually restored — though the annotation itself appears in the sidebar panel. This affects both shared URL restore and draft restore.
Root Cause
findTextInDOM() in Viewer.tsx searches for the annotation's originalText as a literal string in the DOM. For cross-block selections, originalText contains \n\n characters representing block boundaries. But in the rendered DOM, those boundaries are structural (<p> elements), not text node newlines — so the search fails silently.
The web-highlighter library already captures startMeta/endMeta (DOM path metadata) when annotations are created, and provides highlighter.fromStore(startMeta, endMeta, text, id) for exact restoration. However:
toShareable()stripsstartMeta/endMetafrom the compact tuple formatfromShareable()leaves themundefinedapplySharedAnnotations()falls back to text search, which fails for cross-block text
Affected Paths
- Shared URL restore (
useSharing.ts→applySharedAnnotations) - Draft restore (
useAnnotationDraft.ts→applySharedAnnotations)
Possible Fixes
- Include
startMeta/endMetain shareable format — extend the tuple to carry DOM metadata, then usehighlighter.fromStore()on restore - Fix
findTextInDOM()to handle cross-block text — normalize both search text and DOM text to handle structural block boundaries
Option 2 is more robust since it fixes all restore paths without changing the share payload format.
Key Files
packages/ui/components/Viewer.tsx—findTextInDOM(),applySharedAnnotations()packages/ui/utils/sharing.ts—toShareable(),fromShareable()packages/ui/types.ts—Annotation.startMeta/endMeta