From 83fab4bc19b2d00d613276e5d6d7338433462ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=9E=E6=B3=95=E6=93=8D=E4=BD=9C?= Date: Thu, 4 Sep 2025 15:09:54 +0800 Subject: [PATCH] chore: (webhook) when content type changed clear the body variables (#25136) --- .../nodes/trigger-webhook/use-config.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/web/app/components/workflow/nodes/trigger-webhook/use-config.ts b/web/app/components/workflow/nodes/trigger-webhook/use-config.ts index f22b596dd8..e754d563f3 100644 --- a/web/app/components/workflow/nodes/trigger-webhook/use-config.ts +++ b/web/app/components/workflow/nodes/trigger-webhook/use-config.ts @@ -27,9 +27,25 @@ const useConfig = (id: string, payload: WebhookTriggerNodeType) => { const handleContentTypeChange = useCallback((contentType: string) => { setInputs(produce(inputs, (draft) => { + const previousContentType = draft.content_type draft.content_type = contentType + + // If the content type changes, reset body parameters and their variables, as the variable types might differ. + // However, we could consider retaining variables that are compatible with the new content type later. + if (previousContentType !== contentType) { + draft.body = [] + if (draft.variables) { + const bodyVariables = draft.variables.filter(v => v.label === 'body') + bodyVariables.forEach((v) => { + if (isVarUsedInNodes([id, v.variable])) + removeUsedVarInNodes([id, v.variable]) + }) + + draft.variables = draft.variables.filter(v => v.label !== 'body') + } + } })) - }, [inputs, setInputs]) + }, [inputs, setInputs, id, isVarUsedInNodes, removeUsedVarInNodes]) const syncVariablesInDraft = useCallback(( draft: WebhookTriggerNodeType,