Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions webview-ui/src/components/settings/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
const { t } = useAppTranslation()

const extensionState = useExtensionState()
const { currentApiConfigName, listApiConfigMeta, uriScheme, settingsImportedAt } = extensionState
const { currentApiConfigName, listApiConfigMeta, uriScheme, settingsImportedAt, mode } = extensionState

const [isDiscardDialogShow, setDiscardDialogShow] = useState(false)
const [isChangeDetected, setChangeDetected] = useState(false)
Expand All @@ -147,6 +147,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
const contentRef = useRef<HTMLDivElement | null>(null)

const prevApiConfigName = useRef(currentApiConfigName)
const prevMode = useRef(mode)
const handledSettingsImportedAt = useRef<number | undefined>(undefined)
const confirmDialogHandler = useRef<() => void>()

Expand Down Expand Up @@ -220,16 +221,17 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
const apiConfiguration = useMemo(() => cachedState.apiConfiguration ?? {}, [cachedState.apiConfiguration])

useEffect(() => {
// Update only when currentApiConfigName is changed.
// Expected to be triggered by loadApiConfiguration/upsertApiConfiguration.
if (prevApiConfigName.current === currentApiConfigName) {
// Update when currentApiConfigName or mode changes.
// Expected to be triggered by loadApiConfiguration/upsertApiConfiguration or mode switch.
if (prevApiConfigName.current === currentApiConfigName && prevMode.current === mode) {
return
}

setCachedState((prevCachedState) => ({ ...prevCachedState, ...extensionState }))
prevApiConfigName.current = currentApiConfigName
prevMode.current = mode
setChangeDetected(false)
}, [currentApiConfigName, extensionState])
}, [currentApiConfigName, mode, extensionState])

// Bust the cache when settings are imported.
useEffect(() => {
Expand Down
Loading
Loading