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
72.02k stars 6.54k forks source link

Issue with Self-Referencing Transitions in stateDiagram-v2 Causing TypeError: Cannot read properties of undefined (reading 'node') #5822

Open abhishek-hopstack opened 2 months ago

abhishek-hopstack commented 2 months ago

Description

Description

When creating a self-referencing transition (e.g., stateA --> stateA) in a stateDiagram-v2, the diagram fails to render and throws a TypeError: Cannot read properties of undefined (reading 'node'). This issue seems to be specific to self-referencing transitions in version 2 of the state diagram.

Expected Behavior

The diagram should render correctly with a self-referencing transition, visually representing the state transition from stateA back to itself.

Actual Behavior

The diagram fails to render and throws the following error in the console:

Steps to reproduce

  1. Create a stateDiagram-v2 with the following content:

    stateDiagram-v2
        [*] --> Draft: Save as Draft
        Draft --> PendingInternalApproval: Submit
        Draft --> Draft: update on draft
  2. Render this diagram in a Mermaid-compatible environment (such as a browser, markdown editor, or code editor supporting Mermaid.js).

  3. Check the browser console for the error:

    TypeError: Cannot read properties of undefined (reading 'node')
  4. Notice that the diagram fails to render, and the self-referencing transition (Draft --> Draft) causes the error.

Screenshots

Screenshot 2024-09-06 at 12 58 44 PM

Code Sample

stateDiagram-v2
    [*] --> Draft: Save as Draft
    Draft --> PendingInternalApproval: Submit
    Draft --> Draft: update on draft

Setup

Suggested Solutions

No response

Additional Context

It was working about a week or 15 days ago

ashishjain0512 commented 2 months ago

@abhishek-hopstack We can reproduce this and are working on a fix for it in the upcoming release.

Seems to be duplicate issue: https://github.com/mermaid-js/mermaid/issues/5820