-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: prevent false unsaved changes notification when mode/API changes externally #7418
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -196,17 +196,44 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t | |||||
|
|
||||||
| setCachedState((prevCachedState) => ({ ...prevCachedState, ...extensionState })) | ||||||
| prevApiConfigName.current = currentApiConfigName | ||||||
| // Reset change detection when API config changes externally | ||||||
| setChangeDetected(false) | ||||||
| }, [currentApiConfigName, extensionState, isChangeDetected]) | ||||||
| }, [currentApiConfigName, extensionState]) | ||||||
|
|
||||||
| // Bust the cache when settings are imported. | ||||||
| useEffect(() => { | ||||||
| if (settingsImportedAt) { | ||||||
| setCachedState((prevCachedState) => ({ ...prevCachedState, ...extensionState })) | ||||||
| // Reset change detection when settings are imported | ||||||
| setChangeDetected(false) | ||||||
| } | ||||||
| }, [settingsImportedAt, extensionState]) | ||||||
|
|
||||||
| // Reset change detection when extensionState changes from outside the settings dialog | ||||||
| // This prevents false positives when mode or API config changes in the main interface | ||||||
| useEffect(() => { | ||||||
| // Check if the changes are coming from outside the settings dialog | ||||||
| // by comparing the extension state with our cached state | ||||||
| const isExternalChange = | ||||||
| extensionState.mode !== cachedState.mode || | ||||||
|
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. The code only checks for |
||||||
| JSON.stringify(extensionState.apiConfiguration) !== JSON.stringify(cachedState.apiConfiguration) | ||||||
|
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. Using
Suggested change
|
||||||
|
|
||||||
| if (isExternalChange && !isChangeDetected) { | ||||||
|
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 intentional? The condition |
||||||
| // Update cached state to match extension state for external changes | ||||||
| setCachedState((prevCachedState) => ({ | ||||||
| ...prevCachedState, | ||||||
| mode: extensionState.mode, | ||||||
| apiConfiguration: extensionState.apiConfiguration, | ||||||
| })) | ||||||
| } | ||||||
| }, [ | ||||||
| extensionState.mode, | ||||||
| extensionState.apiConfiguration, | ||||||
| cachedState.mode, | ||||||
| cachedState.apiConfiguration, | ||||||
| isChangeDetected, | ||||||
| ]) | ||||||
|
|
||||||
| const setCachedStateField: SetCachedStateField<keyof ExtensionStateContextType> = useCallback((field, value) => { | ||||||
| setCachedState((prevState) => { | ||||||
| if (prevState[field] === value) { | ||||||
|
|
||||||
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.
There are now three separate places handling similar logic for
setChangeDetected(false)(lines 200, 208, and within the new effect). Could we consolidate this logic into a single helper function or custom hook to improve maintainability?