Breaking change introduced in 4.5.5 by changing the default behaviour #2763
Unanswered
vitorsilvalima
asked this question in
Bug report
Replies: 3 comments 5 replies
-
version 4.5.4: Screen.Recording.2024-09-30.at.19.00.24.movversion 4.5.5: Screen.Recording.2024-09-30.at.19.00.01.mov |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for reporting. Meanwhile, to get the previous behavior, I think this workaround would do: |
Beta Was this translation helpful? Give feedback.
5 replies
-
Another critical bug caused by this behavior change might be #2827. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Bug Description
In previous versions of Zustand (up to version 4.5.4), the default state would automatically persist in the storage (e.g., AsyncStorage in React Native) even if it had never changed. This behavior was crucial in ensuring that the app retained its initial state after a restart, which helped maintain consistency.
However, after updating to version 4.5.5, I've noticed that the default state is no longer persisted at all. Upon app restarts, the default state keeps resetting, causing significant issues in production. This change in the default behavior of Zustand is breaking expected functionality in my React Native application, leading to data inconsistency and unexpected behavior.
I believe this might be an unintended regression or change in the library's persistence mechanism, and I would appreciate any clarification or fix for this issue.
Steps to reproduce:
Use Zustand version 4.5.5 in a React Native app with AsyncStorage for persistence.
Define a default state in the store.
Restart the app without manually changing the state.
Observe that the default state does not persist across restarts.
Expected behavior: The default state should persist in storage, as it did in version 4.5.4 and earlier, unless explicitly modified by the user.
Actual behavior: The default state is not persisted in storage after app restarts, causing it to reset.
Environment:
Zustand version: 4.5.5
Example:
Reproduction Link
4.5.4: https://stackblitz.com/edit/zustand-persist-behavior-4-5-4?file=src%2Fmain.tsx
4.5.5: https://stackblitz.com/edit/zustand-persist-behavior-4-5-5?file=src%2Fmain.tsx
Beta Was this translation helpful? Give feedback.
All reactions