question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Usage of duplicate IDs across diagrams has potential to break some diagrams

See original GitHub issue

Describe the bug Class and State Diagrams all share <def> elements with the same id instead of making them unique. If given two diagrams that share <def> elements with the same id, and the first gets hidden, it can affect all other diagrams that share the same <def> ids.

In this example, notice that when the Class Diagram is hidden, the State Diagram underneath loses its arrows.

wDLLe3E7Zu

This is because both the State Diagram and the Class Diagram define <def> elements that use the exact same id. Below is an example of the <dev> id that is generated in these SVGs. It is not unique like other diagrams generate. It would be expected to have dependencyEnd<some_number>, but instead all Class and State Diagrams use the exact same id.

<marker id="dependencyEnd" refX="19" refY="7" markerWidth="20" markerHeight="28" orient="auto"><path d="M 19,7 L9,13 L14,7 L9,1 Z"></path></marker>

This only works as long as the first doesn’t get hidden (the only ID that the browser cares about, as IDs are required to be unique).

I imagine stylesheets would also have to get cleaned up as they are currently using things like:

#dependencyStart {
  @include composition;
}

#dependencyEnd {
  @include composition;
}

You could maybe get away with something like:

[id^="dependencyEnd] {
  @include composition;
}

On a side note, using IDs in general like this could mistakenly break things in a site if a user happens to use the same ID in their document. At the very least, it may make sense to kind of namespace the ids to reduce the chance of a user accidentally using the same ID __mermaid_dependencyEnd<number>. Something to think about.

Expected behavior

All <dev> elements should be generated with unique ids.

Screenshots

See above

Desktop (please complete the following information):

Not OS or Browser specific

  • Mermaid Version: 8.4.8

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
chumido98commented, Sep 14, 2021

So I spent some time on this today, and found that if create my own loader that wraps each diagram in a shadow DOM, I no longer get non-unique ID problems as the individual diagrams no longer are shared.

encapsulate

I don’t know if this is a direction that Mermaid would like to go in, but it may be something to think about if anyone has general issues with ID conflicts. I find this solves most of my issues.

Can you guide me how to fix the arrow issue? I’m using mermaid in Obsidian, and when i export note to PDF, the arrow of diagram disappear. Like this: image

Sorry my English is not good.

2reactions
lishidcommented, Jun 6, 2021

@knsv Just curious if there was any progress on this - I’m doing a routine bug sweep and it seems that this bug is still a common encounter among users.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IDs used in ARIA and labels must be unique | Axe Rules
Duplicate IDs are common validation errors that may break the accessibility of labels, e.g., ARIA elements, form fields, table header cells. Unique ID's...
Read more >
Relational Database Normalization Process
It means decomposing (dividing/breaking down) a 'big' un-normalise table (file) into several smaller tables by: Eliminating insertion, update and delete ...
Read more >
Codes, Tags and Labels—Interpreting Piping and ... - AIChE
P&IDs may be viewed as a database of equipment, devices, lines and various sundry items that make up a process plant.
Read more >
Results-Reports Visualizations - Qualtrics
Attention: Not every question type is compatible with every visualization. For example, it doesn't make sense to have a Bar Chart option for...
Read more >
Working With Large Internal Link Graphs in Python - Briggsby
Hard-to-understand metrics and analysis: Statistics and calculations on large datasets can have increased complexity. The outputs may also be ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found