Repository navigation
Description
Proposal: Defer some non-critical Onyx subscriptions to after the splash screen hides
Background
The Expensify app uses Onyx, a custom key-value persistence layer built for offline-first functionality. When the app launches, Onyx reads data and delivers it to subscribers. The splash screen is shown during this initialization period and hides only when three conditions are satisfied: the navigation tree is ready, a public room check has completed, and the preferred locale has loaded from storage. Expensify.tsx is the root component of the application — the moment it is imported by the module system, every file it statically imports is also evaluated, including files whose sole purpose is to register Onyx collection subscriptions.
Problem
When the app starts cold, if Onyx processes non-critical full-collection subscriptions alongside the reads that gate the splash screen, the splash takes longer to hide than the critical path alone would require.
Four modules — UnreadIndicatorUpdater, replaceOptimisticReportWithActualReport, registerPaginationConfig, and subscribeToPushNotifications — immediately register 13 Onyx subscriptions at module load time, including full COLLECTION.REPORT, COLLECTION.REPORT_ACTIONS, COLLECTION.REPORT_NAME_VALUE_PAIRS, and COLLECTION.REPORT_ACTIONS_PAGES reads with waitForCollectionCallback: true, that compete with the critical-path reads gating the splash screen.
Solution
- Remove the static imports of these four modules from
Expensify.tsx - Add a
useEffecttoSplashScreenStateContextthat dynamically imports those modules.useEffectis appropriate precisely because this is a side-effect of the state transition.
diff --git a/src/SplashScreenStateContext.tsx b/src/SplashScreenStateContext.tsx
index 39b8db625b6..3be02c7f7fa 100644
--- a/src/SplashScreenStateContext.tsx
+++ b/src/SplashScreenStateContext.tsx
@@ -1,4 +1,4 @@
-import React, {useContext, useState} from 'react';
+import React, {useContext, useEffect, useState} from 'react';
import type {ValueOf} from 'type-fest';
import CONST from './CONST';
import type ChildrenProps from './types/utils/ChildrenProps';
@@ -21,15 +21,26 @@ const SplashScreenActionsContext = React.createContext<SplashScreenActionsContex
setSplashScreenState: () => {},
});
+function loadPostSplashScreenModules() {
+ import('./libs/actions/replaceOptimisticReportWithActualReport');
+ import('./libs/Notification/PushNotification/subscribeToPushNotifications');
+ import('./libs/registerPaginationConfig');
+ import('./libs/UnreadIndicatorUpdater');
+}
+
function SplashScreenStateContextProvider({children}: ChildrenProps) {
const [splashScreenState, setSplashScreenState] = useState<SplashScreenState>(CONST.BOOT_SPLASH_STATE.VISIBLE);
- // Because of the React Compiler we don't need to memoize it manually
- // eslint-disable-next-line react/jsx-no-constructed-context-values
- const stateValue = {splashScreenState};
+ // Load post-splash-screen modules when the splash screen is hidden
+ useEffect(() => {
+ if (splashScreenState !== CONST.BOOT_SPLASH_STATE.HIDDEN) {
+ return;
+ }
+ loadPostSplashScreenModules();
+ }, [splashScreenState]);
- // Because of the React Compiler we don't need to memoize it manually
- // eslint-disable-next-line react/jsx-no-constructed-context-values
+ // Because of the React Compiler we don't need to memoize these context values manually
+ const stateValue = {splashScreenState};
const actionsValue = {setSplashScreenState};
return (This is safe because all collection subscriptions in these modules use waitForCollectionCallback: true, meaning Onyx delivers a complete snapshot of all currently stored data as the first callback when they subscribe — no incremental updates are missed regardless of when the modules load. The unread badge count (UnreadIndicatorUpdater) and pagination config (registerPaginationConfig) are invisible and unused while the splash is showing. The optimistic report replacement logic only activates on an API response containing a preexistingReportID, which cannot arrive before the splash hides on a cold start. Push notification handlers (subscribeToPushNotifications) use Navigation.waitForProtectedRoutes() internally, so they are already gated on navigation readiness. The deferral is driven entirely by the render tree — no callbacks or requestAnimationFrame wrappers are needed.
Issue Owner
Current Issue Owner: @elirangoshenUpwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022031072748505234230
- Upwork Job ID: 2031072748505234230
- Last Price Increase: 2026-03-09
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
melvin-bot commentedon Mar 9, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @jayeshmangwani (
External)[-]Defer some non-critical Onyx subscriptions to after the splash screen hides[/-][+][$250] Defer some non-critical Onyx subscriptions to after the splash screen hides[/+]melvin-bot commentedon Mar 9, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022031072748505234230
melvin-bot commentedon Mar 9, 2026
Triggered auto assignment to @kadiealexander (
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.MelvinBot commentedon Mar 9, 2026
5 remaining items
PiyushChandra17 commentedon Mar 9, 2026
@roryabraham I am really sorry on this, i'll keep this in my mind for future and make sure will never repeat the same mistake again ..
elirangoshen commentedon Mar 10, 2026
Update: I addressed comments on the pr and waiting for feedback.
Julesssss commentedon Mar 10, 2026
PR looking good, remaining comment from me is just to share some before/after metrics.
elirangoshen commentedon Mar 11, 2026
Update: I addressed the comment in the pr, and also implemented another improvement suggested by @roryabraham . Waiting for feedback
elirangoshen commentedon Mar 12, 2026
Update:my pr has been merged
melvin-bot commentedon Mar 17, 2026
@elirangoshen Eep! 4 days overdue now. Issues have feelings too...
elirangoshen commentedon Mar 17, 2026
Its already merged, we should close it ?
elirangoshen commentedon Mar 18, 2026
would be good to close it or to move it to weekly as pr has been merged already
Julesssss commentedon Mar 19, 2026
Thanks, yep closing