react-native-onyx 3.0.24 → 3.0.26

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/useOnyx.js +2 -11
  2. package/package.json +1 -1
package/dist/useOnyx.js CHANGED
@@ -86,7 +86,6 @@ function useOnyx(key, options, dependencies = []) {
86
86
  const previousValueRef = (0, react_1.useRef)(null);
87
87
  // Stores the newest cached value in order to compare with the previous one and optimize `getSnapshot()` execution.
88
88
  const newValueRef = (0, react_1.useRef)(null);
89
- const lastConnectedKeyRef = (0, react_1.useRef)(key);
90
89
  // Stores the previously result returned by the hook, containing the data from cache and the fetch status.
91
90
  // We initialize it to `undefined` and `loading` fetch status to simulate the initial result when the hook is loading from the cache.
92
91
  // However, if `initWithStoredValues` is `false` we set the fetch status to `loaded` since we want to signal that data is ready.
@@ -115,15 +114,6 @@ function useOnyx(key, options, dependencies = []) {
115
114
  canBeMissing: options === null || options === void 0 ? void 0 : options.canBeMissing,
116
115
  }), [options === null || options === void 0 ? void 0 : options.selector, options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.canBeMissing]);
117
116
  (0, react_1.useEffect)(() => () => OnyxSnapshotCache_1.default.deregisterConsumer(key, cacheKey), [key, cacheKey]);
118
- (0, react_1.useEffect)(() => {
119
- if (lastConnectedKeyRef.current === key) {
120
- return;
121
- }
122
- lastConnectedKeyRef.current = key;
123
- shouldGetCachedValueRef.current = true;
124
- previousValueRef.current = null;
125
- resultRef.current = [undefined, { status: (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false ? 'loaded' : 'loading' }];
126
- }, [key, options === null || options === void 0 ? void 0 : options.initWithStoredValues]);
127
117
  (0, react_1.useEffect)(() => {
128
118
  // These conditions will ensure we can only handle dynamic collection member keys from the same collection.
129
119
  if ((options === null || options === void 0 ? void 0 : options.allowDynamicKey) || previousKey === key) {
@@ -239,8 +229,9 @@ function useOnyx(key, options, dependencies = []) {
239
229
  // - The previously cached value is different from the new value.
240
230
  // - The previously cached value is `null` (not set from cache yet) and we have cache for this key
241
231
  // OR we have a pending `Onyx.clear()` task (if `Onyx.clear()` is running cache might not be available anymore
232
+ // OR the subscriber is triggered (the value is gotten from the storage)
242
233
  // so we update the cached value/result right away in order to prevent infinite loading state issues).
243
- const shouldUpdateResult = !areValuesEqual || (previousValueRef.current === null && (hasCacheForKey || OnyxCache_1.default.hasPendingTask(OnyxCache_1.TASK.CLEAR)));
234
+ const shouldUpdateResult = !areValuesEqual || (previousValueRef.current === null && (hasCacheForKey || OnyxCache_1.default.hasPendingTask(OnyxCache_1.TASK.CLEAR) || !isFirstConnectionRef.current));
244
235
  if (shouldUpdateResult) {
245
236
  previousValueRef.current = newValueRef.current;
246
237
  // If the new value is `null` we default it to `undefined` to ensure the consumer gets a consistent result from the hook.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "3.0.24",
3
+ "version": "3.0.26",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",