@@ -40,6 +40,8 @@ import { useSelectorDisplayName } from '@/hooks/use-selector-display-name'
4040import { useVariablesStore } from '@/stores/panel/variables/store'
4141import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
4242import { useSubBlockStore } from '@/stores/workflows/subblock/store'
43+ import { useWorkflowStore } from '@/stores/workflows/workflow/store'
44+ import { wouldCreateCycle } from '@/stores/workflows/workflow/utils'
4345
4446const logger = createLogger ( 'WorkflowBlock' )
4547
@@ -844,7 +846,11 @@ export const WorkflowBlock = memo(function WorkflowBlock({
844846 data-handleid = 'target'
845847 isConnectableStart = { false }
846848 isConnectableEnd = { true }
847- isValidConnection = { ( connection ) => connection . source !== id }
849+ isValidConnection = { ( connection ) => {
850+ if ( connection . source === id ) return false
851+ const edges = useWorkflowStore . getState ( ) . edges
852+ return ! wouldCreateCycle ( edges , connection . source ! , connection . target ! )
853+ } }
848854 />
849855 ) }
850856
@@ -1045,7 +1051,11 @@ export const WorkflowBlock = memo(function WorkflowBlock({
10451051 data-handleid = { `condition-${ cond . id } ` }
10461052 isConnectableStart = { true }
10471053 isConnectableEnd = { false }
1048- isValidConnection = { ( connection ) => connection . target !== id }
1054+ isValidConnection = { ( connection ) => {
1055+ if ( connection . target === id ) return false
1056+ const edges = useWorkflowStore . getState ( ) . edges
1057+ return ! wouldCreateCycle ( edges , connection . source ! , connection . target ! )
1058+ } }
10491059 />
10501060 )
10511061 } ) }
@@ -1064,7 +1074,11 @@ export const WorkflowBlock = memo(function WorkflowBlock({
10641074 data-handleid = 'error'
10651075 isConnectableStart = { true }
10661076 isConnectableEnd = { false }
1067- isValidConnection = { ( connection ) => connection . target !== id }
1077+ isValidConnection = { ( connection ) => {
1078+ if ( connection . target === id ) return false
1079+ const edges = useWorkflowStore . getState ( ) . edges
1080+ return ! wouldCreateCycle ( edges , connection . source ! , connection . target ! )
1081+ } }
10681082 />
10691083 </ >
10701084 ) }
@@ -1081,7 +1095,11 @@ export const WorkflowBlock = memo(function WorkflowBlock({
10811095 data-handleid = 'source'
10821096 isConnectableStart = { true }
10831097 isConnectableEnd = { false }
1084- isValidConnection = { ( connection ) => connection . target !== id }
1098+ isValidConnection = { ( connection ) => {
1099+ if ( connection . target === id ) return false
1100+ const edges = useWorkflowStore . getState ( ) . edges
1101+ return ! wouldCreateCycle ( edges , connection . source ! , connection . target ! )
1102+ } }
10851103 />
10861104
10871105 { shouldShowDefaultHandles && (
@@ -1100,7 +1118,11 @@ export const WorkflowBlock = memo(function WorkflowBlock({
11001118 data-handleid = 'error'
11011119 isConnectableStart = { true }
11021120 isConnectableEnd = { false }
1103- isValidConnection = { ( connection ) => connection . target !== id }
1121+ isValidConnection = { ( connection ) => {
1122+ if ( connection . target === id ) return false
1123+ const edges = useWorkflowStore . getState ( ) . edges
1124+ return ! wouldCreateCycle ( edges , connection . source ! , connection . target ! )
1125+ } }
11041126 />
11051127 ) }
11061128 </ >
0 commit comments