Skip to content

Commit c35b1c4

Browse files
committed
fix(dups): onConntext being called twice for a signle edge, once in onConnectEnd and onConnectExtended
1 parent 7bf3d73 commit c35b1c4

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

apps/sim/lib/workflows/comparison/compare.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export function hasWorkflowChanged(
2424
deployedState: WorkflowState | null
2525
): boolean {
2626
// If no deployed state exists, then the workflow has changed
27-
if (!deployedState) return true
27+
if (!deployedState) {
28+
return true
29+
}
2830

2931
// 1. Compare edges (connections between blocks)
3032
const currentEdges = currentState.edges || []

apps/sim/stores/operation-queue/store.ts

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,41 @@ export const useOperationQueueStore = create<OperationQueueState>((set, get) =>
9595
return
9696
}
9797

98-
// Enhanced duplicate content check - especially important for block operations
99-
const duplicateContent = state.operations.find(
100-
(op) =>
101-
op.operation.operation === operation.operation.operation &&
102-
op.operation.target === operation.operation.target &&
103-
op.workflowId === operation.workflowId &&
104-
// For block operations, check the block ID specifically
105-
((operation.operation.target === 'block' &&
106-
op.operation.payload?.id === operation.operation.payload?.id) ||
107-
// For other operations, fall back to full payload comparison
108-
(operation.operation.target !== 'block' &&
109-
JSON.stringify(op.operation.payload) === JSON.stringify(operation.operation.payload)))
110-
)
98+
// Enhanced duplicate content check - especially important for block and edge operations
99+
const duplicateContent = state.operations.find((op) => {
100+
if (
101+
op.operation.operation !== operation.operation.operation ||
102+
op.operation.target !== operation.operation.target ||
103+
op.workflowId !== operation.workflowId
104+
) {
105+
return false
106+
}
107+
108+
// For block operations, check the block ID specifically
109+
if (operation.operation.target === 'block') {
110+
return op.operation.payload?.id === operation.operation.payload?.id
111+
}
112+
113+
// For edge operations (batch-add-edges), check by source→target connection
114+
// This prevents duplicate edges with different IDs but same connection
115+
if (
116+
operation.operation.target === 'edges' &&
117+
operation.operation.operation === 'batch-add-edges'
118+
) {
119+
const newEdges = operation.operation.payload?.edges || []
120+
const existingEdges = op.operation.payload?.edges || []
121+
// Check if any new edge has the same source→target as an existing operation's edges
122+
return newEdges.some((newEdge: any) =>
123+
existingEdges.some(
124+
(existingEdge: any) =>
125+
existingEdge.source === newEdge.source && existingEdge.target === newEdge.target
126+
)
127+
)
128+
}
129+
130+
// For other operations, fall back to full payload comparison
131+
return JSON.stringify(op.operation.payload) === JSON.stringify(operation.operation.payload)
132+
})
111133

112134
const isReplaceStateWorkflowOp =
113135
operation.operation.target === 'workflow' && operation.operation.operation === 'replace-state'

0 commit comments

Comments
 (0)