gabrielmbmb / vuex-multi-tab-state

πŸ’ΎπŸ”—πŸ–₯️ Share, synchronize and persist state between multiple tabs with this plugin for Vuex. TypeScript types included.
MIT License
160 stars 17 forks source link

State is fully observed and deeply cloned instead of statePaths only #106

Open tspoke opened 1 year ago

tspoke commented 1 year ago

Hi,

The PR #64 introduced a bug. The full state is observed and is deeply cloned before the filtering of the statesPaths the next line. This lead to a full state copy instead of only the portions we need to sync.

You should only clone the wanted portion of the state :

    if (statesPaths.length === 0) return { ...newState };

    statesPaths.forEach((statePath) => {
      const newValue = cloneObj(pick(statePath, newState)); // clone only the wanted path
      ...

The faulty line is here : https://github.com/abernh/vuex-multi-tab-state/blob/3d0bc186db0741309f1e1a42fb26dad964f5f5b5/src/index.ts#L48

andreww2012 commented 1 year ago

This deep cloning algorithm is also causing issues for objects with Dates. That said, I'm not entirely sure whether it is a good practice/officially (not) recommended to store Dates in Vuex in the first place, but that caused crashes in production because Dates had been destroyed after the cloning.

Though I'm very grateful for that library, it was a real savior for me.