Zustand Storage isn't persisting [BUG]
See original GitHub issueDescribe the bug
Storage doesn’t sync to server (liveblocks Dashboard) or any other connected clients.
To Reproduce
Steps to reproduce the behavior:
- Run
zustand-whiteboard
example (I cloned on codesandbox) - Fire-up a few browser tabs.
Expected behavior
- Positions of rectangles are synced across browser tabs
- Positions data is visible in liveblocks dashboard
Illustrations
Screenshot of independent rectangle positions:
Screenshot of empty liveblocks dashboard:
Environment (please complete the following information):
Everything in your Examples
- @liveblocks/client@0.16.9
- https://github.com/liveblocks/liveblocks/blob/main/examples/zustand-whiteboard/package.json#L6-L7
Additional context
- I’m trying to pull state out into Zustand/Redux/jotai and getting no luck.
- The React-based examples seem to work fine.
- Same issue in your “Upgrade examples to 0.16.1” PR
Issue Analytics
- State:
- Created a year ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Is it possible to immediately load persisted data? #346 - GitHub
I'm using the persist middleware and loading state from local storage. As far as I am aware, there is a brief period where...
Read more >react native with zustand persist - Stack Overflow
Now, when I try to add a todo, I run into the following error: ERROR TypeError: Invalid attempt to spread non-iterable instance. In...
Read more >Persistence - Jotai
Jotai has an atomWithStorage function in the utils bundle for persistence that supports persisting state in sessionStorage , localStorage , AsyncStorage ...
Read more >zustand - npm
Persist middleware. You can persist your store's data using any kind of storage. import create from 'zustand' ...
Read more >Zustand State Management in React (Better than Redux?)
Become a Patron and help the channel grow https://www.patreon.com/classsed ⌨️ Source Code ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This was the key thing I think I was missing when I first attempted this upgrade yesterday. I had explicit annotations all over the place that (I think) were necessary with the complexity of our use of pre v0.4 zustand and pre v0.18 liveblocks, and now it seems to be working with just that one annotation like you said.
I’ll let you know if I run into any other issues!
Hi @jamesbvaughan, that’s great feedback!
I’ll think about where to best document this, but that’s a great point. For now, we do have an internal test file that uses Zustand’s fishes-and-bears slice example, and you can use it as a reference to understand how you can define the slices, and how to annotate your
create()
call.You can find the standard Zustand setup parts here and here. Nothing Liveblocks related so far. Also, I wrapped this example in a
subscribeWithSelector
.The key type annotation to focus on from a Liveblocks perspective is now this line:
Key points:
WithLiveblocks<...>
helper, so the type of theliveblocks
property will be known.create()(...)
. This is required by Zustand, not Liveblocks, to aid type inference.Other than this, it should all work automatically. Please let us know if you’re running into issues with this.
With this new version, the only place where you should add an annotation is at the
create<T>()(...)
call. There,T
should be of the formWithLiveblocks<YourState>
. Once you do that, you should be able to remove all other explicit type annotations from your Zustand and Liveblocks related code. Again, please let us know if there’s anything we can help you with.