Node drag causes React-Flow's internal state to get out of sync
See original GitHub issueI encountered a problem where after node is dragged, its position becomes stale and cannot be updated via changing node.position property; the root cause of this seems to be related to the following code in the reducer:
In my testing, the condition is never true and therefore allows node.__rf.position to get out of sync with node.position; I believe the correct logic should be
if (storeNode.__rf.position.x !== propElement.position.x || storeNode.__rf.position.y !== propElement.position.y) { 
   updatedNode.__rf.position = propElement.position; 
 } 
Please note, this bug only surfaces after node position has been updated by node drag and subsequently updating the node’s position via node.position will cease to have an effect on the node’s position (ie node.__rf.position becomes out of sync with node.position).
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
Migrate to v10 Guide - React Flow
It was always a bit messy to sync the local user state with the internal state ... with the ability to drag nodes,...
Read more >Lifting State Up - React
Often, several components need to reflect the same changing data. We recommend lifting the shared state up to their closest common ancestor.
Read more >Designing a Dataflow Editor With TypeScript and React
So we set out to make a dataflow editor with three primary properties: ... Adjacent edges feel like part of the node state,...
Read more >copy the node while drag and drop using react-flow-renderer
You have to add the code that will update the position in the state. By default this position is only used when creating...
Read more >A react library for building node-based graphs - Morioh
Feel free to check out the examples or read the blog post to get started. ... other elements inside your custom node that...
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

Thank you @Danybs; the PR I submitted to fix this issue had been approved, hopefully, it will be released soon. Per my experiment and writeup above, after node drag
node.position !== reflect node.__rf.position; this is why the fix needs to be made to the reducer as any attempts to programmatically update a node’s position after node drag event will not physically move the node since rendering is based onnode.__rf.positionNOTnode.position.when drag elements to flow if move nodes, dont update position state i updated elements state position this way:
regards