Skip to content

[$250] Defer some non-critical Onyx subscriptions to after the splash screen hides #84624

Closed

Description

@roryabraham

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

  1. Remove the static imports of these four modules from Expensify.tsx
  2. Add a useEffect to SplashScreenStateContext that dynamically imports those modules. useEffect is 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 OwnerCurrent Issue Owner: @elirangoshen
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022031072748505234230
  • Upwork Job ID: 2031072748505234230
  • Last Price Increase: 2026-03-09

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Mar 9, 2026
  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 9, 2026
  3. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Mar 9, 2026
  4. melvin-bot commented on Mar 9, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @jayeshmangwani (External)

  5. changed the title [-]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[/+] on Mar 9, 2026
  6. melvin-bot commented on Mar 9, 2026

    @melvin-bot
  7. melvin-bot commented on Mar 9, 2026

    @melvin-bot

    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.

  8. MelvinBot commented on Mar 9, 2026

    @MelvinBot
  9. 5 remaining items

  10. removed
    Help WantedApply this label when an issue is open to proposals by contributors
    on Mar 9, 2026
  11. PiyushChandra17 commented on Mar 9, 2026

    @PiyushChandra17
    Contributor

    @PiyushChandra17 do not try to defy Proposal Police without a clear explanation for how you think it was wrong and your proposal was materially different from others.

    @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 ..

  12. elirangoshen commented on Mar 10, 2026

    @elirangoshen
    Contributor

    Update: I addressed comments on the pr and waiting for feedback.

  13. Julesssss commented on Mar 10, 2026

    @Julesssss
    Contributor

    PR looking good, remaining comment from me is just to share some before/after metrics.

  14. elirangoshen commented on Mar 11, 2026

    @elirangoshen
    Contributor

    Update: I addressed the comment in the pr, and also implemented another improvement suggested by @roryabraham . Waiting for feedback

  15. elirangoshen commented on Mar 12, 2026

    @elirangoshen
    Contributor

    Update:my pr has been merged

  16. melvin-bot commented on Mar 17, 2026

    @melvin-bot

    @elirangoshen Eep! 4 days overdue now. Issues have feelings too...

  17. elirangoshen commented on Mar 17, 2026

    @elirangoshen
    Contributor

    Its already merged, we should close it ?

  18. elirangoshen commented on Mar 18, 2026

    @elirangoshen
    Contributor

    would be good to close it or to move it to weekly as pr has been merged already

  19. Julesssss commented on Mar 19, 2026

    @Julesssss
    Contributor

    Thanks, yep closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions