fix: prevent false dirty state from headers in OpenAICompatible #10491
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
OpenAICompatiblecomponent has auseEffecthook that blindly callssetApiConfigurationField("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.stringifybefore callingsetApiConfigurationField, matching the pattern already used inApiOptions.tsx. NowsetApiConfigurationFieldis only called if theopenAiHeadershave truly changed.Also added
apiConfiguration?.openAiHeadersto theuseEffectdependency array for proper reactivity.Feedback and guidance are welcome.
Test Procedure
cd webview-ui && npx vitest run src/components/settings/providers/__tests__/OpenAICompatible.spec.tsxsetApiConfigurationFieldis NOT called when headers have not changedManual testing:
Pre-Submission Checklist
Documentation Updates
Additional Notes
This fix follows the exact pattern suggested by @rossdonald in issue #8230 and matches the existing implementation in
ApiOptions.tsx.