From fbb7b02e90bb7116f15eb977f3717d2c96e66384 Mon Sep 17 00:00:00 2001 From: lyzno1 <92089059+lyzno1@users.noreply.github.com> Date: Tue, 9 Sep 2025 17:11:11 +0800 Subject: [PATCH] fix(webhook): prevent SimpleSelect from resetting user selections (#25423) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- web/app/components/base/select/index.tsx | 17 +++++++++++------ .../components/parameter-table.tsx | 8 ++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/web/app/components/base/select/index.tsx b/web/app/components/base/select/index.tsx index 6befd86b80..d054a2f1d8 100644 --- a/web/app/components/base/select/index.tsx +++ b/web/app/components/base/select/index.tsx @@ -194,13 +194,18 @@ const SimpleSelect: FC = ({ const [selectedItem, setSelectedItem] = useState(null) - // Ensure selectedItem is properly set when defaultValue or items change + // Enhanced: Preserve user selection, only reset when necessary useEffect(() => { - let defaultSelect = null - // Handle cases where defaultValue might be undefined, null, or empty string - defaultSelect = (defaultValue && items.find((item: Item) => item.value === defaultValue)) || null - setSelectedItem(defaultSelect) - }, [defaultValue, items]) + // Only reset if no current selection or current selection is invalid + const isCurrentSelectionValid = selectedItem && items.some(item => item.value === selectedItem.value) + + if (!isCurrentSelectionValid) { + let defaultSelect = null + // Handle cases where defaultValue might be undefined, null, or empty string + defaultSelect = items.find((item: Item) => item.value === defaultValue) ?? null + setSelectedItem(defaultSelect) + } + }, [defaultValue, items, selectedItem]) const listboxRef = useRef(null) diff --git a/web/app/components/workflow/nodes/trigger-webhook/components/parameter-table.tsx b/web/app/components/workflow/nodes/trigger-webhook/components/parameter-table.tsx index da113183fb..ee1a663cb4 100644 --- a/web/app/components/workflow/nodes/trigger-webhook/components/parameter-table.tsx +++ b/web/app/components/workflow/nodes/trigger-webhook/components/parameter-table.tsx @@ -1,6 +1,6 @@ 'use client' import type { FC } from 'react' -import React from 'react' +import React, { useMemo } from 'react' import { useTranslation } from 'react-i18next' import GenericTable from './generic-table' import type { ColumnConfig, GenericTableRow } from './generic-table' @@ -31,7 +31,11 @@ const ParameterTable: FC = ({ }) => { const { t } = useTranslation() - const typeOptions = createParameterTypeOptions(contentType, isRequestBody) + // Memoize typeOptions to prevent unnecessary re-renders that cause SimpleSelect state resets + const typeOptions = useMemo(() => + createParameterTypeOptions(contentType, isRequestBody), + [contentType, isRequestBody], + ) // Define columns based on component type - matching prototype design const columns: ColumnConfig[] = [