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

Calling state setter function in onRehydrateStorage listener is not working when onRehydrateStorage and partialize exists #1527

Closed
3 tasks
lclrobert2020 opened this issue Jan 10, 2023 · 4 comments
Labels
enhancement New feature or request help wanted Please someone help on this middleware/persist This issue is about the persist middleware

Comments

@lclrobert2020
Copy link

lclrobert2020 commented Jan 10, 2023

Summary

When using persist middleware, if both onRehydrateStorage callback and partialize exist in the Persist options,
Setting state by calling store function inside the onRehydrateStorage listener failed to set and update the state of the store

The demo demonstrates the problem,
even when the setHasHydrated and onRehydrateStorage are being called
the screen still stuck in loading because the store is value is not updated

this happens only in v4.3.X

v.4.2.0 has no such problem

Link to reproduction

https://codesandbox.io/s/zustand-4-3-x-bug-srmtzq?file=/src/App.js
Please download it and run it locally because CodePen Demo can't access localStorage directly

Check List

[ tick ] Please do not ask questions in issues.

  • I've already opened a discussion before opening this issue.

Please fill this template if you're filling an issue regarding TypeScript.

  • I've added a link to a typescript playground or codesandbox with a minimal reproduction. Or some other way of reproduction if these two don't suffice.
  • I've read the typescript guide, in particular that create is to be used as create<T>()(...) and not create<T>(...).
@dai-shi
Copy link
Member

dai-shi commented Jan 11, 2023

Thanks for reporting. Very nice catch.

#1518 is the relevant PR.

Can anyone help identifying the issue? (Then, if possible, create a test and a fix?)

#1505 (comment) @MHC03 Is this the issue you mentioned about toThenable?

@dai-shi dai-shi added bug Something isn't working help wanted Please someone help on this middleware/persist This issue is about the persist middleware labels Jan 11, 2023
@dai-shi
Copy link
Member

dai-shi commented Jan 11, 2023

Wait, this only works in v4.2.0, but not in other previous versions. So, it's by-product of v4.2.0 before #1518 fix, not a bug introduced with new implementation.

@dai-shi dai-shi added enhancement New feature or request and removed bug Something isn't working labels Jan 11, 2023
@paradise
Copy link

paradise commented Mar 9, 2023

Any info about this? How to use onRehydrateStorage and partialize together ?

@dai-shi
Copy link
Member

dai-shi commented Mar 14, 2023

#1688 supersedes this.

@dai-shi dai-shi closed this as completed Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Please someone help on this middleware/persist This issue is about the persist middleware
Projects
None yet
Development

No branches or pull requests

3 participants