mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
71.2k stars 6.42k forks source link

when using multiple diagrams on the same page, interactions via bindFunctions only end up working on one instance #4346

Open vesper8 opened 1 year ago

vesper8 commented 1 year ago

Description

I am using the very latest version mermaid@10.1.0

I have two separate flowcharts on the same page, both of them make use of interactions (click functions as well as tooltips)

I've noticed that there is essentially a race condition and only one of the two diagrams end up being able to use interactions

Steps to reproduce

Have two different diagrams with distinct elements and interactions Call initialize and render for each diagram Notice that interactions only work on one instance, but never both

Screenshots

No response

Code Sample

In one component

        mermaid.initialize({
          startOnLoad: false,
          securityLevel: 'loose',
        });

        const element = document.getElementById('mermaid-project-tree');

        if (element) {
          await mermaid
            .render('mermaid-project-tree-svg', this.diagram) //
            .then(({ svg, bindFunctions }) => {
              element.innerHTML = svg;
              bindFunctions(element);
            });
        }

In another component

        mermaid.initialize({
          startOnLoad: false,
          securityLevel: 'loose',
        });

        const element = document.getElementById('mermaid-requirements-tree');

        if (element) {
          await mermaid
            .render('mermaid-requirements-tree-svg', this.diagram) //
            .then(({ svg, bindFunctions }) => {
              element.innerHTML = svg;
              bindFunctions(element);
            });
        }


### Setup

- Mermaid version:  mermaid@10.1.0
- Browser and Version: [Chrome, Edge, Firefox] Chrome 112

### Additional Context

Maybe I am going about this wrong and this is not the proper way to have more than one diagram that uses interactions on the same page. If so, some advice or an example would be much appreciated!

Many thanks
dword-design commented 1 year ago

Same issue here. This blocks me from upgrading mermaid in vue-mermaid-string.

dword-design commented 11 months ago

Any updates here? Still a blocker for vue-mermaid-string, which is sticking to mermaid@^8 😢.

jgreywolf commented 10 months ago

Adding to roadmap discussion and will update here within a week or so

stefnotch commented 8 months ago

@jgreywolf I humbly apologise for the ping. Is there an update regarding this?

BossHogg97 commented 6 months ago

@jgreywolf Sorry for the ping. Is there any update about this problem? Thanks

BenjaminHofstetter commented 5 months ago

i have the same issue.