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

RootState should be a complete copy not a reference. #1939

Closed
rauan100 opened this issue Feb 27, 2021 · 2 comments
Closed

RootState should be a complete copy not a reference. #1939

rauan100 opened this issue Feb 27, 2021 · 2 comments

Comments

@rauan100
Copy link

Version

3.6.2

Reproduction link

https://codesandbox.io/s/dank-https-tqtvo?file=/src/store/index.js

Steps to reproduce

Change input value

What is expected?

It is expected that the profile state value does not change

What is actually happening?

the profile state is change


The rootState parameter passed to an action, should be a complete copy of the state, not a reference. This allows me to change the state of another module without using an action or a commit for that module.

@sagadav
Copy link

sagadav commented Feb 28, 2021

rootState shouldn't be a copy. You are incorrectly assigning payload in the mutation

SET_PERSON(state, profile) {
      state.person = { ...profile };
}

https://vuex.vuejs.org/guide/mutations.html#mutations-follow-vue-s-reactivity-rules

@cuebit
Copy link
Member

cuebit commented Mar 20, 2021

As @sagadav quite rightly mentioned, rootState should be a reference. Actions are asynchronous, state can change at any point between an actions invocation and resolution.

@cuebit cuebit closed this as completed Mar 20, 2021
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

3 participants