From 3162641acea20e8180032bf467b9cf8db2d77e4e Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Mon, 16 Mar 2026 22:16:36 -0700 Subject: [PATCH 1/2] fix(embedded): block layout should not be dependent on viewport --- .../[workspaceId]/w/[workflowId]/workflow.tsx | 78 ++++++++++++++++++- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx index 9b13576c64..2e52970ad3 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx @@ -208,7 +208,8 @@ const reactFlowStyles = [ '[&_.react-flow__node-subflowNode.selected]:!shadow-none', ].join(' ') const reactFlowFitViewOptions = { padding: 0.6, maxZoom: 1.0 } as const -const embeddedFitViewOptions = { padding: 0.15, maxZoom: 0.85, minZoom: 0.35 } as const +const embeddedFitViewOptions = { padding: 0.15, maxZoom: 0.85, minZoom: 0.1 } as const +const embeddedResizeFitViewOptions = { ...embeddedFitViewOptions, duration: 0 } as const const reactFlowProOptions = { hideAttribution: true } as const /** @@ -244,7 +245,10 @@ const WorkflowContent = React.memo( const [potentialParentId, setPotentialParentId] = useState(null) const [selectedEdges, setSelectedEdges] = useState(new Map()) const [isErrorConnectionDrag, setIsErrorConnectionDrag] = useState(false) + const canvasContainerRef = useRef(null) const selectedIdsRef = useRef(null) + const embeddedFitFrameRef = useRef(null) + const hasCompletedInitialEmbeddedFitRef = useRef(false) const canvasMode = useCanvasModeStore((state) => state.mode) const isHandMode = embedded ? true : canvasMode === 'hand' const { handleCanvasMouseDown, selectionProps } = useShiftSelectionLock({ isHandMode }) @@ -373,6 +377,34 @@ const WorkflowContent = React.memo( ] ) + const scheduleEmbeddedFit = useCallback(() => { + if (!embedded || !isWorkflowReady) return + + if (embeddedFitFrameRef.current !== null) { + cancelAnimationFrame(embeddedFitFrameRef.current) + } + + embeddedFitFrameRef.current = requestAnimationFrame(() => { + embeddedFitFrameRef.current = null + + const container = canvasContainerRef.current + if (!container) return + + const rect = container.getBoundingClientRect() + if (rect.width <= 0 || rect.height <= 0) return + + const nodes = reactFlowInstance.getNodes() + if (nodes.length > 0) { + void reactFlowInstance.fitView(embeddedResizeFitViewOptions) + } + + if (!hasCompletedInitialEmbeddedFitRef.current) { + hasCompletedInitialEmbeddedFitRef.current = true + setIsCanvasReady(true) + } + }) + }, [embedded, isWorkflowReady, reactFlowInstance]) + const { getNodeDepth, getNodeAbsolutePosition, @@ -3750,10 +3782,46 @@ const WorkflowContent = React.memo( activeWorkflowId, ]) + useEffect(() => { + if (!embedded || !isWorkflowReady) { + return + } + + const container = canvasContainerRef.current + if (!container) { + return + } + + scheduleEmbeddedFit() + + const resizeObserver = new ResizeObserver(() => { + scheduleEmbeddedFit() + }) + + resizeObserver.observe(container) + + return () => { + resizeObserver.disconnect() + + if (embeddedFitFrameRef.current !== null) { + cancelAnimationFrame(embeddedFitFrameRef.current) + embeddedFitFrameRef.current = null + } + } + }, [embedded, isWorkflowReady, scheduleEmbeddedFit]) + + useEffect(() => { + if (!embedded || !isWorkflowReady) { + return + } + + scheduleEmbeddedFit() + }, [displayNodes, embedded, isWorkflowReady, scheduleEmbeddedFit]) + return (
-
+
{!isWorkflowReady && (
{ + if (embedded) { + return + } + requestAnimationFrame(() => { - instance.fitView(embedded ? embeddedFitViewOptions : reactFlowFitViewOptions) + instance.fitView(reactFlowFitViewOptions) setIsCanvasReady(true) }) }} From b188e6af2d0fbf6bd2be6c97558100eecc2b63c6 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Mon, 16 Mar 2026 22:49:20 -0700 Subject: [PATCH 2/2] address comments --- .../sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx index 2e52970ad3..c57a7a984b 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx @@ -3816,7 +3816,7 @@ const WorkflowContent = React.memo( } scheduleEmbeddedFit() - }, [displayNodes, embedded, isWorkflowReady, scheduleEmbeddedFit]) + }, [blocksStructureHash, embedded, isWorkflowReady, scheduleEmbeddedFit]) return (