mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
fix: prevent false dirty state when opening Settings after Mode/API change
- Added isInitialMount ref to track first mount of SettingsView - Sync extension state on mount without marking as dirty - Simplified setApiConfigurationField to only mark as dirty for user actions - Removed complex initial sync logic that was causing false positives Fixes #8230
This commit is contained in:
parent
0e1b23d09c
commit
8109ac3339
1 changed files with 15 additions and 7 deletions
|
|
@ -195,6 +195,9 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
|
|||
|
||||
const apiConfiguration = useMemo(() => cachedState.apiConfiguration ?? {}, [cachedState.apiConfiguration])
|
||||
|
||||
// Track if this is the initial mount to avoid marking as dirty on first sync
|
||||
const isInitialMount = useRef(true)
|
||||
|
||||
useEffect(() => {
|
||||
// Update only when currentApiConfigName is changed.
|
||||
// Expected to be triggered by loadApiConfiguration/upsertApiConfiguration.
|
||||
|
|
@ -215,6 +218,15 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
|
|||
}
|
||||
}, [settingsImportedAt, extensionState])
|
||||
|
||||
// Sync with extension state on mount without marking as dirty
|
||||
useEffect(() => {
|
||||
if (isInitialMount.current) {
|
||||
setCachedState(extensionState)
|
||||
setChangeDetected(false)
|
||||
isInitialMount.current = false
|
||||
}
|
||||
}, [extensionState])
|
||||
|
||||
const setCachedStateField: SetCachedStateField<keyof ExtensionStateContextType> = useCallback((field, value) => {
|
||||
setCachedState((prevState) => {
|
||||
if (prevState[field] === value) {
|
||||
|
|
@ -233,13 +245,9 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
|
|||
return prevState
|
||||
}
|
||||
|
||||
const previousValue = prevState.apiConfiguration?.[field]
|
||||
|
||||
// Only skip change detection for automatic initialization (not user actions)
|
||||
// This prevents the dirty state when the component initializes and auto-syncs values
|
||||
const isInitialSync = !isUserAction && previousValue === undefined && value !== undefined
|
||||
|
||||
if (!isInitialSync) {
|
||||
// Only mark as changed if this is a user action
|
||||
// Don't mark as changed for programmatic updates (like initial sync)
|
||||
if (isUserAction) {
|
||||
setChangeDetected(true)
|
||||
}
|
||||
return { ...prevState, apiConfiguration: { ...prevState.apiConfiguration, [field]: value } }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue