quarrant / mobx-persist-store

Persist and rehydrate observable properties in mobx store.
268 stars 14 forks source link

StorageController setItem is called even if data hasn't changed #115

Open lionelhorn opened 7 months ago

lionelhorn commented 7 months ago

Hello,

I'm trying to use mobx-persist-store with a another backing storage than localStorage.

While building a POC for my idea (https://github.com/lionelhorn/vlcn-mobx-persist), using the demo your provided, I've seen that setItem is called on page load (even without data changes).

I added a proxy to localStorage to be able to see calls.

image

Repro : https://codesandbox.io/p/sandbox/mobx-persist-store-version-1-forked-nv42gh?file=%2Fsrc%2Fstores%2FUser.store.ts%3A26%2C3

Steps

  1. Open page.
  2. Open devtools
  3. Click "Load random user"
  4. Reload page and inspect console logs.

setItem is called even if there was not any changes since page was just reloaded.