@@ -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