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

$patch method mutates the state property while trying to update another one #528

Closed
Oleksii14 opened this issue Jun 7, 2021 · 4 comments
Labels
bug Something isn't working has workaround The issue contains a temporary solution to get around the problem

Comments

@Oleksii14
Copy link

Reproduction

Clone repo https://github.com/Oleksii14/pinia-bug
yarn
yarn serve

Steps to reproduce the behavior

  1. Click on the items, see the error in the console about vue keys
  2. See that when you click on the items, I don't change the array. I update only selected property
  3. See that when I am trying to update one state property, $patch mutates another too

Expected behavior

$patch mutates only the property that I am passing in the state object

Actual behavior

I think $patch is not working properly because it updates the state properties that were not requested

Additional information

@posva posva added bug Something isn't working has workaround The issue contains a temporary solution to get around the problem labels Jun 7, 2021
@posva
Copy link
Member

posva commented Jun 7, 2021

As a workaround, directly set the property:

store.selectedItem = ...
store.$patch(state => {
  state.selectedItem = ...
})

@posva posva closed this as completed in a6a75e8 Jun 7, 2021
posva added a commit that referenced this issue Jun 7, 2021
@Oleksii14
Copy link
Author

@posva can you clarify, was this commit included in the vue2 version? Currently, I am using 0.5.2

@posva
Copy link
Member

posva commented Jul 27, 2021

yeah, it's fixed: 581bd08#diff-bc88fe45113de76e465408cc245572d27de83d31216672b06d1d2c16ccac7801R130

do you have a new failing test case? There are a few cases that cannot be achieved with the object syntax for $patch but they revolve around partial nested objects

@Oleksii14
Copy link
Author

Oleksii14 commented Jul 27, 2021

No, just asking for clarification 👍

All works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has workaround The issue contains a temporary solution to get around the problem
Projects
None yet
Development

No branches or pull requests

2 participants