fix(renderer): animate mermaid block height when the diagram renders - #2142
Draft
roxi3906 wants to merge 2 commits into
Draft
fix(renderer): animate mermaid block height when the diagram renders#2142roxi3906 wants to merge 2 commits into
roxi3906 wants to merge 2 commits into
Conversation
Streamdown reserves a 200px placeholder for mermaid fences and swaps in the real SVG once the block scrolls near the viewport. The placeholder and rendered heights almost never match, so the transcript jumps. Add an install-time DOM enhancement that observes each mermaid block with a ResizeObserver and transitions the block's height (180ms) from the placeholder height to the rendered height instead of snapping. The first measurement never animates, sub-2px changes are ignored, prefers-reduced-motion skips the animation, and a height change that lands mid-transition chains into a follow-up animation rather than snapping at the end.
…jump # Conflicts: # src/renderer/src/components/streamdown/install-streamdown.ts
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.
Problem
Streamdown reserves a fixed ~200px placeholder for each mermaid fence and only renders the diagram once the block scrolls near the viewport (IntersectionObserver + idle callback). The rendered SVG's height almost never matches the placeholder, so the moment the diagram appears, the surrounding transcript jumps abruptly.
Change
Adds an install-time DOM enhancement (
installMermaidHeightAnimation, wired intoinstallStreamdown) that smooths the swap:[data-streamdown="mermaid-block"]elements inside.agent-markdown-root(covers both static and streaming render modes, since both go through the same DOM).height: auto.prefers-reduced-motion: reduceskips the animation entirely.No upstream patch and no changes to streamdown's rendering or to the mermaid block chrome (actions/fullscreen/download all untouched).
Testing
mermaid-height-animation.test.ts(9 tests): placeholder→render animation, initial-measurement skip, delta threshold, mid-transition chaining, observer frame filtering, reduced motion, blocks outside the markdown root, add/remove tracking, uninstall cleanup.vitest run: 23,695 passed; the only 4 failures (network-enforcement.integration,literature-review kernel,kernel-executorWindows cancellation) reproduce identically on a cleanmaincheckout — pre-existing environment issues (Python version, sandbox network policy), unrelated to this change.npm run typecheckand ESLint clean.