Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 6, 2026

Related GitHub Issue

Closes: #8230

Description

This PR attempts to address Issue #8230 where the Settings dialog incorrectly shows an unsaved changes prompt after Mode/API change without actual edits.

Root Cause (as identified by @rossdonald):
The OpenAICompatible component has a useEffect hook that blindly calls setApiConfigurationField("openAiHeaders", ...) on mount after a 300ms delay. It does not check if the new headers object is actually different from the current configuration. Since SettingsView relies on reference equality (===) to detect changes, the creation of a new object (even if identical in content) triggers the "dirty" state.

Fix:
Added a deep equality check using JSON.stringify before calling setApiConfigurationField, matching the pattern already used in ApiOptions.tsx. Now setApiConfigurationField is only called if the openAiHeaders have truly changed.

Also added apiConfiguration?.openAiHeaders to the useEffect dependency array for proper reactivity.

Feedback and guidance are welcome.

Test Procedure

  1. Run the existing tests: cd webview-ui && npx vitest run src/components/settings/providers/__tests__/OpenAICompatible.spec.tsx
  2. All 12 tests pass (including 2 new tests specifically for this fix)
  3. New tests verify that setApiConfigurationField is NOT called when headers have not changed

Manual testing:

  1. Open Settings with OpenAI Compatible provider configured
  2. Verify the unsaved changes prompt does not appear unless actual changes are made

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes.
  • Documentation Impact: No documentation updates required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

This fix follows the exact pattern suggested by @rossdonald in issue #8230 and matches the existing implementation in ApiOptions.tsx.

Add deep equality check before calling setApiConfigurationField for
openAiHeaders in OpenAICompatible.tsx. This prevents the Settings
dialog from incorrectly showing an unsaved changes prompt when the
headers have not actually changed.

The fix follows the same pattern already used in ApiOptions.tsx,
using JSON.stringify for deep equality comparison.

Fixes #8230
@roomote
Copy link
Contributor Author

roomote bot commented Jan 6, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly adds a deep equality check using JSON.stringify before calling setApiConfigurationField, following the established pattern in ApiOptions.tsx. The fix properly addresses the root cause where a new object reference was being created on mount even when headers had not changed, which incorrectly triggered the dirty state.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Unsaved-changes prompt after Mode/API change without edits

3 participants