Skip to content

Commit 39faf7c

Browse files
fix: address socket parent sync review
1 parent 94b0be2 commit 39faf7c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

apps/sim/socket/database/operations.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ async function handleBlockOperationTx(
601601
workflowId: string,
602602
operation: string,
603603
payload: any
604-
): Promise<OperationResult | void> {
604+
): Promise<OperationResult | undefined> {
605605
switch (operation) {
606606
case BLOCK_OPERATIONS.UPDATE_POSITION: {
607607
if (!payload.id || !payload.position) {
@@ -1062,7 +1062,7 @@ async function handleBlocksOperationTx(
10621062
workflowId: string,
10631063
operation: string,
10641064
payload: any
1065-
): Promise<OperationResult | void> {
1065+
): Promise<OperationResult | undefined> {
10661066
switch (operation) {
10671067
case BLOCKS_OPERATIONS.BATCH_UPDATE_POSITIONS: {
10681068
const { updates } = payload
@@ -1631,10 +1631,8 @@ async function handleBlocksOperationTx(
16311631

16321632
const allRemovedEdgeIds: string[] = []
16331633
const allAddedEdges: NonNullable<OperationResult['addedEdges']> = []
1634+
const applicableUpdates: Array<(typeof updates)[number]> = []
16341635

1635-
// Collect all block IDs being moved in this batch so removeBoundaryEdges
1636-
// can treat them as already inside the target container
1637-
const allMovingBlockIds = new Set(updates.map((u: { id: string }) => u.id))
16381636
for (const update of updates) {
16391637
const { id, parentId, position } = update
16401638
if (!id) continue
@@ -1662,6 +1660,17 @@ async function handleBlocksOperationTx(
16621660
continue
16631661
}
16641662

1663+
applicableUpdates.push(update)
1664+
}
1665+
1666+
// Collect only block IDs that will actually be moved in this batch so
1667+
// removeBoundaryEdges can treat them as already inside the target container.
1668+
const allMovingBlockIds = new Set(applicableUpdates.map((update) => update.id))
1669+
1670+
for (const update of applicableUpdates) {
1671+
const { id, parentId, position } = update
1672+
if (!id) continue
1673+
16651674
const isRemovingFromParent = !parentId
16661675

16671676
// Get current data and position

apps/sim/socket/handlers/operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
type VariableOperation,
1010
WORKFLOW_OPERATIONS,
1111
} from '@/socket/constants'
12-
import { persistWorkflowOperation, enrichBatchAddBlocksPayload } from '@/socket/database/operations'
12+
import { enrichBatchAddBlocksPayload, persistWorkflowOperation } from '@/socket/database/operations'
1313
import type { AuthenticatedSocket } from '@/socket/middleware/auth'
1414
import { checkRolePermission } from '@/socket/middleware/permissions'
1515
import type { IRoomManager, UserSession } from '@/socket/rooms'

0 commit comments

Comments
 (0)