-
Hello, I'm currently using collaborative mode and have encountered an issue. When two users are connected to the flow chart and each selects a different node (for example, user 1 selects a circle node and user 2 selects a rectangle node), if user 1 moves their selected node, the node selected by user 2 also moves involuntarily. Is this normal behavior, and is there a way to resolve this issue? Ideally, I'd like users to be able to move their nodes independently. Any insights or suggestions would be greatly appreciated. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I think this happens, because users click on nodes, selected prop becomes "true", and that's why all nodes move by one user. |
Beta Was this translation helpful? Give feedback.
-
Hey @Kost927, we did some digging and found a possible solution for your issue: To prevent changes from being synced between local and remote state, you can change the observer code to distinguish between local and remote updates: useNodesStateSynced.ts:73 // here we are observing the nodesMap and updating the nodes state whenever the map changes.
useEffect(() => {
const observer = (_: unknown, transaction: Transaction) => {
// The idea here is that when the update originates from a local mutation to
// the `nodesMap`, we want to update the nodes state directly...
if (transaction.local) {
setNodes(Array.from(nodesMap.values()));
}
// ... but when the change is coming from remote, we want to *only* sync
// the properties defined in `syncedProperties` and keep the rest of the
// state local.
else {
const nextNodes = Array.from(nodesMap.values());
setNodes(
nextNodes.map((node) => {
// this is for demo purposes, you probably want to implement your own syncing logic here
node.selected = false;
return node;
})
);
}
};
nodesMap.observe(observer);
return () => nodesMap.unobserve(observer);
}, [setNodes]); Thanks for raising this issue, we'll update the pro example to reflect these changes. |
Beta Was this translation helpful? Give feedback.
-
Same problem and I've ended up founding my own solution: |
Beta Was this translation helpful? Give feedback.
Hey @Kost927,
we did some digging and found a possible solution for your issue: To prevent changes from being synced between local and remote state, you can change the observer code to distinguish between local and remote updates:
useNodesStateSynced.ts:73