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.
- package/dist/OnyxUtils.js +21 -9
- 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
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
|
1342
|
-
//
|
|
1343
|
-
//
|
|
1344
|
-
|
|
1345
|
-
//
|
|
1346
|
-
|
|
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
|