-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
RFC: How is v5-alpha/beta? #2329
Comments
|
|
|
|
|
Maybe this ordering on "exports" can be changed for RN users of zustand ? |
@jacargentina let me take care of that |
@dbritto-dev I've solved it by configuring in config.resolver.unstable_conditionNames = ['require']; default is |
@jacargentina nice, I found that yesterday too but I didn't have time to answer any question. We shall add it to the docs. |
Does the readme of the v5 branch already reflect the changes that will be coming up in v5 or is there some other place where one could read about it? |
Thanks for reporting. |
I will create an example later. I can first describe how I encountered this problem. I first migrated from redux toolkit to zustand^4 and everything worked fine. The reason for this problem may be that Redux useSelector's callback do'not need to be wrapped by useCallback. After #2395, which may have caused the issue. Maybe useSyncExternalStoreWithSelector would be more suitable? |
https://stackblitz.com/edit/vitejs-vite-qvlgmz?file=src%2Fcomponents%2FTodolist.tsx @dai-shi I have create a todo list demo with this bug. The reason why it fails is because of the use of the useTodoFindIds function. Of course, the actual scenario is more complicated than what is written here. I want to find a set of data and then return their IDs. I'm not sure if some best practices were violated that caused this problem? |
Yes, you create a new reference every time in your selector function. // an easy reproduction
const useFooStore = create((set) => ({
todos: [],
}))
// this will cause an infinite loop because of new reference every render
useFooStore((state) => state.todos.map((todo) => todo.id)) To resolve it, either use This infinite-loop behavior can happen without Zustand, and Zustand follows the same behavior. |
@flq yeah, I'll add it. btw, they talk about memoizing selectors. |
FYI, proxy-memoize also works. https://redux.js.org/usage/deriving-data-selectors#proxy-memoize |
https://www.npmjs.com/package/zustand/v/5.0.0-beta.0 is published! Migration Guide: https://github.com/pmndrs/zustand/blob/v5/docs/guides/migrating-to-v5.mdx |
May post a reproduction when I find the time, but as a general note, I've been getting a ton of
and
errors after migrating from the latest version of v4 to v5 beta EDIT: Found the cause
|
Also ran into the same error when combing Zustand with proxy-memoize v3 that didn't occur before. Not exactly sure how to solve this one.
|
That sounds unexpected. Can you create a small reproduction with stackblitz? |
https://stackblitz.com/edit/vitejs-vite-ob9acn?file=src%2FApp.tsx |
Thanks. Now I get it. It the usage issue of proxy-memoze. By default, In other words, zustand v5 reveals the issue which was hidden in v4, and with the new one, it performs better. |
I tried install immer in my project. It works fine.
|
Are you sure? We got reports from someone that it didn't work with v4 without installing |
Ops, I fonud that @reduxjs/toolkit deps on immer. I made a mistake. It seems that there are some things to pay attention to when migrating from redux/toolkit to zustand |
@cqh963852 yeah, redux toolkit use immer if you use plain redux everything would be ok but since you are using redux toolkit you need to be careful due to is not a straightforward migration to zustand |
This comment was marked as off-topic.
This comment was marked as off-topic.
I'll work on creating a reproduction in React Native, but using 5.0.0-beta.0 returns this error "The result of getSnapshot should be cached to avoid an infinite loop". zustand@5.0.0-beta.0 works well on Next.js v14 (see tekton.com) |
I realized on our Next.js app that we are still using I think making stable selectors will fix this issue: https://github.com/pmndrs/zustand/blob/v5/docs/guides/migrating-to-v5.mdx#requiring-stable-selector-outputs I will verify and confirm. |
FYI: The migrating to v5 doc has moved, it is now here -> https://github.com/pmndrs/zustand/blob/v5/docs/migrations/migrating-to-v5.md (some of the links in the discussions above now may end up as 404 not found) |
#2138 is finally merged. Thanks everyone for your support. |
Zustand v5 is being developed #2138 and some alpha versions have been published.
We need more feedback before going beta, and releasing it finally.
npm i zustand@next
Please add reactions to this issue:
👍 : I tested v5-alpha in my project and it works fine.
👎 : I tested v5-alpha in my project and it fails. < Comment below!
👀 : I'm going to try it ASAP.
The text was updated successfully, but these errors were encountered: