diff --git a/.changeset/gentle-walls-hammer.md b/.changeset/gentle-walls-hammer.md new file mode 100644 index 00000000..21f4f3be --- /dev/null +++ b/.changeset/gentle-walls-hammer.md @@ -0,0 +1,5 @@ +--- +'@xyflow/react': patch +--- + +Fix fitView not working when onNodesChange is not defined. diff --git a/packages/react/src/components/BatchProvider/index.tsx b/packages/react/src/components/BatchProvider/index.tsx index 382324da..f41b79a8 100644 --- a/packages/react/src/components/BatchProvider/index.tsx +++ b/packages/react/src/components/BatchProvider/index.tsx @@ -42,13 +42,16 @@ export function BatchProvider[]; + + // We only want to fire onNodesChange if there are changes to the nodes if (changes.length > 0) { - onNodesChange(changes); + onNodesChange?.(changes); } else if (fitViewQueued) { // If there are no changes to the nodes, we still need to call setNodes // to trigger a re-render and fitView. @@ -61,6 +64,7 @@ export function BatchProvider(nodeQueueHandler); const edgeQueueHandler = useCallback((queueItems: QueueItem[]) => {