mermaid icon indicating copy to clipboard operation
mermaid copied to clipboard

undefined is not an object (evaluating 'node2.id')

Open jjrscott opened this issue 2 years ago • 5 comments

Description

Attempting to render the graph listed in Steps to reproduce causes an exception. I'm new to the project but managed to track down the exception to:

const recursiveRender = (_elem, graph, diagramtype, parentCluster) => {
...
const node2 = graph.node(v); // ‼️ node2 is undefined where v == "D"
...
log$1.info("Node - the non recursive path", v, node2.id, node2); // 💥 due to node2.id

Steps to reproduce

This graph renders fine:

graph TD;
subgraph A
  subgraph B
    C
  end
end
A --> D
B --> D
C --> D
graph TD;
subgraph A
  subgraph B
    C
  end
end
A --> D
B --> D
C --> D

But comment out the last edge and the render fails:

graph TD;
subgraph A
  subgraph B
    C
  end
end
A --> D
B --> D
%% C --> D

Screenshots

No response

Code Sample

No response

Setup

Desktop

Mermaid: https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.5fa68f79.js

  • OS and Version: macOS Ventura 13.1 (22C65)
  • Browser and Version:
    • Safari 16.2 (18614.3.7.1.5)
    • Chrome 109.0.5414.119 (Official Build) (arm64)

Additional Context

No response

jjrscott avatar Feb 18 '23 21:02 jjrscott

Thanks for identifying the bug @jjrscott! Do you want to give a shot at a fix too? We can help with the PR in case you run into issues. Looks like you've already identified the location.

sidharthv96 avatar Feb 19 '23 04:02 sidharthv96

I'm up for giving it a go, although there's a big different between tracking down a crash and fixing it. If you're able to point me in the right direction I'd be grateful.

jjrscott avatar Feb 19 '23 13:02 jjrscott

I've further limited the issue to adjustClustersAndEdges:

image

jjrscott avatar Feb 19 '23 16:02 jjrscott

Hmm, so it fails if there are only links between subgraphs and nodes, instead of atleast one with another node.

sidharthv96 avatar Feb 19 '23 16:02 sidharthv96

I'm not sure, this graph also fails:

graph TD;
subgraph A
  subgraph B
    C
  end
  E
end
A --> D
B --> D
E --> D // ‼️Node to node

jjrscott avatar Feb 20 '23 09:02 jjrscott

Closing this in favor of #4644, please refer to the new issue. It is a error that comes across different issues.

nirname avatar Jul 16 '23 11:07 nirname