Skip to content

[Due for payment 2025-12-26] [$250] The 'navigation' object hasn't been initialized yet" console error #76536

Closed

Description

@m-natarajan

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.2.67-4
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @QichenZhu
Slack conversation (hyperlinked to channel name): #Expensify Bugs

Action Performed:

  1. Navigate to https://staging.new.expensify.com/
  2. Login with valid credentials and observe console log

Expected Result:

No error in console during signin

Actual Result:

The 'navigation' object hasn't been initialized yet" console error displayed

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop
Platforms Tested: On which of our officially supported platforms was this issue tested:
  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Image Image

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021997004322612288913
  • Upwork Job ID: 1997004322612288913
  • Last Price Increase: 2025-12-05
  • Automatic offers:
    • thelullabyy | Contributor | 109826079
Issue OwnerCurrent Issue Owner: @dylanexpensify

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Dec 2, 2025
  2. melvin-bot commented on Dec 2, 2025

    @melvin-bot

    Triggered auto assignment to @dylanexpensify (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.

  3. thelullabyy commented on Dec 2, 2025

    @thelullabyy
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    The 'navigation' object hasn't been initialized yet" console error displayed

    What is the root cause of that problem?

    We don't check if navigationRef is ready or not before calling it

    function getVisibleWideRHPKeys(allWideRHPKeys: string[]) {

    So it throws err when trying to access
    Image

    What changes do you think we should make in order to solve the problem?

    We should safe handling when navigation is not yet initialized first here

        if (!navigationRef.isReady()) {
            return [];
        }

    Could do similar these places (and other places use navigation) as well

    export default function isRoutePreloaded(routeName: keyof AuthScreensParamList) {

    function getActiveRoute(): string {

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  4. abbasifaizan70 commented on Dec 2, 2025

    @abbasifaizan70
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    During sign-in, a console error appears: "The 'navigation' object hasn't been initialized yet". This error occurs when navigation functions try to access the navigation state before the NavigationContainer is ready.

    What is the root cause of that problem?

    Several Navigation functions in App/src/libs/Navigation/Navigation.ts access navigation state without checking if navigation is ready first. These functions call navigationRef.getState() or navigationRef.getRootState() during sign-in before the NavigationContainer has finished initializing.

    The affected functions are:

    • getTopmostReportId - calls navigationRef.getState() without checking readiness
    • getTopmostReportActionId - calls navigationRef.getState() without checking readiness
    • getActiveRoute - calls navigationRef.getRootState() without checking readiness
    • getReportRouteByID - calls navigationRef.getRootState() without checking readiness
    • isOnboardingFlow - calls navigationRef.getRootState() without checking readiness
    • isValidateLoginFlow - calls navigationRef.getRootState() without checking readiness
    • resetToHome - calls navigationRef.getRootState() without checking readiness
    • getVisibleWideRHPKeys in App/src/components/WideRHPContextProvider/getVisibleRHPRouteKeys.ts - calls navigationRef.getRootState() without checking readiness

    When these functions are called during the sign-in process or during component initialization (which happens early in the app lifecycle), the navigation ref may not be ready yet, causing React Navigation to throw the error.

    What changes do you think we should make in order to solve the problem?

    Add navigation readiness checks to all affected functions in App/src/libs/Navigation/Navigation.ts:

    1. getTopmostReportId and getTopmostReportActionId:

    // Before:
    const getTopmostReportId = (state = navigationRef.getState()) => getTopmostReportParams(state)?.reportID;
    const getTopmostReportActionId = (state = navigationRef.getState()) => getTopmostReportParams(state)?.reportActionID;
    
    // After:
    const getTopmostReportId = (state = navigationRef.isReady() ? navigationRef.getState() : undefined) => getTopmostReportParams(state)?.reportID;
    const getTopmostReportActionId = (state = navigationRef.isReady() ? navigationRef.getState() : undefined) => getTopmostReportParams(state)?.reportActionID;

    2. getActiveRoute:

    // Before:
    function getActiveRoute(): string {
        const currentRoute = navigationRef.current && navigationRef.current.getCurrentRoute();
        if (!currentRoute?.name) {
            return '';
        }
        const routeFromState = getPathFromState(navigationRef.getRootState(), linkingConfig.config);
        if (routeFromState) {
            return routeFromState;
        }
        return '';
    }
    
    // After:
    function getActiveRoute(): string {
        // Safe handling when navigation is not yet initialized
        if (!navigationRef.isReady()) {
            return '';
        }
        const currentRoute = navigationRef.current && navigationRef.current.getCurrentRoute();
        if (!currentRoute?.name) {
            return '';
        }
        const routeFromState = getPathFromState(navigationRef.getRootState(), linkingConfig.config);
        if (routeFromState) {
            return routeFromState;
        }
        return '';
    }

    3. getReportRouteByID:

    // Before:
    function getReportRouteByID(reportID?: string, routes: NavigationRoute[] = navigationRef.getRootState().routes): NavigationRoute | null {
        if (!reportID || !routes?.length) {
            return null;
        }
        // ... rest of function
    }
    
    // After:
    function getReportRouteByID(reportID?: string, routes?: NavigationRoute[]): NavigationRoute | null {
        // Safe handling when navigation is not yet initialized
        if (!navigationRef.isReady()) {
            return null;
        }
        const routesToSearch = routes ?? navigationRef.getRootState().routes;
        if (!reportID || !routesToSearch?.length) {
            return null;
        }
        // ... rest of function
    }

    4. isOnboardingFlow:

    // Before:
    function isOnboardingFlow() {
        const state = navigationRef.getRootState();
        const currentFocusedRoute = findFocusedRoute(state);
        return isOnboardingFlowName(currentFocusedRoute?.name);
    }
    
    // After:
    function isOnboardingFlow() {
        // Safe handling when navigation is not yet initialized
        if (!navigationRef.isReady()) {
            return false;
        }
        const state = navigationRef.getRootState();
        const currentFocusedRoute = findFocusedRoute(state);
        return isOnboardingFlowName(currentFocusedRoute?.name);
    }

    5. isValidateLoginFlow:

    // Before:
    function isValidateLoginFlow() {
        const state = navigationRef.getRootState();
        const currentFocusedRoute = findFocusedRoute(state);
        return currentFocusedRoute?.name === SCREENS.VALIDATE_LOGIN;
    }
    
    // After:
    function isValidateLoginFlow() {
        // Safe handling when navigation is not yet initialized
        if (!navigationRef.isReady()) {
            return false;
        }
        const state = navigationRef.getRootState();
        const currentFocusedRoute = findFocusedRoute(state);
        return currentFocusedRoute?.name === SCREENS.VALIDATE_LOGIN;
    }

    6. resetToHome:

    // Before:
    function resetToHome() {
        const isNarrowLayout = getIsNarrowLayout();
        const rootState = navigationRef.getRootState();
        // ... rest of function
    }
    
    // After:
    function resetToHome() {
        // Safe handling when navigation is not yet initialized
        if (!navigationRef.isReady()) {
            return;
        }
        const isNarrowLayout = getIsNarrowLayout();
        const rootState = navigationRef.getRootState();
        // ... rest of function
    }

    7. getVisibleWideRHPKeys:

    // Before:
    function getVisibleWideRHPKeys(allWideRHPKeys: string[]) {
        const rootState = navigationRef.getRootState();
        if (!rootState) {
            return [];
        }
        // ... rest of function
    }
    
    // After:
    function getVisibleWideRHPKeys(allWideRHPKeys: string[]) {
        // Safe handling when navigation is not yet initialized
        if (!navigationRef.isReady()) {
            return [];
        }
        const rootState = navigationRef.getRootState();
        if (!rootState) {
            return [];
        }
        // ... rest of function
    }

    This pattern already exists in the codebase - getReportRHPActiveRoute function demonstrates the correct approach with a readiness check and safe return value.

    What alternative solutions did you explore? (Optional)

    None

    Demo

    This error is no longer visible.
    Image

  5. PiyushChandra17 commented on Dec 3, 2025

    @PiyushChandra17
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    There's a console error "Navigation object hasn't been initialized yet"

    What is the root cause of that problem?

    The console error comes from React Navigation, when we call navigationRef.getRootState() before React Navigation has mounted here

    What changes do you think we should make in order to solve the problem?

    We need to add a check navigationRef.isReady() before Navigating

    function getVisibleWideRHPKeys(allWideRHPKeys: string[]) {
        if (!navigationRef.isReady()) {
            return [];
        }
        const rootState = navigationRef.getRootState();
    
        if (!rootState) {
            return [];
        }

    What alternative solutions did you explore? (Optional)

    Or we can replace the direct call with a safe check so the function returns early when Navigation is not ready

    // before
    const rootState = navigationRef.getRootState();
    
    // after
    const rootState = navigationRef.current?.getRootState?.();
    if (!rootState) {
      return [];
    }

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  6. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Dec 5, 2025
  7. changed the title [-]The 'navigation' object hasn't been initialized yet" console error[/-] [+][$250] The 'navigation' object hasn't been initialized yet" console error[/+] on Dec 5, 2025
  8. melvin-bot commented on Dec 5, 2025

    @melvin-bot
  9. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Dec 5, 2025
  10. melvin-bot commented on Dec 5, 2025

    @melvin-bot

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

  11. 22 remaining items

  12. melvin-bot commented on Dec 19, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.2.84-8 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-12-26. 🎊

    For reference, here are some details about the assignees on this issue:

  13. melvin-bot commented on Dec 19, 2025

    @melvin-bot

    @hungvu193 @dylanexpensify 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]

  14. mvtglobally commented on Dec 20, 2025

    @mvtglobally

    Issue not reproducible during KI retests. (First week)

  15. hungvu193 commented on Dec 29, 2025

    @hungvu193
    Contributor

    BugZero Checklist:

    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: https://github.com/Expensify/App/pull/76163/changes#r2650135674

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: N/A

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Test:

    1. Login with any account.
    2. Verify that there's no error console The 'navigation' object hasn't been initialized yet"

    Do we agree 👍 or 👎

  16. melvin-bot commented on Dec 31, 2025

    @melvin-bot

    @dylanexpensify Huh... This is 4 days overdue. Who can take care of this?

  17. melvin-bot commented on Jan 2, 2026

    @melvin-bot

    @dylanexpensify Still overdue 6 days?! Let's take care of this!

  18. dylanexpensify commented on Jan 5, 2026

    @dylanexpensify
    Contributor

    Payment summary:

    Contributor: @thelullabyy $250 via Upwork
    Contributor+: @hungvu193 $250 via NewDot

    Please apply/request!

  19. twisterdotcom commented on Jan 7, 2026

    @twisterdotcom
    Contributor

    @hungvu193 has submitted payment for this report on ND here.

    SO: https://stackoverflowteams.com/c/expensify/questions/7582

    Zapier Logs Run ID: 00040eee-2001-a9d0-9e36-c8e78537d684
  20. QichenZhu commented on Oct 21, 2026

    @QichenZhu
    Contributor

    Can we reopen this issue? It happens every time I open the Android and iOS apps.

    Simulator.Screen.Recording.-.iPhone.17.-.2026-10-21.at.14.42.34.mov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

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

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions