Repository navigation
Fix the diagram block breaking when a node with a saved comment is clicked (Inbox file pane) - #4151
Merged
Merged
Conversation
… 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.
… 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
marked this pull request as ready for review
November 27, 2026 20:49
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.
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.
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'sonRestoreReportin 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: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
LazyBlockBoundaryshows the fallback.Two Viewer effects had the same dependency and churned the same way in that host, without the crash:
The text highlighter (
useAnnotationHighlighter) andHtmlVieweralready read these host callbacks through a ref.Fix
All three effects now read
onRestoreReportthrough 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/uithat calls a hostonRestoreReportfrom 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) andHtmlEmbedBlock.tsx(hostRef.current).MermaidBlockandGraphvizBlockonly 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 newpackages/inbox/unanchoredSet.ts(mergeUnanchoredReport). The newuseUnanchoredSethook gives the pane the set, its setter, and one stable report callback, now auseCallback.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.tsxstays at its 3140-line ceiling: the two./Markupimports became one line to make room for the new import. Nothing on screen changes.Which surfaces were affected
packages/editor/App.tsxpasses a stableuseCallback. Checked by hand, see below.useBodyComments.tspasses a stableuseCallback.Test
packages/ui/components/DiagramBlock.restoreReportLoop.test.tsx(DOM-gated, added totests/dom-test-list.txt) drives the realViewerunder a host shaped like the Inbox pane: an inlineonRestoreReportthat stores a new Set. It runs outsideact()with bounded waits, becauseact()never settles during the loop: the test fails rather than hangs.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 intests/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:packages/inbox/unanchoredSet.test.ts(unit, 3 tests, all passing):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 --noEmitis clean forpackages/ui/tsconfig.jsonandpackages/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.
Not checked
Viewerunder the same callback shape, and theci:e2erun covers the Inbox diagram specs.