From eb52216a9c4131795cd7bcda829a37c3950b6946 Mon Sep 17 00:00:00 2001 From: crazywoola <100913391+crazywoola@users.noreply.github.com> Date: Tue, 9 Sep 2025 16:23:44 +0800 Subject: [PATCH] Revert "example of remove useEffect" (#25418) --- .../variable-inspect/value-content.tsx | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/web/app/components/workflow/variable-inspect/value-content.tsx b/web/app/components/workflow/variable-inspect/value-content.tsx index 2b28cd8ef4..a3ede311c4 100644 --- a/web/app/components/workflow/variable-inspect/value-content.tsx +++ b/web/app/components/workflow/variable-inspect/value-content.tsx @@ -60,18 +60,22 @@ const ValueContent = ({ const [fileValue, setFileValue] = useState(formatFileValue(currentVar)) const { run: debounceValueChange } = useDebounceFn(handleValueChange, { wait: 500 }) - if (showTextEditor) { - if (currentVar.value_type === 'number') - setValue(JSON.stringify(currentVar.value)) - if (!currentVar.value) - setValue('') - setValue(currentVar.value) - } - if (showJSONEditor) - setJson(currentVar.value ? JSON.stringify(currentVar.value, null, 2) : '') - if (showFileEditor) - setFileValue(formatFileValue(currentVar)) + // update default value when id changed + useEffect(() => { + if (showTextEditor) { + if (currentVar.value_type === 'number') + return setValue(JSON.stringify(currentVar.value)) + if (!currentVar.value) + return setValue('') + setValue(currentVar.value) + } + if (showJSONEditor) + setJson(currentVar.value ? JSON.stringify(currentVar.value, null, 2) : '') + + if (showFileEditor) + setFileValue(formatFileValue(currentVar)) + }, [currentVar.id, currentVar.value]) const handleTextChange = (value: string) => { if (currentVar.value_type === 'string')