Commit 91f57ad
authored
feat(ui): highlight external SSE annotations inline on plan text (#511)
* feat(ui): highlight external SSE annotations inline on plan text
External annotations posted via /api/external-annotations previously
appeared in the sidebar only. They now highlight the matching `originalText`
span in the rendered plan, giving tools (linters, agents) an optional way
to attach feedback to specific phrases — while `GLOBAL_COMMENT` (or any
annotation without `originalText`) still degrades to sidebar-only.
Implementation is a new focused hook that drives the Viewer's existing
imperative `applySharedAnnotations` / `removeHighlight` API, reusing the
same DOM text-search path that share-URL restoration uses. No protocol
change, no schema change to `transformPlanInput`, and App.tsx gains only
a single hook call.
The hook tracks applied ids with a type+originalText fingerprint so SSE
updates correctly remove+reapply, clears its bookkeeping only on plan
markdown change (where blocks re-render), and early-returns (preserving
state) while diff view or a linked doc overlay is active so SSE removals
arriving under those conditions still reconcile when the hook re-enables.
For provenance purposes, this commit was AI assisted.
* fix(ui): repaint external SSE highlights after share import, clean dead code
Addresses three review findings on the external annotation highlight hook:
- Share-import wipe: `importFromShareUrl` merges annotations without
changing `markdown`, so our `planKey` stayed stable. The share-apply
effect in App.tsx calls `clearAllHighlights()` to reset the DOM before
applying imported annotations — which also wiped live external SSE
highlights. The hook believed they were still painted and never re-drove
them, leaving sidebar entries with no visible highlight until the next
SSE event. Fix: hook now exposes a `reset()` that clears its applied-set
and re-runs the main effect via a counter; App.tsx calls it right after
`clearAllHighlights()` in the share-apply path.
- Removed a dead `nextIds.has(a.id)` guard inside the apply timer callback.
`toAdd` is computed as a subset of `eligible`, and `nextIds` was built
from `eligible.map(.id)`, so the guard was vacuously always true.
- Removed the stable `viewerRef` from the main effect's dep array; React
ref objects have stable identity for the component's lifetime so it was
noise. Added a comment noting the intentional omission.
For provenance purposes, this commit was AI assisted.
* docs(ui): note reset() in useExternalAnnotationHighlights header comment
For provenance purposes, this commit was AI assisted.1 parent b7af16a commit 91f57ad
3 files changed
Lines changed: 123 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
386 | 387 | | |
387 | 388 | | |
388 | 389 | | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
389 | 400 | | |
390 | 401 | | |
391 | 402 | | |
| |||
473 | 484 | | |
474 | 485 | | |
475 | 486 | | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
476 | 490 | | |
477 | 491 | | |
478 | 492 | | |
479 | | - | |
| 493 | + | |
480 | 494 | | |
481 | 495 | | |
482 | 496 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
0 commit comments