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:
1 file changed
+7
-1
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user