react-native-onyx 3.0.67 → 3.0.69

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.
@@ -135,7 +135,7 @@ declare function getCollectionDataAndSendAsObject<TKey extends OnyxKey>(matching
135
135
  * Remove a key from Onyx and update the subscribers
136
136
  */
137
137
  declare function remove<TKey extends OnyxKey>(key: TKey, isProcessingCollectionUpdate?: boolean): Promise<void>;
138
- declare function reportStorageQuota(): Promise<void>;
138
+ declare function reportStorageQuota(error?: Error): Promise<void>;
139
139
  /**
140
140
  * Handles storage operation failures based on the error type:
141
141
  * - Storage capacity errors: evicts data and retries the operation
package/dist/OnyxUtils.js CHANGED
@@ -231,6 +231,11 @@ function get(key) {
231
231
  // The key is not a collection one or something went wrong during split, so we proceed with the function's logic.
232
232
  }
233
233
  }
234
+ // Prefer cache over stale storage if a concurrent write populated it during the read.
235
+ const cachedValue = OnyxCache_1.default.get(key);
236
+ if (cachedValue !== undefined) {
237
+ return cachedValue;
238
+ }
234
239
  if (val === undefined) {
235
240
  OnyxCache_1.default.addNullishStorageKey(key);
236
241
  return undefined;
@@ -633,13 +638,13 @@ function remove(key, isProcessingCollectionUpdate) {
633
638
  }
634
639
  return storage_1.default.removeItem(key).then(() => undefined);
635
640
  }
636
- function reportStorageQuota() {
641
+ function reportStorageQuota(error) {
637
642
  return storage_1.default.getDatabaseSize()
638
643
  .then(({ bytesUsed, bytesRemaining }) => {
639
- Logger.logInfo(`Storage Quota Check -- bytesUsed: ${bytesUsed} bytesRemaining: ${bytesRemaining}`);
644
+ Logger.logInfo(`Storage Quota Check -- bytesUsed: ${bytesUsed} bytesRemaining: ${bytesRemaining}. Original error: ${error}`);
640
645
  })
641
646
  .catch((dbSizeError) => {
642
- Logger.logAlert(`Unable to get database size. Error: ${dbSizeError}`);
647
+ Logger.logAlert(`Unable to get database size. getDatabaseSize error: ${dbSizeError}. Original error: ${error}`);
643
648
  });
644
649
  }
645
650
  /**
@@ -654,7 +659,7 @@ function retryOperation(error, onyxMethod, defaultParams, retryAttempt) {
654
659
  const nextRetryAttempt = currentRetryAttempt + 1;
655
660
  Logger.logInfo(`Failed to save to storage. Error: ${error}. onyxMethod: ${onyxMethod.name}. retryAttempt: ${currentRetryAttempt}/${MAX_STORAGE_OPERATION_RETRY_ATTEMPTS}`);
656
661
  if (error && Str.startsWith(error.message, "Failed to execute 'put' on 'IDBObjectStore'")) {
657
- Logger.logAlert('Attempted to set invalid data set in Onyx. Please ensure all data is serializable.');
662
+ Logger.logAlert(`Attempted to set invalid data set in Onyx. Please ensure all data is serializable. Error: ${error}`);
658
663
  throw error;
659
664
  }
660
665
  const errorMessage = (_b = (_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.toLowerCase) === null || _b === void 0 ? void 0 : _b.call(_a);
@@ -674,12 +679,12 @@ function retryOperation(error, onyxMethod, defaultParams, retryAttempt) {
674
679
  // If we have no acceptable keys to remove then we are possibly trying to save mission critical data. If this is the case,
675
680
  // then we should stop retrying as there is not much the user can do to fix this. Instead of getting them stuck in an infinite loop we
676
681
  // will allow this write to be skipped.
677
- Logger.logAlert('Out of storage. But found no acceptable keys to remove.');
678
- return reportStorageQuota();
682
+ Logger.logAlert(`Out of storage. But found no acceptable keys to remove. Error: ${error}`);
683
+ return reportStorageQuota(error);
679
684
  }
680
685
  // Remove the least recently accessed key and retry.
681
- Logger.logInfo(`Out of storage. Evicting least recently accessed key (${keyForRemoval}) and retrying.`);
682
- reportStorageQuota();
686
+ Logger.logInfo(`Out of storage. Evicting least recently accessed key (${keyForRemoval}) and retrying. Error: ${error}`);
687
+ reportStorageQuota(error);
683
688
  // @ts-expect-error No overload matches this call.
684
689
  return remove(keyForRemoval).then(() => onyxMethod(defaultParams, nextRetryAttempt));
685
690
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "3.0.67",
3
+ "version": "3.0.69",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",