Fix stacked Mermaid error graphics while typing - #165
Open
mohit-nayak wants to merge 1 commit into
Open
mohit-nayak wants to merge 1 commit into
mohit-nayak wants to merge 1 commit into
Conversation
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.
Fixes #156
While you type a Mermaid diagram, mermaid's built-in "Syntax error in text"
graphic gets added to the page on every keystroke and never cleaned up. They pile
up until they cover the screen and push the editor out of view, and the only way
out is a refresh.
The cause: we call mermaid.render() without a container element, so mermaid
creates a temp div in document.body and removes it at the end of the render. When
parsing fails it draws its error graphic into that div and rethrows before the
cleanup runs, so the div is left behind. The preview re-renders on a 150ms
debounce and half-typed syntax fails to parse on most keystrokes, so they add up
fast. Since these leftovers are direct children of body, which is a flex column,
each one steals vertical space from the editor instead of just sitting below it.
The fix is suppressErrorRendering: true in configureMermaid(). With that flag
mermaid cleans up its temp element and skips drawing its own graphic. Our inline
error message still shows, and it now includes mermaid's real parse error with
the line number instead of the generic "Syntax error in text".
A few supporting changes:
on every keystroke. A diagram that never rendered still shows its error at once.
every diagram was being re-rendered on every character.
mermaid internals staying as they are.
The CSS adds styles for the stale diagram and error note, and keeps mermaid's
temp containers out of the body flex column. I left the flex sizing itself alone,
since .split-container relies on the default flex-shrink for its normal layout
and Monaco sizes against its height: 100%.
dist/ isn't rebuilt here. It's committed to the repo but looks like something you
build yourself. Happy to add it if you'd prefer.