Repository navigation
perf: keep the Mermaid SVG markup object stable - #693
Merged
Merged
Conversation
react-dom 19.2 assigns innerHTML whenever the dangerouslySetInnerHTML
object changes identity, without comparing the markup. Mermaid passed a
new { __html } object on every render, so each re-render of a finished
diagram reparsed its whole SVG and the SVG's <style> forced a document
style recalculation. Memoize the object on the SVG string.
Contributor
|
@bendrucker is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
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.
Mermaidpassed a new{ __html }object on every render.react-dom19.2 rewritesinnerHTMLwhenever that object changes identity, so each re-render reparsed the diagram's SVG and its<style>forced a document-wide style recalculation.Diagrams re-render on every context change, which happens per token when options are passed inline, and once when a stream ends. Memoizing the object on the SVG string keeps the existing DOM.
On a Vite app with React 19.2.8, one stream of a mixed document on 2.7.0 cost:
ParseHTMLUpdateLayoutTreeNext.js 16.3's bundled React compares the markup first, so Next apps never paid this.