Skip to content

Commit 1a9ecc2

Browse files
authored
Merge pull request #711 from thelullabyy/fix/71693/patch-onyx
fix: onyx snapshot cache & status
2 parents 6f35534 + 9257efc commit 1a9ecc2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/useOnyx.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,24 +307,26 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
307307
previousValueRef.current = newValueRef.current;
308308

309309
// If the new value is `null` we default it to `undefined` to ensure the consumer gets a consistent result from the hook.
310-
const newStatus = newFetchStatus ?? 'loaded';
310+
newFetchStatus = newFetchStatus ?? 'loaded';
311311
resultRef.current = [
312312
previousValueRef.current ?? undefined,
313313
{
314-
status: newStatus,
314+
status: newFetchStatus,
315315
sourceValue: sourceValueRef.current,
316316
},
317317
];
318318

319319
// If `canBeMissing` is set to `false` and the Onyx value of that key is not defined,
320320
// we log an alert so it can be acknowledged by the consumer. Additionally, we won't log alerts
321321
// if there's a `Onyx.clear()` task in progress.
322-
if (options?.canBeMissing === false && newStatus === 'loaded' && !isOnyxValueDefined && !OnyxCache.hasPendingTask(TASK.CLEAR)) {
322+
if (options?.canBeMissing === false && newFetchStatus === 'loaded' && !isOnyxValueDefined && !OnyxCache.hasPendingTask(TASK.CLEAR)) {
323323
Logger.logAlert(`useOnyx returned no data for key with canBeMissing set to false for key ${key}`, {showAlert: true});
324324
}
325325
}
326326

327-
onyxSnapshotCache.setCachedResult<UseOnyxResult<TReturnValue>>(key, cacheKey, resultRef.current);
327+
if (newFetchStatus !== 'loading') {
328+
onyxSnapshotCache.setCachedResult<UseOnyxResult<TReturnValue>>(key, cacheKey, resultRef.current);
329+
}
328330

329331
return resultRef.current;
330332
}, [options?.initWithStoredValues, options?.allowStaleData, options?.canBeMissing, key, memoizedSelector, cacheKey]);

0 commit comments

Comments
 (0)