Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: nodeExtraData might be undefined (#21856)

crazywoola21e68b9cf146
diff --git a/web/app/components/workflow/hooks/use-nodes-data.ts b/web/app/components/workflow/hooks/use-nodes-data.ts
index aeb45ddb934..7df6b2ffd00 100644
--- a/web/app/components/workflow/hooks/use-nodes-data.ts
+++ b/web/app/components/workflow/hooks/use-nodes-data.ts
@@ -34,15 +34,14 @@ export const useNodesExtraData = () => {
export const useAvailableBlocks = (nodeType?: BlockEnum, isInIteration?: boolean, isInLoop?: boolean) => {
const nodesExtraData = useNodesExtraData()
const availablePrevBlocks = useMemo(() => {
- if (!nodeType)
+ if (!nodeType || !nodesExtraData[nodeType])
return []
return nodesExtraData[nodeType].availablePrevNodes || []
}, [nodeType, nodesExtraData])
const availableNextBlocks = useMemo(() => {
- if (!nodeType)
+ if (!nodeType || !nodesExtraData[nodeType])
return []
-
return nodesExtraData[nodeType].availableNextNodes || []
}, [nodeType, nodesExtraData])
@@ -55,10 +54,7 @@ export const useAvailableBlocks = (nodeType?: BlockEnum, isInIteration?: boolean
if (isInLoop && (nType === BlockEnum.Iteration || nType === BlockEnum.Loop || nType === BlockEnum.End))
return false
- if (!isInLoop && nType === BlockEnum.LoopEnd)
- return false
-
- return true
+ return !(!isInLoop && nType === BlockEnum.LoopEnd)
}),
availableNextBlocks: availableNextBlocks.filter((nType) => {
if (isInIteration && (nType === BlockEnum.Iteration || nType === BlockEnum.Loop || nType === BlockEnum.End))
@@ -67,10 +63,7 @@ export const useAvailableBlocks = (nodeType?: BlockEnum, isInIteration?: boolean
if (isInLoop && (nType === BlockEnum.Iteration || nType === BlockEnum.Loop || nType === BlockEnum.End))
return false
- if (!isInLoop && nType === BlockEnum.LoopEnd)
- return false
-
- return true
+ return !(!isInLoop && nType === BlockEnum.LoopEnd)
}),
}
}, [isInIteration, availablePrevBlocks, availableNextBlocks, isInLoop])