Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session/local storage weird behaviour #193

Closed
yegorsid opened this issue Dec 3, 2024 · 3 comments
Closed

Session/local storage weird behaviour #193

yegorsid opened this issue Dec 3, 2024 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@yegorsid
Copy link

yegorsid commented Dec 3, 2024

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
Copy link
Owner

charkour commented Dec 3, 2024

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

@charkour charkour added the needs repro A reproduction is needed label Dec 3, 2024
@yegorsid
Copy link
Author

yegorsid commented Dec 3, 2024

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

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

@charkour charkour self-assigned this Jan 19, 2025
@charkour charkour added question Further information is requested and removed needs repro A reproduction is needed labels Jan 19, 2025
@charkour
Copy link
Owner

Thanks for the reproduction. I should update the documentation, but you'll need to put persist around both zustand stores. This issue has a solution: #121 (comment)

Here's an updated Stackblitz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants