Skip to content

Commit ce31c53

Browse files
committed
fix(workflow): size a container from one snapshot of the store
`calculateLoopDimensions` took child positions from the live store but child dimensions from the hook's render snapshot, so it was reading two ages of the same data. `resizeLoopNodes` walks deepest-first: an inner container resized earlier in the pass was already updated in the live snapshot and still stale in the closed-over one, so its parent sized against the old inner box and only caught up on a later render — a nested container visibly resizing twice, which is the symptom this branch set out to remove. Take both from the snapshot the function already reads.
1 parent a12011e commit ce31c53

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-node-utilities.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ export function useNodeUtilities(blocks: Record<string, any>) {
4040
* because measurements are not persisted. Estimating from state removes the
4141
* gap rather than waiting it out: both passes now produce the same number.
4242
*/
43-
const getBlockDimensions = useCallback(
44-
(blockId: string): { width: number; height: number } => {
45-
const block = blocks[blockId]
43+
const dimensionsOfBlock = useCallback(
44+
(block: any): { width: number; height: number } => {
4645
if (!block) {
4746
return { width: BLOCK_DIMENSIONS.FIXED_WIDTH, height: BLOCK_DIMENSIONS.MIN_HEIGHT }
4847
}
@@ -66,7 +65,12 @@ export function useNodeUtilities(blocks: Record<string, any>) {
6665
height: block.type === 'note' && block.height ? block.height : metrics.height,
6766
}
6867
},
69-
[blocks, isContainerType]
68+
[isContainerType]
69+
)
70+
71+
const getBlockDimensions = useCallback(
72+
(blockId: string): { width: number; height: number } => dimensionsOfBlock(blocks[blockId]),
73+
[blocks, dimensionsOfBlock]
7074
)
7175

7276
/**
@@ -298,14 +302,21 @@ export function useNodeUtilities(blocks: Record<string, any>) {
298302
.map((childId) => {
299303
const child = currentBlocks[childId]
300304
if (!child?.position) return null
301-
const { width, height } = getBlockDimensions(childId)
305+
/* Sized from `currentBlocks`, the same snapshot the position came
306+
from. Reading dimensions off the hook's render snapshot instead
307+
mixed two ages of the same store: `resizeLoopNodes` walks
308+
deepest-first, so an inner container resized earlier in the pass
309+
was already updated here but still old there, and the parent sized
310+
against a stale inner box — leaving nested containers to converge
311+
over a second pass. */
312+
const { width, height } = dimensionsOfBlock(child)
302313
return { x: child.position.x, y: child.position.y, width, height }
303314
})
304315
.filter((position): position is NonNullable<typeof position> => position !== null)
305316

306317
return calculateContainerDimensions(childPositions)
307318
},
308-
[getBlockDimensions]
319+
[dimensionsOfBlock]
309320
)
310321

311322
/**

0 commit comments

Comments
 (0)