From f925869f61a357b8cefd5a38d10cb003dbbaac9e Mon Sep 17 00:00:00 2001 From: Minamiyama Date: Tue, 8 Jul 2025 15:41:27 +0800 Subject: [PATCH] fix(variable): ensure unique variable names in var-list (#22038) --- .../nodes/_base/components/variable/var-list.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-list.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-list.tsx index 73ee8262a..9eb34ac7f 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-list.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-list.tsx @@ -75,8 +75,16 @@ const VarList: FC = ({ if (isSupportConstantValue) draft[index].variable_type = VarKindType.variable - if (!draft[index].variable) - draft[index].variable = value[value.length - 1] + if (!draft[index].variable) { + const variables = draft.map(v => v.variable) + let newVarName = value[value.length - 1] + let count = 1 + while (variables.includes(newVarName)) { + newVarName = `${value[value.length - 1]}_${count}` + count++ + } + draft[index].variable = newVarName + } } else { draft[index].variable_type = VarKindType.constant