Repository navigation
Replies: 2 comments
|
xyflow-zustand-repro-github.zip |
|
Immer is a contributor here but I'd bet the bigger cost is zundo has a documented pattern for exactly this, pause history tracking for the duration of the drag, then resume and commit a single entry at the end: const { pause, resume } = useEditorStore.temporal.getState()
const onNodeDragStart = useCallback(() => {
pause()
}, [])
const onNodeDragStop = useCallback(() => {
resume()
// one more set() here so this final position gets recorded
useEditorStore.setState((s) => ({ nodes: s.nodes }))
}, [])<ReactFlow
onNodesChange={onNodesChange}
onNodeDragStart={onNodeDragStart}
onNodeDragStop={onNodeDragStop}
/>While paused, zundo's wrapped temporal(config, {
handleSet: (handleSet) => throttle(handleSet, 200),
})I'd still keep the pause/resume version for drags specifically though, throttling means you're still running the deep equality every 200ms during the drag rather than not at all, and you'd lose fine-grained history entries you might actually want elsewhere in the app. |
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone! I'm testing strange behaviour in my code with react version of xyflow.
I test dragging perfomance on 100 simple nodes withoud connected edges (arrows). When I use
everything is smooth both with devtools opened and closed.
When I use function from my custom Zustand store with this function
dragging becomes laggy (with drops to 2fps and freezes).
My store consists of slices and uses some middlewares like zundo and immer:
I tried comment them and use store without them - nothing changed.
I've attached editorSlice as it is too big to show here), but here is the onNodesChange function.
Why it could possibly so dramatically drop in perfomance?
All reactions