fix: merge persisted settings with current snapshot during hydration

Prevent hydrateClientSettings from unconditionally overwriting in-memory
state with stale persisted data. If the snapshot changed while hydration
was in-flight (e.g. user toggled a setting), the persisted values are
now merged underneath the current snapshot, matching the merge strategy
already used in replaceSavedEnvironmentRegistryState.
This commit is contained in:
Cursor Agent committed 2026-04-10 03:20:08 +00:00
1 parent af019da240
commit 7a848c2ecd
1 file changed
+7 -1
+7 -1
View File
@@ -61,10 +61,16 @@ async function hydrateClientSettings(): Promise<void> {
}
const nextHydration = (async () => {
const snapshotBeforeHydration = clientSettingsSnapshot;
try {
const persistedSettings = await ensureLocalApi().persistence.getClientSettings();
if (persistedSettings) {
replaceClientSettingsSnapshot(persistedSettings);
const currentSnapshot = clientSettingsSnapshot;
if (currentSnapshot !== snapshotBeforeHydration) {
replaceClientSettingsSnapshot({ ...persistedSettings, ...currentSnapshot });
} else {
replaceClientSettingsSnapshot(persistedSettings);
}
}
} catch (error) {
console.error(`${CLIENT_SETTINGS_PERSISTENCE_ERROR_SCOPE} hydrate failed`, error);