Why the InitialLayoutCompleted event is fired twice?


This is an example to reproduce the issue here.

Why this event is fired twice (same for LayoutCompleted) ?

My guess:
Because you are using gojs-react (or gojs-angular) the initDiagram function is setting up an empty model for the diagram, causing the first “InitialLayoutCompleted” DiagramEvent. Then your app supplies its data, and so then the second “InitialLayoutCompleted” happens.

I suppose you could check whether then model is empty or not.

I didn’t see this happens before moving to gojs-react.
I expect to get InitialLayaoutCompleted only once.
Now I’m using a counter to trigger my logic after the second call and I don’t feel this is the right way.
Is there anyway to get InitialLayaoutCompleted only once with ReactDiagram ?

The “InitialLayoutCompleted” DiagramEvent is supposed to happen each time the diagram gets a new model. And I think it does. But you can ignore the first one when the model is empty.