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

Vuex strict mode always leads to "do not mutate vuex store state outside mutation handlers" #184

Open
phil294 opened this issue Mar 16, 2020 · 2 comments

Comments

@phil294
Copy link

phil294 commented Mar 16, 2020

Strict mode: https://vuex.vuejs.org/guide/strict.html

When this is enabled, all mutations throw an error (stack trace below), even when commited through a mutation, as you should:

<button @click="$store.commit('setSomeVal')">set someVal</button>
export function createStore() {
	return new Vuex.Store({
		strict: true, // <----------
		state() { return { someVal: false } },
		mutations: {
			setSomeVal(state) {
				state.someVal = true;
			}
		},
		actions: {}, modules: {}
})}

Clicking the button should not generate the error, but it does. I tested this with a clean vue project with nothing else added.

Is this expected behaviour or a bug? If the latter, do you still accept pull requests in case I can track it down?
Thanks!

VM547 chunk-vendors.js:8373 [Vue warn]:
Error in callback for watcher "function () { return this._data.$$state }":
  "Error: [vuex] do not mutate vuex store state outside mutation handlers."

(found in <Root>)
warn @ VM547 chunk-vendors.js:8373
logError @ VM547 chunk-vendors.js:9636
globalHandleError @ VM547 chunk-vendors.js:9631
handleError @ VM547 chunk-vendors.js:9591
run @ VM547 chunk-vendors.js:12317
update @ VM547 chunk-vendors.js:12289
notify @ VM547 chunk-vendors.js:8484
reactiveSetter @ VM547 chunk-vendors.js:8809
reactiveSetter @ vue.runtime.esm.js:1050
setSomeVal @ index.js:16
wrappedMutationHandler @ vuex.esm.js:744
commitIterator @ vuex.esm.js:392
(anonymous) @ vuex.esm.js:391
_withCommit @ vuex.esm.js:526
commit @ vuex.esm.js:390
boundCommit @ vuex.esm.js:335
click @ Home.vue?012f:17
invokeWithErrorHandling @ vue.runtime.esm.js:1854
invoker @ vue.runtime.esm.js:2179
original._wrapper @ vue.runtime.esm.js:6917
VM547 chunk-vendors.js:9640 Error: [vuex] do not mutate vuex store state outside mutation handlers.
    at assert (VM547 chunk-vendors.js:16303)
    at Vue.store._vm.$watch.deep (VM547 chunk-vendors.js:17006)
    at Watcher.run (VM547 chunk-vendors.js:12315)
    at Watcher.update (VM547 chunk-vendors.js:12289)
    at Dep.notify (VM547 chunk-vendors.js:8484)
    at Object.reactiveSetter (VM547 chunk-vendors.js:8809)
    at Object.reactiveSetter [as someVal] (VM547 chunk-vendors.js:8804)
    at Store.setSomeVal (VM548 app.js:1950)
    at wrappedMutationHandler (VM547 chunk-vendors.js:16957)
    at commitIterator (VM547 chunk-vendors.js:16605)
@waydelyle
Copy link
Contributor

try removing vuex-router-sync if you have it.

@phil294
Copy link
Author

phil294 commented Mar 18, 2020

@waydelyle Nice idea, but not installed. Adding it does not change anything either.
The issue also happens in a fresh vue / ssr-plugin install wihtout any further modifications.

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

2 participants