@@ -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