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

please highlight breaking changes when migrating from v2 to v3 (( thank you )). #159

Closed
a-eid opened this issue Aug 18, 2020 · 8 comments
Closed

Comments

@a-eid
Copy link

a-eid commented Aug 18, 2020

so far I was able to identify 1 breaking change in the lib api.

const [useStore, storeApi] = create(...)
storeApi.setState(...)
const useStore = create(...)
useStore.setState(...)
@drcmda
Copy link
Member

drcmda commented Aug 18, 2020

it's in the release tag https://github.com/react-spring/zustand/releases/tag/v3.0.0

there are no breaking changes in this release. but v4 will cut off the tuple api.

@a-eid a-eid closed this as completed Aug 18, 2020
@uzairfaisal
Copy link

uzairfaisal commented Oct 14, 2020

Actually, I'd like to highlight a breaking change. When using devtools, the set function which saves the partial object to the state would previously accept the name of the action as the 2nd param. Now, the 2nd param is changed to whether the partial object should overwrite the state or not - and any previous name param being passed to the set(...) would result in the state being overwritten in 3.x whereas this was not the behaviour in 2.x.

This is highlighted here:
https://github.com/pmndrs/zustand/blob/master/src/middleware.ts#L33

Compared to what was there for 2.x:
https://github.com/pmndrs/zustand/blob/f87534e444f2f48a1af89459d141660ffda855c6/src/middleware.ts

Unless I missed something already mentioned before, please highlight this as a breaking change from 2 -> 3 so it's clear for all. This tripped our upgrade to 3.x.

@dai-shi
Copy link
Member

dai-shi commented Oct 14, 2020

@uzairfaisal
Hi, thanks for trying. As far as I remember, that's something we fixed in v3. #77
Does devtools in v2 work at all for you?

@uzairfaisal
Copy link

uzairfaisal commented Oct 14, 2020

@uzairfaisal
Hi, thanks for trying. As far as I remember, that's something we fixed in v3. #77
Does devtools in v2 work at all for you?

@dai-shi the fix you're referring to is adding the replace argument for the set(...) (when using devtools), but instead you added it as the 2nd param but that breaks the API from v2 code (from set(partial, name) -> set(partial, replace, name)).

Afaik, devtools should works for us in v2 (CC: @timkindberg) though I haven't explicitly checked this. The very same code example that should work in v2 in that post you linked would fail misbehave in v3:

const [useStore] = create(devtools(set => ({
  count: 1,
  inc: () => set(state => ({ count: state.count + 1 }), 'inc'), // in v3, the 2nd param is for replace and in v2, the 2nd param is for name
  dec: () => set(state => ({ count: state.count - 1 }), 'dec') // same here
})))

It should instead be

const [useStore] = create(devtools(set => ({
  count: 1,
  inc: () => set(state => ({ count: state.count + 1 }), false, 'inc'), // notice the 2nd param change
  dec: () => set(state => ({ count: state.count - 1 }), false, 'dec') // same here
})))

If I don't pass false (or falsey) as the 2nd argument, the inc + dec attributes will be lost in the store. This means that v2 code using devtools does need to be changed (ie. breaking change). Hope that helps narrow this down.

@dai-shi
Copy link
Member

dai-shi commented Oct 14, 2020

That was a huge misunderstanding of mine. Thanks for noting.
I added a note in v3.0.2 release which has the change.
Please suggest better description if you have any.
https://github.com/pmndrs/zustand/releases/tag/v3.0.2

@MarkAPhillips
Copy link

MarkAPhillips commented May 24, 2022

Please note there is still in issue in relation to Typescript which has been mentioned but thought I would highlight it again as it still expects 1-2 arguments and not 3 as above if you use the SetState type

referencing #705 (comment)

@dai-shi
Copy link
Member

dai-shi commented May 24, 2022

@MarkAPhillips TS support is changed and should be improved in v4. Please open a new issue with a reproduction.

@MarkAPhillips
Copy link

MarkAPhillips commented May 24, 2022

@dai-shi thanks - I realise the issue now and more relates to documentation - that is you can use the NamedSet<T> type if using devtools - which I determined from your updates - maybe this is something to consider when releasing the next version

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

No branches or pull requests

5 participants