From c3cb9eba47350f476aa175e7a03fe58003e1885e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Henriques?= Date: Mon, 4 Aug 2025 18:16:46 +0100 Subject: [PATCH 1/3] Add unit test to cover the bug --- tests/unit/useOnyxTest.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unit/useOnyxTest.ts b/tests/unit/useOnyxTest.ts index d1ba29235..842b3c7f5 100644 --- a/tests/unit/useOnyxTest.ts +++ b/tests/unit/useOnyxTest.ts @@ -132,6 +132,30 @@ describe('useOnyx', () => { }); describe('misc', () => { + it('should initially return loading state while loading non-existent key, and then return `undefined` and loaded state', async () => { + const {result} = renderHook(() => useOnyx(ONYXKEYS.TEST_KEY)); + + expect(result.current[0]).toBeUndefined(); + expect(result.current[1].status).toEqual('loading'); + + await act(async () => waitForPromisesToResolve()); + + expect(result.current[0]).toBeUndefined(); + expect(result.current[1].status).toEqual('loaded'); + }); + + it('should initially return loading state while loading non-existent collection key, and then return `undefined` and loaded state', async () => { + const {result} = renderHook(() => useOnyx(ONYXKEYS.COLLECTION.TEST_KEY)); + + expect(result.current[0]).toBeUndefined(); + expect(result.current[1].status).toEqual('loading'); + + await act(async () => waitForPromisesToResolve()); + + expect(result.current[0]).toBeUndefined(); + expect(result.current[1].status).toEqual('loaded'); + }); + it('should return value and loaded state when loading cached key', async () => { Onyx.set(ONYXKEYS.TEST_KEY, 'test'); From 4124cf2d49ed4ea31c389441601afcfa9e9b36df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Wed, 6 Aug 2025 23:53:05 +0200 Subject: [PATCH 2/3] wip: OnyxUtils.subscribeToKey: remove collection check when adding nullish storage key --- lib/OnyxUtils.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/OnyxUtils.ts b/lib/OnyxUtils.ts index 0f93730a9..f8ae32313 100644 --- a/lib/OnyxUtils.ts +++ b/lib/OnyxUtils.ts @@ -1377,9 +1377,7 @@ function subscribeToKey(connectOptions: ConnectOptions Date: Tue, 12 Aug 2025 09:32:22 +0200 Subject: [PATCH 3/3] revert mapping.key check --- lib/OnyxUtils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/OnyxUtils.ts b/lib/OnyxUtils.ts index f8ae32313..7781f5633 100644 --- a/lib/OnyxUtils.ts +++ b/lib/OnyxUtils.ts @@ -1377,7 +1377,9 @@ function subscribeToKey(connectOptions: ConnectOptions