Defect #44664
closedMermaid diagram may be drawn into another diagram on the same page
Description
Problem¶
When a page contains multiple Mermaid diagrams, a diagram may be drawn into another diagram, and its own place is left empty. In the screenshot below, Diagram 3 is drawn into Diagram 2.

Cause¶
mermaid.run() generates the SVG id from Date.now(), so diagrams that start rendering in the same millisecond get the same id. Some Mermaid renderers look up their target element by id, so they draw into the wrong diagram. #44584 pointed out the same cause, but its fix only stopped error diagrams from being drawn, and the duplicate ids remain.
Solution¶
The attached patch renders each diagram with mermaid.render() and a unique id. With the patch, each diagram is drawn in its own place.

Files
Updated by Go MAEDA 23 days ago
- Related to Feature #44425: Render Mermaid code blocks as diagrams added
Updated by Go MAEDA 23 days ago
- Status changed from New to Closed
- Assignee set to Go MAEDA
- Resolution set to Fixed
Committed the patch as part of #44425 in r25321, with slight changes. Thank you.
Unlike mermaid.run(), mermaid.render() does not remove the indentation shared by all lines of the source. Without that step, a YAML front-matter block in an indented code block is not recognized and the diagram fails to render. The following is an example:
I added a step that removes the shared indentation before the source is passed to mermaid.render(), so that such diagrams render as before.