Przeglądaj źródła

Fix settings dirty check (#5779)

Matt Rubens 6 miesięcy temu
rodzic
commit
0f994fcf22

+ 2 - 2
webview-ui/src/components/settings/ApiOptions.tsx

@@ -167,10 +167,10 @@ const ApiOptions = ({
 
 
 	// Update `apiModelId` whenever `selectedModelId` changes.
 	// Update `apiModelId` whenever `selectedModelId` changes.
 	useEffect(() => {
 	useEffect(() => {
-		if (selectedModelId) {
+		if (selectedModelId && apiConfiguration.apiModelId !== selectedModelId) {
 			setApiConfigurationField("apiModelId", selectedModelId)
 			setApiConfigurationField("apiModelId", selectedModelId)
 		}
 		}
-	}, [selectedModelId, setApiConfigurationField])
+	}, [selectedModelId, setApiConfigurationField, apiConfiguration.apiModelId])
 
 
 	// Debounced refresh model updates, only executed 250ms after the user
 	// Debounced refresh model updates, only executed 250ms after the user
 	// stops typing.
 	// stops typing.

+ 9 - 1
webview-ui/src/components/settings/SettingsView.tsx

@@ -218,7 +218,15 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
 					return prevState
 					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 } }
 				return { ...prevState, apiConfiguration: { ...prevState.apiConfiguration, [field]: value } }
 			})
 			})
 		},
 		},