Closed collinsleewyatt closed 2 weeks ago
Thanks for the super detailed explanation here :) This should be fixed in 12.0.0-next.16.
Hey, I've tested my example on v12-next.16, and I'm not able to get nodesInitialized to run consistently on the demo. I've added an alert statement whenever nodesInitialized changes for debugging purposes. The nodes useEffect will run only once (not twice for population & measurement), and the nodesInitialized useEffect seems to only fire when I initialize / hot reload the page. However, on my school project, I'm able to get nodesInitialized to fire, and I'm not really sure why it's inconsistent here.
This is on v12-next.16: https://codesandbox.io/p/sandbox/reactflow-measurement-bug-v12-next-12-forked-yw88qs
Thanks for the response and maintaining this package.
It seems we need to re-open this :/ We will check it next week. Thanks for the codesandbox!
Thanks! Take care.
This is fixed in 12.0.0-next.17. Thanks again @collinsleewyatt !
Thanks :) I can confirm that behavior is consistent between 12.0.0-next.12 and 12.0.0-next.17. Appreciate the look into this.
Describe the Bug
When using React Flow v12.13, useNodesInitialized appears to fire before getNodes() is able to expose its
.measured
values. Additionally, auseEffect(() => {}, [nodes])
will no longer fire after the nodes get measured as of v12.13.Your Example Website or App
See codesandboxes below.
Steps to Reproduce the Bug or Issue
For v12-next.12 (expected behavior), go here: https://codesandbox.io/p/sandbox/reactflow-measurement-bug-v12-next-12-ms4gx9 For v12-next.13 (unexpected behavior), go here: https://codesandbox.io/p/sandbox/reactflow-measurement-bug-v12-next-13-thgclp
On both: Pressing the "Add node" button will change the nodes array. Pressing the "Remove nodes" button will remove all nodes.
Press "Add node" on both, and watch for the alerts.
nodesInitialized
is true ANDgetNodes().every((node) => node.measured !== undefined || node.computed !== undefined)
is also true, which I would expect (keep in mind v12.13 changed thecomputed
field tomeasured
).Expected behavior
On v12.12, the events fired will be (in order):
On v12.13, this is different:
As you can see, the third event, nodes change detection, no longer fires when React Flow measures the nodes, and nodesInitialized changed to true before its measurements were exposed, meaning we could not get the dimensions.
Screenshots or Videos
https://github.com/xyflow/xyflow/assets/54917619/6eed49cf-34fe-44da-8889-afdbd9611fe3
Platform
Additional context
No response