From c98b6c01f918a8ad63dee790e172a40951a56dd6 Mon Sep 17 00:00:00 2001 From: peterkogo Date: Wed, 5 Mar 2025 15:16:12 +0100 Subject: [PATCH] Add comments --- packages/react/src/hooks/useReactFlow.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/react/src/hooks/useReactFlow.ts b/packages/react/src/hooks/useReactFlow.ts index b67ef0d3..a02cbb55 100644 --- a/packages/react/src/hooks/useReactFlow.ts +++ b/packages/react/src/hooks/useReactFlow.ts @@ -280,9 +280,14 @@ export function useReactFlow | undefined) => { + // We either create a new Promise or reuse the existing one + // Even if fitView is called multiple times in a row, we only end up with a single Promise const fitViewResolver = store.getState().fitViewResolver ?? Promise.withResolvers(); + + // We schedule a fitView by setting fitViewQueued and triggering a setNodes store.setState({ fitViewQueued: true, fitViewOptions: options, fitViewResolver }); batchContext.nodeQueue.push((nodes) => [...nodes]); + return fitViewResolver.promise; }, };