Skip to content

Fix the diagram block breaking when a node with a saved comment is clicked (Inbox file pane) - #4151

Merged
backnotprop merged 2 commits into
mainfrom
fix/diagram-node-comment-reopen
Nov 27, 2026
Merged

backnotprop merged 2 commits into
mainfrom
fix/diagram-node-comment-reopen

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

What broke

Clicking a diagram node that already had a saved comment broke the whole diagram block in the Inbox's file pane. This pane is used by the plan page and by Markdown files opened from a thread or from Spaces. The block turned into its source text under "Couldn't load this view. Reload", and the console logged React error #185 ("Maximum update depth exceeded") and "[plannotator] A part of the page could not load". QA reproduced this 4 of 4 times on the plan page, and the same steps fail on 0.29.5, so it is not new.

Before the click, the same page was already re-rendering without end. This started as soon as any diagram on the page had a saved comment. No error showed, but CPU was used the whole time.

Cause

DiagramBlock's restore-report effect had the host's onRestoreReport in its dependency list and called it. The Inbox file pane passes (report) => setUnanchored(new Set(report.unanchored)) (packages/inbox/components/AttachmentPane.tsx). That is a new function on every render, and it always stores a new Set. The result is a loop:

  1. The effect sends the report.
  2. The pane's state changes and the pane re-renders.
  3. The block gets a new callback and its memo misses.
  4. The effect sends the report again, and so on.

The loop runs only when the block has comments to report. A click on the commented part mounts the composer. The composer's layout effect, which measures its own height, turns the churn into nested synchronous updates. React then throws #185 and LazyBlockBoundary shows the fallback.

Two Viewer effects had the same dependency and churned the same way in that host, without the crash:

  • the image-region restore report (a comment on part of an image);
  • the "no diagram in this document" report (a diagram comment whose fence is gone).

The text highlighter (useAnnotationHighlighter) and HtmlViewer already read these host callbacks through a ref.

Fix

All three effects now read onRestoreReport through a ref. They depend on whether a callback exists, not on its identity, so they re-run only when what they report on changes. The fix is in the shared UI, so any host is safe, whatever callback it passes. Nothing on screen changes.

Every site in packages/ui that calls a host onRestoreReport from an effect: DiagramBlock.tsx (restore report), Viewer.tsx (image-region report), Viewer.tsx (no-diagram report). All three are fixed here, and that list is complete. Two other sites already read the callback through a ref and are unchanged: the highlighter (useAnnotationHighlighter.ts) and HtmlEmbedBlock.tsx (hostRef.current). MermaidBlock and GraphvizBlock only compare the callback in their memo.

Added after review: the pane's "Unanchored" set now merges reports

The loop had been hiding a second bug in the Inbox file pane. Several reporters send restore reports separately: the text highlighter, each diagram block, and the image-region check. Each reports only the comments it tried. The pane, however, replaced its whole unanchored set with every report, so the last reporter won. For example, diagram A cannot place a comment; then the highlighter, or diagram B, reports with nothing missing, and A's "Unanchored" chip disappears. Before this PR, the loop made diagram blocks win over and over; after the ref fix it would come down to timing.

The pane now merges each report the way plan review already does (packages/editor/App.tsx, handleRestoreReport): the ids a report tried leave the set, and the ones it could not place join it. A report that changes nothing returns the same set, so the pane does not re-render. The merge is a small pure function in the new packages/inbox/unanchoredSet.ts (mergeUnanchoredReport). The new useUnanchoredSet hook gives the pane the set, its setter, and one stable report callback, now a useCallback.

The set still resets on a file or version change exactly as before, and the code view and the HTML viewer still set the whole set as before. AttachmentPane.tsx stays at its 3140-line ceiling: the two ./Markup imports became one line to make room for the new import. Nothing on screen changes.

Which surfaces were affected

  • Inbox file pane (plan page, Markdown files from a thread or Spaces): affected. Its callback is the inline one above.
  • Plan review and annotate: not affected. packages/editor/App.tsx passes a stable useCallback. Checked by hand, see below.
  • Inbox thread message bodies: not affected by this loop. useBodyComments.ts passes a stable useCallback.

Test

packages/ui/components/DiagramBlock.restoreReportLoop.test.tsx (DOM-gated, added to tests/dom-test-list.txt) drives the real Viewer under a host shaped like the Inbox pane: an inline onRestoreReport that stores a new Set. It runs outside act() with bounded waits, because act() never settles during the loop: the test fails rather than hangs.

  • A stored comment on flowchart node D:
    • the report still says the comment was found;
    • the page stops rendering when idle;
    • a click on D opens the composer;
    • afterwards the diagram, the node and the comment's badge are still drawn, with no "Couldn't load this view" and no "Maximum update depth" logged.
  • A stored image-region comment: it is reported as found, and the page stops rendering.
  • A diagram comment in a document with no diagram: it is reported unanchored, and the page stops rendering.

On main (54145c0), all 3 fail: 791, 4352 and 5062 host renders in 300 ms while idle. With this change, all 3 pass. A scratch run of the same host on main, clicking the node, logged exactly QA's console: "Maximum update depth exceeded … The above error occurred in the component … LazyBlockBoundary".

packages/ui/components/DiagramBlock.restoreReportFresh.test.tsx (DOM-gated, from the independent review, registered in tests/dom-test-list.txt) checks the other side of the ref: a real change still produces a report, and it reaches the host's newest callback. It has 4 tests, all passing:

  • a late comment arriving together with a new callback is reported to the new one;
  • a callback that goes from undefined to defined gets the report;
  • a new diagram comment in a document with no diagram is reported again;
  • an image removed from the document makes its region comment report as unanchored again.

packages/inbox/unanchoredSet.test.ts (unit, 3 tests, all passing):

  • reporter A leaves a comment unanchored, then reporter B reports clean, and A's id stays;
  • an id its reporter places again leaves the set, and an id it loses joins it;
  • a report that changes nothing returns the same set.

The first case fails under the old replace-the-set behaviour.

Also run, all passing: tests/inbox-structure.test.ts (5, which covers the size ceilings), DiagramBlock.anchor.test.tsx (7), Viewer.diagramLazyRestore.test.tsx (3), scripts/dom-test-allowlist.test.ts (1). tsc --noEmit is clean for packages/ui/tsconfig.json and packages/inbox/tsconfig.json.

Checked by hand

I checked annotate, before and after the fix. Each run was a compiled binary in a sandbox (scratch HOME and data dir, loopback only, every other host aborted), and Playwright only drove it, on a Markdown file with a mermaid flowchart. The steps: click node Start, write a comment, press Comment, reload, press Restore on the draft, click Start again.

  • Before (QA's 0.29.6 build): the composer opens ("On Start (node A) · line 7") and the restored badges stay. This confirms annotate was never affected.
  • After (this branch): the same steps give the same result. The badge comes back after the reload, and the composer opens on the commented node with the diagram intact. No regression.

Not checked

  • I did not drive the Inbox file pane by hand, before or after. Driving it needs a sandboxed Inbox, the Inbox app build and a seeded thread with a Markdown attachment. That is well over 20 minutes, and our build rules say not to start an Inbox locally. The DOM test drives the same Viewer under the same callback shape, and the ci:e2e run covers the Inbox diagram specs.
  • I did not run the full DOM, unit or e2e suites locally; CI runs them.

… and Viewer

A diagram block re-sent its restore report whenever the host's
onRestoreReport changed identity. The Inbox's file pane passes a new
function each render that stores the report as a new Set, so each report
re-rendered the pane, which handed the block a new callback, which sent the
report again: thousands of renders a second while the page sat still, as
soon as a diagram on it had a saved comment. A click on the commented part
mounted the composer, whose layout effect turned the churn into nested
synchronous updates; React threw "Maximum update depth exceeded" (#185) and
the block fell back to its source under "Couldn't load this view".

The Viewer's image-region report and its no-diagram report had the same
dependency and churned the same way in that host. All three now read the
callback through a ref, as the highlighter and HtmlViewer already do, and
re-run only when what they report on changes.
@backnotprop backnotprop added the ci:e2e Run the full browser suite (Inbox window e2e) on this PR label Nov 27, 2026
… reports

The Inbox file pane replaced its whole unanchored set with each restore
report, but the text highlighter, each diagram block and the image-region
check each report only the comments they tried, so the last reporter won and
a diagram comment that could not be placed lost its chip. Merge per report
as plan review does (the ids tried leave, the ones not placed join), through
one stable callback; a report that changes nothing keeps the same set.

Also add tests that a real change still reports to the host's newest
callback now that the Viewer and the diagram blocks read it through a ref.
@backnotprop
backnotprop marked this pull request as ready for review November 27, 2026 20:49
@backnotprop
backnotprop merged commit 74cb08e into main Nov 27, 2026
54 checks passed
backnotprop added a commit to bendrucker/plannotator that referenced this pull request Nov 28, 2026
…panel swipes and the HTML viewer's lost highlights

ui 0.67.0 and core 0.25.35 went to npm on 2026-11-28 with package files
that match the v0.29.6 tag (c21f65e), so this pair carries what merged
after v0.29.6, up to v0.29.7.

core 0.25.36 is additive: the linked mark "decisions" and
InboxDecision.machine (backnotprop#4066), DraftFileUploader.previewUrl (backnotprop#4165), and
holdingsOf no longer counting a question Mark read closed (backnotprop#4160). No
exports subpath changes; nothing removed.

ui 0.68.0 is a minor: Escape while an input method composes only ends the
composition, and shortcuts skip such keys; holdsImeEscape is new (backnotprop#3689,
backnotprop#4162). HtmlViewer treats a collapsed live Range as lost (backnotprop#4152). Compact
panels: OverlayScrollArea scrollMemory, SidebarContainer closing and
scrollPositions, ActionMenu compactEdgeSwipe, four new hooks and the panel
rules in theme.css (backnotprop#2861). useLaunchAnnouncement waits for ready (backnotprop#4067).
ui uses nothing new from core; its exact pin follows so a host gets one
core. Publish core first.

README and HANDOFF name the new pair, and HANDOFF adds what the published
0.25.35 / 0.67.0 already held beyond their notes (backnotprop#4114, backnotprop#4151).

bun.lock is bun install's own output: the two package version lines, and
six app workspace version lines (0.29.5 to 0.29.7) the release bumps left
behind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:e2e Run the full browser suite (Inbox window e2e) on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant