Skip to content

Commit a8b3490

Browse files
committed
fix: handle undefined Gemini settings when toggling checkboxes
- Add special handling for enableUrlContext and enableGrounding fields - Treat undefined as functionally equivalent to false for these boolean fields - Prevent false positives in change detection when setting from undefined to false - Fixes issue where Save button would not activate when toggling these settings Fixes #6616
1 parent 3f966df commit a8b3490

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,31 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
221221
const setApiConfigurationField = useCallback(
222222
<K extends keyof ProviderSettings>(field: K, value: ProviderSettings[K]) => {
223223
setCachedState((prevState) => {
224-
if (prevState.apiConfiguration?.[field] === value) {
224+
const previousValue = prevState.apiConfiguration?.[field]
225+
226+
// Check for strict equality first
227+
if (previousValue === value) {
225228
return prevState
226229
}
227230

228-
const previousValue = prevState.apiConfiguration?.[field]
231+
// Special handling for optional boolean fields where undefined is functionally equivalent to false
232+
// If the previous value was undefined and the new value is false, consider it no change.
233+
// This prevents false positives for change detection when an optional boolean is explicitly set to false.
234+
if (
235+
(field === "enableUrlContext" || field === "enableGrounding") &&
236+
previousValue === undefined &&
237+
value === false
238+
) {
239+
return prevState
240+
}
229241

230242
// Don't treat initial sync from undefined to a defined value as a user change
231243
// This prevents the dirty state when the component initializes and auto-syncs the model ID
232-
const isInitialSync = previousValue === undefined && value !== undefined
244+
// This check should NOT apply to the specific boolean fields where undefined is treated as false.
245+
const isInitialSync =
246+
previousValue === undefined &&
247+
value !== undefined &&
248+
!(field === "enableUrlContext" || field === "enableGrounding") // Exclude these fields from initial sync logic
233249

234250
if (!isInitialSync) {
235251
setChangeDetected(true)

0 commit comments

Comments
 (0)