robinvdvleuten / vuex-persistedstate

💾 Persist and rehydrate your Vuex state between page reloads.
https://npm.im/vuex-persistedstate
MIT License
5.77k stars 378 forks source link

vuex-persistedstate does not follow vuex plugin guidelines #436

Open jaitaiwan opened 2 years ago

jaitaiwan commented 2 years ago

Refer to https://github.com/vuejs/vuex/issues/2046#issuecomment-879155842

Effectively vuex-persistedstate modify's the store state within it's constructor and doesn't emit any mutations to the store thereby breaking the initial state.

As far as I can tell, the plugin will need a significant re-write to support this.

robinvdvleuten commented 2 years ago

@jaitaiwan thanks for notifying about this. I don't see any "official" guidelines, so could you maybe give a summary on how the plugin needs to be rewritten?

jaitaiwan commented 2 years ago

Sorry, I should have linked it @robinvdvleuten, my bad.

According to https://vuex.vuejs.org/guide/plugins.html#committing-mutations-inside-plugins plugins should not directly mutate state at all but rather should rely on mutations. From what I could tell of the plugin it's missing any concept of a mutation and emitting changes to the store (I did find it difficult to tell what branches have active development, but after checking 3 of them that was my conclusion).

I've just opened up a new PR to vuex-persist to fix some of their issue with vuex 4; but theirs is because of the use of Vue.set. They already have documentation around enabling "strict mode" and adding a mutation from the plugin.

Does that help at all? I haven't had much more time to delve into vuex-persistedstate beyond my initial comments above and in the vuex ticket.