react-native-onyx icon indicating copy to clipboard operation
react-native-onyx copied to clipboard

`Onyx.clear()` will wipe `Onyx.set()` from `Storage`

Open marcaaron opened this issue 3 years ago • 0 comments

cc @neil-marcellini and coming from https://github.com/Expensify/react-native-onyx/pull/129#discussion_r883005645...

Unsure if there is any observable problem with this at the moment, but it just doesn't seem like the expected behavior.

This is how this code runs today...

const promises = [];
promises.push(Onyx.clear());
promises.push(Onyx.set('test', {someValue: 'test'});
Promise.all(promises)
    .then(() => {
        Storage.getItem('test').then((val) => console.log(val)) // null
    });

The cache values end up correct, but the storage values are not. The behavior is documented but we might want to fix it eventually.

One idea I had:

  • Set an internal flag that Onyx.clear() is still running and hasn't fully cleared storage.
  • While that happens batch any new writes to storage or flag which keys need to be saved after we are done, but allow cached values to be set, merged, whatever.
  • Once Storage.clear() is done we can sync up any queued "writes" with the values in the cache.

marcaaron avatar May 27 '22 01:05 marcaaron