Repository navigation
fix(editor): restore Mermaid reading position after rendering - #35031
Conversation
d24a08a to
7070888
Compare
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 10 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
[Low impact] The PR appears safe to merge; the remaining feedback is a non-blocking request for a cancellation test. Findings
SummaryRestores Mermaid reading positions after slow renders and after hidden workspaces become visible.
|
| visible = true | ||
| act(() => resizes.forEach((callback) => callback())) | ||
|
|
||
| expect(viewer.scrollTop).toBe(600) |
There was a problem hiding this comment.
User cancellation lacks a test
Both tests cover successful restoration, but neither checks that user input cancels it. Add a test that starts with a pending restore, dispatches a user scroll event, then completes rendering and fires the resize callback. Assert that neither callback restores the cached position. Otherwise, a change that breaks cancellation could pass both tests and let a late render override the reader's choice.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
7070888 to
d0682d3
Compare
Problem
MermaidViewerrestores the cached diagram scroll position by retrying for up to 30 animation frames (about 500 ms), then gives up. Mermaid renders run through one serialized global queue that is shared with Markdown preview and chat diagrams, and the first render also waits for the lazymermaidimport. A large or queued diagram can finish after that window, so the viewer reopens at the top. When the workspace is hidden (zero-height viewport) the retries always fail, so the position is also lost on return.Fix
MermaidBlocktakes an optionalonRenderCompletecallback, fired from a layout effect once the current source has rendered (success or error).MermaidViewerkeeps the cached target pending and applies it once, clamped, when the viewport is measurable and either the render is complete or the content is already tall enough. A temporaryResizeObservercovers a render that finished while the viewport was hidden.MermaidBlock, so whitespace-only edits cannot leave a restore pending without a render to complete it.The renderer-local, in-memory cache key is unchanged. Other
MermaidBlockcallers don't pass the new prop, so they are unaffected.Tests
MermaidViewer.test.tsxhas two regression tests. Both fail onmainand assert only the viewer'sscrollTop:pnpm check:changed --maxWorkers=2passes.