Skip to content

Commit d7bb688

Browse files
committed
added back store check
1 parent 88a7991 commit d7bb688

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

apps/sim/stores/workflows/workflow/store.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,19 @@ describe('workflow store', () => {
297297
expectEdgeConnects(edges, 'block-1', 'block-2')
298298
})
299299

300+
it('should not add duplicate edges', () => {
301+
const { addBlock, batchAddEdges } = useWorkflowStore.getState()
302+
303+
addBlock('block-1', 'starter', 'Start', { x: 0, y: 0 })
304+
addBlock('block-2', 'function', 'End', { x: 200, y: 0 })
305+
306+
batchAddEdges([{ id: 'e1', source: 'block-1', target: 'block-2' }])
307+
batchAddEdges([{ id: 'e2', source: 'block-1', target: 'block-2' }])
308+
309+
const state = useWorkflowStore.getState()
310+
expectEdgeCount(state, 1)
311+
})
312+
300313
it('should prevent self-referencing edges', () => {
301314
const { addBlock, batchAddEdges } = useWorkflowStore.getState()
302315

apps/sim/stores/workflows/workflow/store.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,16 @@ export const useWorkflowStore = create<WorkflowStore>()(
506506
// Skip self-referencing edges
507507
if (edge.source === edge.target) continue
508508

509+
// Skip if identical connection already exists (same ports)
510+
const connectionExists = newEdges.some(
511+
(e) =>
512+
e.source === edge.source &&
513+
e.sourceHandle === edge.sourceHandle &&
514+
e.target === edge.target &&
515+
e.targetHandle === edge.targetHandle
516+
)
517+
if (connectionExists) continue
518+
509519
// Skip if would create a cycle
510520
if (wouldCreateCycle([...newEdges], edge.source, edge.target)) continue
511521

0 commit comments

Comments
 (0)