From cbcb573ce2ad74d632ae6d1148973af39715e585 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 29 Dec 2025 15:40:28 +0700 Subject: [PATCH 1/3] fix: result isn't changed when the member collection change v2 --- lib/useOnyx.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/useOnyx.ts b/lib/useOnyx.ts index 92fe448b..9da81201 100644 --- a/lib/useOnyx.ts +++ b/lib/useOnyx.ts @@ -264,10 +264,10 @@ function useOnyx>( return result; } - // We get the value from cache while the first connection to Onyx is being made, + // We get the value from cache while the first connection to Onyx is being made or the key has changed, // so we can return any cached value right away. After the connection is made, we only // update `newValueRef` when `Onyx.connect()` callback is fired. - if (isFirstConnectionRef.current || shouldGetCachedValueRef.current) { + if (isFirstConnectionRef.current || shouldGetCachedValueRef.current || key !== previousKey) { // Gets the value from cache and maps it with selector. It changes `null` to `undefined` for `useOnyx` compatibility. const value = OnyxUtils.tryGetCachedValue(key) as OnyxValue; const selectedValue = memoizedSelector ? memoizedSelector(value) : value; From dd4a41ce28fce168b77675c5b69ae48ba6e43ddc Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 7 Jan 2026 15:50:06 +0700 Subject: [PATCH 2/3] Update lib/useOnyx.ts Co-authored-by: Carlos Alvarez --- lib/useOnyx.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/useOnyx.ts b/lib/useOnyx.ts index 9da81201..b71f2e0d 100644 --- a/lib/useOnyx.ts +++ b/lib/useOnyx.ts @@ -264,7 +264,7 @@ function useOnyx>( return result; } - // We get the value from cache while the first connection to Onyx is being made or the key has changed, + // We get the value from cache while the first connection to Onyx is being made or if the key has changed, // so we can return any cached value right away. After the connection is made, we only // update `newValueRef` when `Onyx.connect()` callback is fired. if (isFirstConnectionRef.current || shouldGetCachedValueRef.current || key !== previousKey) { From 3dbffba0474304e1724f39a581916d79c81a5941 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 8 Jan 2026 23:34:10 +0700 Subject: [PATCH 3/3] update explain comment --- lib/useOnyx.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/useOnyx.ts b/lib/useOnyx.ts index b71f2e0d..56d5f19a 100644 --- a/lib/useOnyx.ts +++ b/lib/useOnyx.ts @@ -265,7 +265,7 @@ function useOnyx>( } // We get the value from cache while the first connection to Onyx is being made or if the key has changed, - // so we can return any cached value right away. After the connection is made, we only + // so we can return any cached value right away. For the case where the key has changed, If we don't return the cached value right away, then the UI will show the incorrect (previous) value for a brief period which looks like a UI glitch to the user. After the connection is made, we only // update `newValueRef` when `Onyx.connect()` callback is fired. if (isFirstConnectionRef.current || shouldGetCachedValueRef.current || key !== previousKey) { // Gets the value from cache and maps it with selector. It changes `null` to `undefined` for `useOnyx` compatibility.