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 } } }) },