question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deepmerge breaks modules not related to persist

See original GitHub issue

After updating to vuex-persist 3.1.3 modules that are not related in any way to vuex-persist plugin are broken when they’re using classes as a part of state. Also i’m using vuex-module-decorators.

For example:

class Foo {
  a = 5;
  bar () {
    this.a = 6;
  }
}

@Module({ namespaced: true, name: 'foo' })
class FooModule extends VuexModule {
  foo = new Foo();

  @Mutation
  baz () {
    this.foo.bar();
  }
}

const persist = new VuexPersist({ 
  modules: ['other', 'some-other-module-2']
})

On the application start it throw an error that foo.bar() is not a function. It would make sense when the module would be loaded by vuex-persist but it it not so it should be not touched.

Everything worked fine when the backend besides merging was handled by lodash. Everything broke after moving to deepmerge.

What it the solution to this? Temporarily we’re using older version but that’s not a good option for a long time.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Magicznecommented, Mar 4, 2021

I have ended up writing this functionality on my own in the projects I’m using it with, caues it looks that library is somehow abandoned.

I also couldn’t find any reason besides #64 why lodash was replaced when it was working perfectly fine.

0reactions
nokazncommented, May 28, 2021

I have a similar issue. I created store including Map and Set value in state, but both are converted to empty objects.

import Vuex from 'vuex';
import VuexPersistence from 'vuex-persist';

const store = new Vuex.Store({
    state: {
        // Expected empty Map, but actually object
        map: new Map(),
        set: new Set(),
    },
});
const persist = new VuexPersistence({
    storage: window.localStorage,
    reducer: (state) => ({ map: state.map }),
}).plugin(store);

This is caused by the behavior of merging object by deepmerge, which replaced lodash.merge from 3.x.

I think another library like just-extend or something should be used. just-extend is a zero-dependency package, so its bundle size is tiny.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Deepmerge breaks modules not related to persist -
After updating to vuex-persist 3.1.3 modules that are not related in any way to vuex-persist plugin are broken when they're using classes as...
Read more >
Javascript deepmerge breaks objectid - node.js - Stack Overflow
I answered my own question, but I'm not sure it's the right answer. query = deepmerge(engageQuery, query, {clone: false});.
Read more >
Even more DRY and maintainable code with Terragrunt
Suppose you have a generic VPC module, and you want to always configure VPC flow logs. ... Using deep merge to DRY nested...
Read more >
deepmerge - npm
A library for deep (recursive) merging of Javascript objects. Latest version: 4.2.2, last published: 3 years ago. Start using deepmerge in ...
Read more >
vuex-persist | Yarn - Package Manager
A Typescript-ready Vuex plugin that enables you to save the state of your app ... BREAKING: replaced lodash.merge with deepmerge (this can cause...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found