feat(GlobalStateStore): prevent saving during initial load

This commit is contained in:
2026-02-07 22:54:00 +02:00
parent 2e23b259ab
commit c2113357f2
4 changed files with 19 additions and 19 deletions

View File

@@ -301,6 +301,9 @@ const GlobalStateStore = createStore<GlobalStateStoreType>((set, get) => ({
...createComplexActions(set, get),
}));
// Flag to prevent saving during initial load
let isInitialLoad = true;
loadStorage()
.then((state) => {
GlobalStateStore.setState((current) => ({
@@ -316,9 +319,18 @@ loadStorage()
})
.catch((e) => {
console.error('Error loading storage:', e);
})
.finally(() => {
// Enable saving after initial load completes
isInitialLoad = false;
});
GlobalStateStore.subscribe((state) => {
// Skip saving during initial load
if (isInitialLoad) {
return;
}
saveStorage(state).catch((e) => {
console.error('Error saving storage:', e);
});

View File

@@ -11,7 +11,6 @@ import {
import type { GlobalState, GlobalStateStoreType, ProgramState } from './GlobalStateStore.types';
import { GetGlobalState, GlobalStateStore } from './GlobalStateStore';
import { loadStorage } from './GlobalStateStore.utils';
interface GlobalStateStoreContextValue {
fetchData: (url?: string) => Promise<void>;
@@ -76,23 +75,6 @@ export function GlobalStateStoreProvider({
await throttledFetch();
}, [throttledFetch]);
useEffect(() => {
loadStorage()
.then((state) => {
GlobalStateStore.setState((current) => ({
...current,
...state,
session: {
...current.session,
...state.session,
},
}));
})
.catch((e) => {
console.error('Error loading storage on mount:', e);
});
}, []);
useEffect(() => {
if (apiURL) {
GlobalStateStore.getState().setApiURL(apiURL);