-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: handle undefined Gemini settings when toggling checkboxes #6617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,15 +221,31 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t | |
| const setApiConfigurationField = useCallback( | ||
| <K extends keyof ProviderSettings>(field: K, value: ProviderSettings[K]) => { | ||
| setCachedState((prevState) => { | ||
| if (prevState.apiConfiguration?.[field] === value) { | ||
| const previousValue = prevState.apiConfiguration?.[field] | ||
|
|
||
| // Check for strict equality first | ||
| if (previousValue === value) { | ||
| return prevState | ||
| } | ||
|
|
||
| const previousValue = prevState.apiConfiguration?.[field] | ||
| // Special handling for optional boolean fields where undefined is functionally equivalent to false | ||
| // If the previous value was undefined and the new value is false, consider it no change. | ||
| // This prevents false positives for change detection when an optional boolean is explicitly set to false. | ||
| if ( | ||
| (field === "enableUrlContext" || field === "enableGrounding") && | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider extracting these hardcoded field names into constants. They're repeated on line 248, which could lead to maintenance issues if more fields need similar handling in the future. |
||
| previousValue === undefined && | ||
| value === false | ||
| ) { | ||
| return prevState | ||
| } | ||
|
|
||
| // 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 | ||
| // This check should NOT apply to the specific boolean fields where undefined is treated as false. | ||
| const isInitialSync = | ||
| previousValue === undefined && | ||
| value !== undefined && | ||
| !(field === "enableUrlContext" || field === "enableGrounding") // Exclude these fields from initial sync logic | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this approach scalable? If other optional boolean fields have similar issues in the future, we'd need to keep adding them here. Would it be worth considering a more generic solution, perhaps by maintaining a list of fields that should treat undefined as false? |
||
|
|
||
| if (!isInitialSync) { | ||
| setChangeDetected(true) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for this new behavior. Consider adding tests to verify:
This would help ensure the fix works as expected and prevent regressions.