xyflow: v11 --> v12 breaks edge position and placement when loading images
What platform were you using when you found the bug?
System:
OS: Linux 6.6 Manjaro Linux
Binaries:
Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
npm: 10.8.2 - ~/.nvm/versions/node/v18.19.0/bin/npm
pnpm: 9.6.0 - ~/.nvm/versions/node/v18.19.0/bin/pnpm
Browsers:
Chromium: 127.0.6533.88
npmPackages:
@xyflow/react: ^12.0.4 => 12.0.4
next: ^14.2.3 => 14.2.3
react: ^18.3.1 => 18.3.1
typescript: 5.5.4 => 5.5.4
Live code example
No response
Describe the Bug
I just updated my repo to the latest version of RF and I noticed that the behavior of the edge placement and updating has changed. Specifically when loading dynamic content such as videos and images, the edges used to update automatically. This also applied when dealing with dynamic CSS modifications (e.g changing the height of something in the node).
I deal with unknown content, so there’s no way to prevent layout shifts. Also the scope and the number of images, make it unfeasible to constantly track image loading state and then call useUpdateNodeInternals.
V11
Position is correct, after content is loaded edges are updated.
V12
Position is incorrect, after content is loaded edges remain where they were mounted initially.
I’m wondering what has changed specifically that has caused this issue? Is this is design choice on your behalf and expected behavior?
Steps to reproduce the bug or issue
This can be tried using the custom node example with a large image
Expected behavior
I expect the edges to automatically shift to correct position.
Screenshots or Videos
No response
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 39 (15 by maintainers)
We will investigate.
@alexanderhorner I actually have no idea! I just noticed it as I was testing the performance of my
onNodeChangesmethod. But if I were to guess, I’d say by usingcurrentyou’re essentially bypassing all the proxy logic. Withoutcurrentcthe function below was hitting 0.8ms while usingcurrentbrought it down to 0.3ms.To be clear, the performance gain can also be specific to my implementation. My nodes and edges are stored as key/value objects instead of the default array[] format that is recommended by RF. So I have to do some logic here and there for updates/sets, but the key/val setup makes it much easier to access and modify individual nodes outside of react components where I don’t have access to hooks and without incurring a O(n) search penalty.
this is my actual function
@alexanderhorner for your immer issues, I think you can use
currentor theoriginalmethods from immer. Performance is much faster thanstructuredCloneand actually even 2x faster thanconst { nodes } = stateadditionally I highly recommend disabling autofreeze viasetAutoFreeze(false)@moklick I still encounter strange issues with
initialWidth/Height. This happens specifically when I throttle my connection using chrome’s dev tools to Slow 3G, and the edges fail to be positioned properly. On speedy connections everything works as expected.Also opening this up again for @alexanderhorner.
measuredis not something that is set by the user but whenever the resize observer detects a change and on first render.I think I found the issue while creating the reproduction repo. The violating node attributes are
widthandheight. If these are present dynamic positioning breaks. Rereading the docs I can see thatUsing width and height now means that the dimensions are not dynamic based on the content but fixed.smh