react-native-onyx 3.0.97 → 3.0.99

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/Onyx.js CHANGED
@@ -240,11 +240,15 @@ function merge(key, changes) {
240
240
  return mergeQueuePromise[key];
241
241
  }
242
242
  mergeQueue[key] = [changes];
243
- mergeQueuePromise[key] = OnyxUtils_1.default.get(key).then((existingValue) => {
243
+ mergeQueuePromise[key] = OnyxUtils_1.default.get(key).then((valueFromGet) => {
244
244
  // Calls to Onyx.set after a merge will terminate the current merge process and clear the merge queue
245
245
  if (mergeQueue[key] == null) {
246
246
  return Promise.resolve();
247
247
  }
248
+ // Other writers (notably Onyx.update's mergeCollection path, which doesn't participate in mergeQueue)
249
+ // can land between get() resolving and this callback running. Applying the delta on top of the value
250
+ // captured back then and broadcasting it would overwrite those writes wholesale, so re-read the cache.
251
+ const existingValue = OnyxCache_1.default.hasCacheForKey(key) ? OnyxCache_1.default.get(key) : valueFromGet;
248
252
  try {
249
253
  const validChanges = mergeQueue[key].filter((change) => {
250
254
  const { isCompatible, existingValueType, newValueType, isEmptyArrayCoercion } = utils_1.default.checkCompatibilityWithExistingValue(change, existingValue);
package/dist/useOnyx.js CHANGED
@@ -99,6 +99,12 @@ function useOnyx(key, options) {
99
99
  if (!shouldGetCachedValueRef.current) {
100
100
  const cachedResult = OnyxSnapshotCache_1.default.getCachedResult(key, cacheKey);
101
101
  if (cachedResult !== undefined) {
102
+ // The slot is shared by all subscribers of the same (key, selector) pair, so it can hold a content-equal
103
+ // result computed by another subscriber. Keep our own result then, otherwise we would needlessly change
104
+ // this hook's result identity and re-render its consumer.
105
+ if (cachedResult !== resultRef.current && (0, memoizedShallowEqual_1.default)(cachedResult[0], resultRef.current[0]) && cachedResult[1].status === resultRef.current[1].status) {
106
+ return resultRef.current;
107
+ }
102
108
  resultRef.current = cachedResult;
103
109
  return cachedResult;
104
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "3.0.97",
3
+ "version": "3.0.99",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",