Project

General

Profile

Actions

Defect #44664

closed

Mermaid diagram may be drawn into another diagram on the same page

Defect #44664: Mermaid diagram may be drawn into another diagram on the same page

Added by Takenori TAKAKI 25 days ago. Updated 23 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
UI
Target version:
-
Resolution:
Fixed
Affected version:

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

mermaid-diagrams-before.png (77.6 KB) mermaid-diagrams-before.png Takenori TAKAKI, 2026-10-23 03:38
mermaid-diagrams-after.png (104 KB) mermaid-diagrams-after.png Takenori TAKAKI, 2026-10-23 03:39
fix-mermaid-duplicate-svg-ids_r25293.patch (2.95 KB) fix-mermaid-duplicate-svg-ids_r25293.patch Takenori TAKAKI, 2026-10-23 03:41

Related issues 1 (0 open — 1 closed)

Related to Redmine - Feature #44425: Render Mermaid code blocks as diagramsClosedGo MAEDAActions

Updated by Go MAEDA 23 days ago Actions #1

  • Related to Feature #44425: Render Mermaid code blocks as diagrams added

Updated by Go MAEDA 23 days ago Actions #2

  • 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:

```mermaid
  ---
  title: Foo
  ---
  graph TD;
  A-->B;
```

I added a step that removes the shared indentation before the source is passed to mermaid.render(), so that such diagrams render as before.

Actions

Also available in: PDF Atom