From 405c7b55f8d1778969ff5548c3b0883f3250ac7d Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Wed, 16 Jul 2025 10:37:09 -0400 Subject: [PATCH] Fix settings dirty check --- webview-ui/src/components/settings/ApiOptions.tsx | 4 ++-- webview-ui/src/components/settings/SettingsView.tsx | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx index d0ec50abadc..06994b16b9b 100644 --- a/webview-ui/src/components/settings/ApiOptions.tsx +++ b/webview-ui/src/components/settings/ApiOptions.tsx @@ -167,10 +167,10 @@ const ApiOptions = ({ // Update `apiModelId` whenever `selectedModelId` changes. useEffect(() => { - if (selectedModelId) { + if (selectedModelId && apiConfiguration.apiModelId !== selectedModelId) { setApiConfigurationField("apiModelId", selectedModelId) } - }, [selectedModelId, setApiConfigurationField]) + }, [selectedModelId, setApiConfigurationField, apiConfiguration.apiModelId]) // Debounced refresh model updates, only executed 250ms after the user // stops typing. diff --git a/webview-ui/src/components/settings/SettingsView.tsx b/webview-ui/src/components/settings/SettingsView.tsx index cf9e779cbde..fd3a8a129b6 100644 --- a/webview-ui/src/components/settings/SettingsView.tsx +++ b/webview-ui/src/components/settings/SettingsView.tsx @@ -218,7 +218,15 @@ const SettingsView = forwardRef(({ onDone, t return prevState } - setChangeDetected(true) + const previousValue = prevState.apiConfiguration?.[field] + + // Don't treat initial sync from undefined to a defined value as a user change + // This prevents the dirty state when the component initializes and auto-syncs the model ID + const isInitialSync = previousValue === undefined && value !== undefined + + if (!isInitialSync) { + setChangeDetected(true) + } return { ...prevState, apiConfiguration: { ...prevState.apiConfiguration, [field]: value } } }) },