Add MutationObserver to viz.init.js for live-edit Graphviz re-rendering#357
Merged
Merged
Conversation
Related to #332 window.load doesn't fire when MPDocument.m replaces body.innerHTML during live editing, so Graphviz diagrams never rendered after the initial page load. This is the same class of bug fixed for Mermaid in #331 / PR #333. Changes: - viz.init.js: add rendering guard flag and MutationObserver that watches for .language-{engine} elements across all 6 Graphviz engines (circo, dot, fdp, neato, osage, twopi); calls init() when any are found. Loop prevention is natural: doGraphviz() replaces the code element with SVG, so the trigger element disappears before the observer can fire again. - MPGraphvizRenderingTests.m: new test file mirroring MPMermaidRenderingTests.m; covers code block rendering, script inclusion/exclusion, preference change detection, multiple diagrams, mixed content, edge cases, and graphviz+mermaid coexistence. - project.pbxproj: register MPGraphvizRenderingTests.m in MacDownTests target.
Contributor
Code Coverage ReportCurrent Coverage: 57.74% Coverage Details (Summary) |
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.
Summary
viz.init.js: adds arenderingguard flag and aMutationObserverthat watches for.language-{engine}elements across all 6 Graphviz engines; callsinit()when any are found afterbody.innerHTMLreplacement. Loop prevention is structural —doGraphviz()replaces the triggering<code>element with SVG before the observer can fire again.MPGraphvizRenderingTests.m: new test file mirroringMPMermaidRenderingTests.m; 15 tests covering code block rendering, script inclusion/exclusion, preference change detection, style changes, multiple diagrams, mixed content, edge cases, and graphviz+mermaid coexistence.project.pbxproj: registers new test file in theMacDownTeststarget.This is the same class of bug fixed for Mermaid in #331 / PR #333.
Test plan
dotfence, edit it — diagram re-renders without full reloadRelated to #332