Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Dynamic module preserveState ignores the overwrite option #311

Open
zeroinformatique opened this issue Aug 20, 2020 · 0 comments
Open

Dynamic module preserveState ignores the overwrite option #311

zeroinformatique opened this issue Aug 20, 2020 · 0 comments

Comments

@zeroinformatique
Copy link

zeroinformatique commented Aug 20, 2020

  • vuex-persistedstate version: 3.1.0
  • node version: 12.18.1
  • npm version: 6.14.5
store.registerModule("myModule", extractVuexModule(MyModule).myModule, { preserveState: true });

I register a dynamic module with this command. When preserveState is false, the state is overwritten by the default store values (this is okay). When preserveState is true, the state is overwritten by the state persisted in the localStore. Since I use paths, the state is not complete; some keys in the state are now undefined.

My options when declaring createPersistedState says explicitly overwrite: false, so based on my understanding, it should deepMerge the localStore with the currently active state (which is the default values when registering the module) : but it doesn't.

Vue crashes because some keys are undefined. I had to create a new init() mutation to fix the store after the module creation:

  @mutation init() {
    if (!this.searchForm) this.searchForm = new SearchForm(); // This property is persisted
    this.loading = false;
    this.lines = [];
  }

Suggested solution: Perform a deepMerge instead of an overwrite when registering new modules dynamically with preserveState: true and overwrite: false

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

No branches or pull requests

1 participant