fix: prevent unnecessary diagram re-rendering when editor changes are outside block#199
Merged
ThisIs-Developer merged 2 commits intoJun 30, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Deploying markdown-viewer with
|
| Latest commit: |
f7ecb6f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://769f7aeb.markdown-viewer.pages.dev |
| Branch Preview URL: | https://fix-prevent-unnecessary-diag.markdown-viewer.pages.dev |
Deploying markdownviewer with
|
| Latest commit: |
f7ecb6f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://07ccfe1b.markdownviewer.pages.dev |
| Branch Preview URL: | https://fix-prevent-unnecessary-diag.markdownviewer.pages.dev |
9bc89ea to
f7ecb6f
Compare
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
Several diagram renderers (Markmap, PlantUML, Graphviz, D2, Vega-Lite, WaveDrom, ABC Notation) were re-rendering whenever any change was made anywhere in the Markdown editor, even if the change was outside the diagram’s fenced code block. This caused visual flickering, state loss (e.g., zoom/pan on Markmap), and unnecessary remote API calls.
This occurred because the DOM patching layer (
canReusePreviewNode) checked if theouterHTMLmatched. However, diagram shells generate a new random ID every time (e.g., viaMath.random()), making theouterHTMLcheck consistently fail.Solution
We updated
canReusePreviewNodeinscript.jsto look for diagram elements (containing adata-original-codeattribute) and reuse them if the source code and diagram engine class name are identical. This preserves the fully-rendered DOM nodes of the diagrams and prevents them from re-rendering on unrelated edits.