From 181fb70294a04e8cafecb7e120a78454800dc6db Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Sat, 6 Dec 2025 21:44:26 +0700 Subject: [PATCH 1/3] fix: status is infinity loading for the none-exist key --- lib/useOnyx.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/useOnyx.ts b/lib/useOnyx.ts index f2aa7fa4..2a27a5d2 100644 --- a/lib/useOnyx.ts +++ b/lib/useOnyx.ts @@ -293,7 +293,7 @@ function useOnyx>( const normalizedNew = newValueRef.current ?? undefined; areValuesEqual = normalizedPrevious === normalizedNew; } else { - areValuesEqual = shallowEqual(previousValueRef.current ?? undefined, newValueRef.current); + areValuesEqual = shallowEqual(previousValueRef.current, newValueRef.current); } // We update the cached value and the result in the following conditions: From 512a3419a933f7084069deddf8dbaa62a604b66f Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Sat, 6 Dec 2025 21:56:19 +0700 Subject: [PATCH 2/3] update the correct approach --- lib/useOnyx.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/useOnyx.ts b/lib/useOnyx.ts index 2a27a5d2..1f1d4c54 100644 --- a/lib/useOnyx.ts +++ b/lib/useOnyx.ts @@ -293,7 +293,7 @@ function useOnyx>( const normalizedNew = newValueRef.current ?? undefined; areValuesEqual = normalizedPrevious === normalizedNew; } else { - areValuesEqual = shallowEqual(previousValueRef.current, newValueRef.current); + areValuesEqual = shallowEqual(previousValueRef.current ?? undefined, newValueRef.current); } // We update the cached value and the result in the following conditions: @@ -302,7 +302,10 @@ function useOnyx>( // - The previously cached value is `null` (not set from cache yet) and we have cache for this key // OR we have a pending `Onyx.clear()` task (if `Onyx.clear()` is running cache might not be available anymore // so we update the cached value/result right away in order to prevent infinite loading state issues). - const shouldUpdateResult = !areValuesEqual || (previousValueRef.current === null && (hasCacheForKey || OnyxCache.hasPendingTask(TASK.CLEAR))); + const shouldUpdateResult = + !areValuesEqual || + (previousValueRef.current === null && (hasCacheForKey || OnyxCache.hasPendingTask(TASK.CLEAR))) || + (previousValueRef.current === null && !isFirstConnectionRef.current); if (shouldUpdateResult) { previousValueRef.current = newValueRef.current; From 5f55dc30745b25355fe865ea0f01b75e06839f22 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 15 Dec 2025 15:14:20 +0700 Subject: [PATCH 3/3] update condition and comment --- lib/useOnyx.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/useOnyx.ts b/lib/useOnyx.ts index f2aa23ae..2b3e0171 100644 --- a/lib/useOnyx.ts +++ b/lib/useOnyx.ts @@ -313,11 +313,9 @@ function useOnyx>( // - The previously cached value is different from the new value. // - The previously cached value is `null` (not set from cache yet) and we have cache for this key // OR we have a pending `Onyx.clear()` task (if `Onyx.clear()` is running cache might not be available anymore + // OR the subscriber is triggered (the value is gotten from the storage) // so we update the cached value/result right away in order to prevent infinite loading state issues). - const shouldUpdateResult = - !areValuesEqual || - (previousValueRef.current === null && (hasCacheForKey || OnyxCache.hasPendingTask(TASK.CLEAR))) || - (previousValueRef.current === null && !isFirstConnectionRef.current); + const shouldUpdateResult = !areValuesEqual || (previousValueRef.current === null && (hasCacheForKey || OnyxCache.hasPendingTask(TASK.CLEAR) || !isFirstConnectionRef.current)); if (shouldUpdateResult) { previousValueRef.current = newValueRef.current;