react-native-onyx 3.0.80 → 3.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/OnyxUtils.js +21 -9
  2. package/package.json +1 -1
package/dist/OnyxUtils.js CHANGED
@@ -279,9 +279,10 @@ function multiGet(keys) {
279
279
  }
280
280
  continue;
281
281
  }
282
- const cacheValue = OnyxCache_1.default.get(key);
283
- if (cacheValue) {
284
- dataMap.set(key, cacheValue);
282
+ // hasCacheForKey catches cached falsy values (0, '', false, null) as cache hits, which
283
+ // a truthy check on the value would miss.
284
+ if (OnyxCache_1.default.hasCacheForKey(key)) {
285
+ dataMap.set(key, OnyxCache_1.default.get(key));
285
286
  continue;
286
287
  }
287
288
  const pendingKey = `${OnyxCache_1.TASK.GET}:${key}`;
@@ -328,6 +329,12 @@ function multiGet(keys) {
328
329
  // The key is not a collection one or something went wrong during split, so we proceed with the function's logic.
329
330
  }
330
331
  }
332
+ // Prefer cache over stale storage if a concurrent write populated it during
333
+ // the read — otherwise cache.merge(temp) below would resurrect dropped fields.
334
+ if (OnyxCache_1.default.hasCacheForKey(key)) {
335
+ dataMap.set(key, OnyxCache_1.default.get(key));
336
+ continue;
337
+ }
331
338
  dataMap.set(key, value);
332
339
  temp[key] = value;
333
340
  }
@@ -1338,12 +1345,17 @@ function mergeCollectionWithPatches({ collectionKey, collection, mergeReplaceNul
1338
1345
  const keyValuePairsForNewCollection = prepareKeyValuePairsForStorage(newCollection, true);
1339
1346
  // finalMergedCollection contains all the keys that were merged, without the keys of incompatible updates
1340
1347
  const finalMergedCollection = Object.assign(Object.assign({}, existingKeyCollection), newCollection);
1341
- // Pre-warm cache for any existing storage keys that aren't yet in cache. get() is a no-op
1342
- // (sync-resolved) for cache hits, and on a cache miss it reads from storage and writes the
1343
- // value back to cache. This is required so the subsequent cache.merge() merges the new delta
1344
- // into the real previous storage value (rather than starting from `undefined` and dropping
1345
- // the existing keys).
1346
- return Promise.all(existingKeys.map((key) => get(key))).then(() => {
1348
+ // Pre-warm cache for cache-miss existingKeys so cache.merge() merges the new delta into
1349
+ // the real previous storage value. Fast path (all warm) skips the pre-warm to preserve
1350
+ // promise-chain depth; slow path batches the misses into one Storage.multiGet.
1351
+ const hasColdExistingKey = existingKeys.some((key) => !OnyxCache_1.default.hasCacheForKey(key));
1352
+ // Swallow pre-warm read failures so a transient Storage.multiGet rejection doesn't
1353
+ // skip the cache.merge() + keysChanged() below. Subscribers still see the merge even
1354
+ // when storage reads fail.
1355
+ const prewarmPromise = hasColdExistingKey
1356
+ ? multiGet(existingKeys).catch((err) => Logger.logInfo(`mergeCollectionWithPatches pre-warm failed; proceeding with cache-only merge. Error: ${err}`))
1357
+ : Promise.resolve();
1358
+ return prewarmPromise.then(() => {
1347
1359
  // Snapshot previous values from the (now-warm) cache for keysChanged's diff, then update
1348
1360
  // cache and notify subscribers synchronously BEFORE issuing storage writes. This matches
1349
1361
  // the cache-first / storage-second invariant followed by every other Onyx write method
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "3.0.80",
3
+ "version": "3.0.81",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",