Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions webview-ui/src/components/settings/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Copy link
Contributor Author

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:

  • The Save button activates when toggling from undefined to true
  • The Save button activates when toggling from undefined to true
  • The Save button doesn't activate when toggling these fields from undefined to false

This would help ensure the fix works as expected and prevent regressions.

(field === "enableUrlContext" || field === "enableGrounding") &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down
Loading