diff --git a/CHANGELOG.md b/CHANGELOG.md index cb5ef99..bd8e4fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # @warkypublic/zustandsyncstore +## 0.0.37 + +### Patch Changes + +- feat(GlobalStateStore): prevent saving during initial load + ## 0.0.36 ### Patch Changes diff --git a/package.json b/package.json index 5a88879..a539092 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@warkypublic/oranguru", "author": "Warky Devs", - "version": "0.0.36", + "version": "0.0.37", "type": "module", "types": "./dist/lib.d.ts", "main": "./dist/lib.cjs.js", diff --git a/src/GlobalStateStore/GlobalStateStore.ts b/src/GlobalStateStore/GlobalStateStore.ts index 6df7de8..ea440aa 100644 --- a/src/GlobalStateStore/GlobalStateStore.ts +++ b/src/GlobalStateStore/GlobalStateStore.ts @@ -301,6 +301,9 @@ const GlobalStateStore = createStore((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); }); diff --git a/src/GlobalStateStore/GlobalStateStoreWrapper.tsx b/src/GlobalStateStore/GlobalStateStoreWrapper.tsx index 413fdd0..aae306b 100644 --- a/src/GlobalStateStore/GlobalStateStoreWrapper.tsx +++ b/src/GlobalStateStore/GlobalStateStoreWrapper.tsx @@ -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; @@ -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);