charkour / zundo

🍜 undo/redo middleware for zustand. <700 bytes
https://codesandbox.io/s/zundo-2dom9
MIT License
648 stars 22 forks source link

Session/local storage weird behaviour #193

Open yegorsid opened 18 hours ago

yegorsid commented 18 hours ago

Hey!

I've just added undo/redo feature to my app and faced a few issues with session storage. Store resets after page reload, but it should not. But after that I can still undo my changes and store roll back to two steps before.

Did I implement Zundo improperly? Or may be there is a problem somewhere else?

Here is my store:

const useStore = create<State>()(
  temporal(
    (set, get) => {
    ...
  },
  {
    wrapTemporal: (storeInitializer) =>
      persist(storeInitializer, { name: 'flow-storage', storage: createJSONStorage(() => sessionStorage)}),
      handleSet: (handleSet) =>
        throttle<typeof handleSet>((state) => {
          handleSet(state);
        }, 1000),
    equality: (pastState, currentState) => customDeepEqual(pastState, currentState)
  })
);

export const useShallowStore = <U>(selector: (state: State) => U) => useStore(useShallow(selector));
charkour commented 18 hours ago

Hi @yegorsid, could you provide a Stackblitz with a simple reproduction? That will help me provide some suggestion! Thanks

yegorsid commented 17 hours ago

Hi @yegorsid, could you provide a Stackblitz with a simple reproduction? That will help me provide some suggestion! Thanks

Here is reproduction https://stackblitz.com/edit/vitejs-vite-95b41s?file=src%2FApp.tsx