From 7a848c2ecdc45bb330abbcdcda9e77d1413f765f Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 10 Apr 2026 03:20:08 +0000 Subject: [PATCH] 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. --- apps/web/src/hooks/useSettings.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/web/src/hooks/useSettings.ts b/apps/web/src/hooks/useSettings.ts index 3dc2cf9b20..a94ec061c1 100644 --- a/apps/web/src/hooks/useSettings.ts +++ b/apps/web/src/hooks/useSettings.ts @@ -61,10 +61,16 @@ async function hydrateClientSettings(): Promise { } 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);