You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2025-09-04] [$250] [Onyx] Fix infinite loading issue for empty collections in useOnyx #68136
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
The useOnyx hook is experiencing an infinite loading state when subscribing to collection keys that don't exist in storage.
Solution
Remove conditional check from subscribeToKey that prevents collections to be treated equally as other keys in terms of empty state identification (nullishStorageKeys). (source)
The problem stemmed from the subscribeToKey function in OnyxUtils.ts. When a connection is made to a key that doesn't exist in storage (returns no matching keys), the system was supposed to:
Add the key to the nullish storage keys set via cache.addNullishStorageKey(mapping.key)
Send a null value to the connection to indicate no data exists
Allow useOnyx to transition from loading to loaded state
However, the original code had a conditional check that prevented collection keys from being added to the nullish storage keys set:
if(matchingKeys.length===0){if(mapping.key&&!isCollectionKey(mapping.key)){// ❌ This condition excluded collectionscache.addNullishStorageKey(mapping.key);}// ...}
The useOnyx hook determines fetchStatus based on several factors, including whether there's cache available for a key:
When useOnyx subscribes to a non-existent collection key
subscribeToKey finds no matching keys (matchingKeys.length === 0)
Due to the conditional check, collection keys were NOT added to nullish storage keys
hasCacheForKey returns false for the collection key
useOnyx.getSnapshot() continues to return loading status indefinitely
The hook never transitions to loaded state, causing infinite loading
This fix resolves a critical UX issue where useOnyx would get stuck in an infinite loading state for non-existent collections. The solution is minimal, consistent, and aligns the behavior of collection keys with individual keys. The change ensures that all Onyx keys, regardless of type, can properly transition through the loading lifecycle, providing a better developer experience and preventing UI freezes in applications using collection subscriptions.
Now tests that were added to monitor this regression (source) are passing just fine.
Do we have an ability to re-run tests from E/App for changes in react-native-onyx in CI? I've noticed that there were couple of test suites which process was randomly terminated on my machine (dunno why) and I would like to be certain. Thanks!
We are going to run the App tests when bumping Onyx, but that's a little bit late in the development pipeline and was wondering if we could run them earlier.
When locally running App tests, we've got two tests failing in DateUtilsTest.ts and UnreadIndicatorsTest.tsx but Fabio said they are known to be flaky. Shall we proceed @mountiny?
changed the title [-][$250] [Onyx] Fix infinite loading issue for empty collections in useOnyx[/-][+][Due for payment 2025-09-04] [$250] [Onyx] Fix infinite loading issue for empty collections in useOnyx[/+]on Aug 28, 2025
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.99-11 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
@DylanDylann@Christinadobrzyn The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Activity
kacper-mikolajczak commentedon Aug 7, 2025
Explanation
The problem stemmed from the
subscribeToKeyfunction inOnyxUtils.ts. When a connection is made to a key that doesn't exist in storage (returns no matching keys), the system was supposed to:cache.addNullishStorageKey(mapping.key)nullvalue to the connection to indicate no data existsuseOnyxto transition fromloadingtoloadedstateHowever, the original code had a conditional check that prevented collection keys from being added to the nullish storage keys set:
The
useOnyxhook determines fetchStatus based on several factors, including whether there's cache available for a key:The
hasCacheForKeymethod returnstrueif either:useOnyxsubscribes to a non-existent collection keysubscribeToKeyfinds no matching keys (matchingKeys.length === 0)hasCacheForKeyreturnsfalsefor the collection keyuseOnyx.getSnapshot()continues to returnloadingstatus indefinitelyloadedstate, causing infinite loadingThis fix resolves a critical UX issue where
useOnyxwould get stuck in an infinite loading state for non-existent collections. The solution is minimal, consistent, and aligns the behavior of collection keys with individual keys. The change ensures that all Onyx keys, regardless of type, can properly transition through the loading lifecycle, providing a better developer experience and preventing UI freezes in applications using collection subscriptions.Now tests that were added to monitor this regression (source) are passing just fine.
fabioh8010 commentedon Aug 7, 2025
cc @mountiny
melvin-bot commentedon Aug 7, 2025
Triggered auto assignment to @Christinadobrzyn (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.kacper-mikolajczak commentedon Aug 7, 2025
Do we have an ability to re-run tests from E/App for changes in react-native-onyx in CI? I've noticed that there were couple of test suites which process was randomly terminated on my machine (dunno why) and I would like to be certain. Thanks!
kacper-mikolajczak commentedon Aug 8, 2025
We are going to run the App tests when bumping Onyx, but that's a little bit late in the development pipeline and was wondering if we could run them earlier.
kacper-mikolajczak commentedon Aug 11, 2025
When locally running App tests, we've got two tests failing in
DateUtilsTest.tsandUnreadIndicatorsTest.tsxbut Fabio said they are known to be flaky. Shall we proceed @mountiny?mountiny commentedon Aug 11, 2025
yeah thoe are sometimes flaky, I think we can proceed
30 remaining items
[-][$250] [Onyx] Fix infinite loading issue for empty collections in useOnyx[/-][+][Due for payment 2025-09-04] [$250] [Onyx] Fix infinite loading issue for empty collections in useOnyx[/+]melvin-bot commentedon Aug 28, 2025
Reviewinglabel has been removed, please complete the "BugZero Checklist".melvin-bot commentedon Aug 28, 2025
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.99-11 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
If no regressions arise, payment will be issued on 2025-09-04. 🎊
For reference, here are some details about the assignees on this issue:
melvin-bot commentedon Aug 28, 2025
@DylanDylann @Christinadobrzyn The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]
Christinadobrzyn commentedon Sep 4, 2025
Payment summary here - #68136 (comment)
@DylanDylann do we need a regression test?
DylanDylann commentedon Sep 4, 2025
I think no, the PR is to fix UTs only (see here)
melvin-bot commentedon Sep 4, 2025
Payment Summary
Upwork Job
BugZero Checklist (@Christinadobrzyn)
Christinadobrzyn commentedon Sep 5, 2025
Payment summary here - #68136 (comment)
@DylanDylann please make sure to request payment via ND. Closing, thanks everyone!
garrettmknight commentedon Oct 29, 2025
$250 approved for @DylanDylann