Skip to content

[$175] Android – App crashes when opening a transaction from a report preview after restarting the app. #105394

Open

Description

@m-natarajan

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


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

Action Performed:

  1. Open the Android app.
  2. Navigate to a workspace chat containing a report with at least two transactions.
  3. Fully close the app.
  4. Reopen the app.
  5. Once the app has fully loaded, tap the report preview to open a transaction.

Expected Result:

The transaction report opens successfully.

Actual Result:

The app crashes.

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

Note:

crash occurs here:

if (contextMenuRef.current?.isContextMenuOpening) {
return;
}

if (contextMenuRef.current?.isContextMenuOpening) {
return;
}It looks like contextMenuRef.current changes from a value → null → a value during hydration, so it may become null after the null check.
When I capture the ref in a local variable instead, the crash disappears:
const contextMenu = contextMenuRef.current;
if (contextMenu?.isContextMenuOpening) {
return;
}

Screenshots/Videos

az_recorder_20261029_104447.mp4
android.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mkhutornyi

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 29, 2026
  2. MelvinBot commented on Oct 29, 2026

    @MelvinBot
    Contributor

    ⚠️ Preliminary analysis (low confidence) — treat as a starting point, not a conclusion.

    I think the crash happens on the screen the tap opens, not in the tap handler. After a restart, the expense report's IOU action isn't in Onyx yet. So openTransactionFromPreview does three things at once:

    1. Writes a bare-bones transaction thread with no parentReportActionID (resolveChildReportID).
    2. Calls openReport for the expense report.
    3. Pushes two screens in the same tick (navigateToExpense).

    The destination lists then mount and change type while data is still loading. On Android, a likely failure point is the native scroll manager. Its scrollToIndex has no range or layout guard (useReportScrollManager/index.native.ts:13-31).

    I wasn't able to verify this. The issue has no stack trace, and I can't run the Android app here. The tap path itself has no throw, non-null assertion, or unguarded scrollToIndex.

    To confirm, check:

    • The Android logcat or Sentry stack for this crash. It shows whether this is a JS fatal or a native crash (react-native-screens or FlashList).
    • Whether it still crashes if you open the expense report once before restarting. If it doesn't, the missing IOU action is the trigger.
    Recent PRs in this path (all in 9.5.24)

    Possibly related: Expense - Split preview loads infinitely and opens not here page after reset app. It also fails when opening from a preview after a reset.


    Next Steps: Reply with @MelvinBot <your feedback> to refine this analysis. A crash stack trace would help most.


    view run

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Oct 29, 2026
  4. melvin-bot commented on Oct 29, 2026

    @melvin-bot

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

  5. changed the title [-]Android – App crashes when opening a transaction from a report preview after restarting the app.[/-] [+][$175] Android – App crashes when opening a transaction from a report preview after restarting the app.[/+] on Oct 29, 2026
  6. melvin-bot commented on Oct 29, 2026

    @melvin-bot
  7. camesenin commented on Oct 29, 2026

    @camesenin
  8. melvin-bot commented on Oct 29, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  9. sonofkratos92 commented on Oct 29, 2026

    @sonofkratos92

    Proposal

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

    On Android, after force-closing and reopening the app in a workspace chat that contains an expense report with multiple transactions, tapping a transaction card inside the report preview crashes the app instead of opening the transaction thread report.

    What is the root cause of that problem?

    There are two parts to why this happens during cold-start hydration on Android:

    1. Why contextMenuRef.current repeatedly flips value -> null -> value during hydration:
      In src/GlobalModals.tsx:31-62, LazyPopoverReportActionContextMenu is mounted with ref={ReportActionContextMenu.contextMenuRef}. Inside src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx:64-105 and 348-388, PopoverReportActionContextMenu subscribes to several global Onyx collections (ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS, ONYXKEYS.BANK_ACCOUNT_LIST, ONYXKEYS.SELF_DM_REPORT_ID, etc.) and is skipped by React Compiler because it reads reportIDRef.current and reportActionRef.current during render.
      At src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx:500-512, useImperativeHandle(ref, () => ({ ... })) is called without a dependency array. In React's commit phase, whenever an effectful useImperativeHandle without stable dependencies re-runs on a render, React first detaches the ref in the mutation phase (safelyDetachRef sets contextMenuRef.current = null) before attaching the newly created handle object in the layout phase (commitAttachRef). Because cold-start hydration after an app restart triggers a stream of Onyx updates across those global subscriptions, contextMenuRef.current repeatedly cycles value -> null -> value.

    2. Why MoneyRequestReportPreview crashes on press:
      In src/pages/inbox/report/ContextMenu/ReportActionContextMenu.ts, all other consumers interact with contextMenuRef through helper functions, whereas src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx directly accesses contextMenuRef.current?.isContextMenuOpening in openReportFromPreview (line 174) and openTransactionFromPreview (line 333). After PR [No QA] Disallow manual memoization in compiled React code #104522 removed manual useCallback memoization in MoneyRequestReportPreview/index.tsx so it is compiled by React Compiler (and lowered through cjs-inline-requires-loader.mjs on native), evaluating contextMenuRef.current?.isContextMenuOpening directly on the imported binding during cold-start hydration crashes on Android unless contextMenuRef.current is captured in a local variable first.

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

    1. In src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx, capture const contextMenu = contextMenuRef.current; in a local variable before checking contextMenu?.isContextMenuOpening in both openReportFromPreview (lines 173-176) and openTransactionFromPreview (lines 332-335):
        const openReportFromPreview = () => {
            const contextMenu = contextMenuRef.current;
            if (!iouReportID || contextMenu?.isContextMenuOpening) {
                return;
            }

    and:

        const openTransactionFromPreview = (transaction: Transaction) => {
            const contextMenu = contextMenuRef.current;
            if (contextMenu?.isContextMenuOpening) {
                return;
            }

    (Alternatively, we can export a small helper function isContextMenuOpening(): boolean from src/pages/inbox/report/ContextMenu/ReportActionContextMenu.ts that captures const contextMenu = contextMenuRef.current; return !!contextMenu?.isContextMenuOpening; and call isContextMenuOpening() in both handlers so MoneyRequestReportPreview does not need to touch contextMenuRef.current directly.)

    1. Optionally, to stop contextMenuRef.current from detaching to null on every background render of PopoverReportActionContextMenu when the popover is closed, we can also store isContextMenuOpening in a ref (or keep the imperative handle methods reading from refs with a stable useImperativeHandle(ref, () => ({ ... }), [ ... ])) in src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx, since isContextMenuOpening is never read in JSX.

    What alternative solutions did you explore? (Optional)

    Waiting for contextMenuRef.current to be non-null before allowing preview presses would block opening reports/transactions during the initial 2-second idle deferral window (IDLE_CALLBACK_TIMEOUT_MS in GlobalModals.tsx) when the context menu has not even been mounted yet. Capturing const contextMenu = contextMenuRef.current locally in openReportFromPreview and openTransactionFromPreview safely treats an unmounted or mid-commit ref as not opening while avoiding the Android crash.

  10. sijo0218 commented on Oct 29, 2026

    @sijo0218

    Proposal

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

    On Android, after force-closing and restarting the app in a workspace chat that contains an expense report with multiple transactions, tapping a transaction card in the report preview causes the app to crash instead of opening the transaction thread report.

    What is the root cause of that problem?

    There are three interrelated architectural and lifecycle factors causing this crash on Android:

    1. Direct ref de-referencing bypassing encapsulation:
      Across the application, contextMenuRef in src/pages/inbox/report/ContextMenu/ReportActionContextMenu.ts is strictly encapsulated behind exported helper functions (showContextMenu, hideContextMenu, isActiveReportAction, clearActiveReportAction, showDeleteModal, hideDeleteModal). Each of these helpers guards access to the underlying ref.
      However, src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx was the sole exception in the entire codebase, importing contextMenuRef directly and evaluating contextMenuRef.current?.isContextMenuOpening inline in openReportFromPreview (line 184) and openTransactionFromPreview (line 349).

    2. Un-memoized useImperativeHandle causing ref.current detachment during Onyx hydration:
      In src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx:501-513, useImperativeHandle(ref, () => ({ ... })) is declared without any dependency array.
      PopoverReportActionContextMenu subscribes to several global Onyx collections (ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS, ONYXKEYS.COLLECTION.REPORT_ACTIONS, etc.).
      During cold-start hydration following an app restart, initial data sequentially hydrates across these subscriptions, triggering multiple successive re-renders of PopoverReportActionContextMenu. Because useImperativeHandle lacks dependencies, React commits cleanup on each render—setting ref.current = null in the mutation phase before attaching the newly created imperative handle in the layout phase. This causes contextMenuRef.current to cycle value -> null -> value.

    3. Android Hermes runtime crash on unmemoized member de-referencing:
      Under React Native Android with Hermes, React Compiler, and inline module requires (cjs-inline-requires-loader.mjs), evaluating contextMenuRef.current?.isContextMenuOpening directly across the imported module binding while the ref is in transition or unattached leads to accessing properties on an uninitialized/null reference, terminating the process with a fatal native crash ("Expensify keeps stopping").

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

    1. Export isContextMenuOpening helper from ReportActionContextMenu.ts

    In src/pages/inbox/report/ContextMenu/ReportActionContextMenu.ts, add and export the encapsulated helper function, matching isActiveReportAction and clearActiveReportAction:

    --- a/src/pages/inbox/report/ContextMenu/ReportActionContextMenu.ts
    +++ b/src/pages/inbox/report/ContextMenu/ReportActionContextMenu.ts
    @@ -191,8 +191,16 @@ function clearActiveReportAction() {
         return contextMenuRef.current.clearActiveReportAction();
     }
     
    -export {contextMenuRef, showContextMenu, hideContextMenu, isActiveReportAction, clearActiveReportAction, showDeleteModal, hideDeleteModal, registerEnsureContextMenuMounted};
    +/**
    + * Whether the context menu is currently opening.
    + */
    +function isContextMenuOpening(): boolean {
    +    const contextMenu = contextMenuRef.current;
    +    return !!contextMenu?.isContextMenuOpening;
    +}
    +
    +export {contextMenuRef, showContextMenu, hideContextMenu, isActiveReportAction, clearActiveReportAction, showDeleteModal, hideDeleteModal, registerEnsureContextMenuMounted, isContextMenuOpening};
     export type {ContextMenuType, ReportActionContextMenu, ContextMenuAnchor};

    Capturing contextMenuRef.current in a local variable (const contextMenu = contextMenuRef.current) ensures the ref is read exactly once in a single evaluation step.

    2. Update MoneyRequestReportPreview/index.tsx to consume isContextMenuOpening

    In src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx, replace direct access to contextMenuRef with the new helper:

    --- a/src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx
    +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx
    @@ -32,7 +32,7 @@ import Navigation from '@libs/Navigation/Navigation';
     import {getNonEmptyStringOnyxID} from '@libs/getNonEmptyStringOnyxID';
     import {getIOUActionForReportID} from '@libs/ReportActionsUtils';
     import {isIOUReport} from '@libs/ReportUtils';
    -import {contextMenuRef} from '@pages/inbox/report/ContextMenu/ReportActionContextMenu';
    +import {isContextMenuOpening} from '@pages/inbox/report/ContextMenu/ReportActionContextMenu';
     import CONST from '@src/CONST';
     import ONYXKEYS from '@src/ONYXKEYS';
     import ROUTES from '@src/ROUTES';
    @@ -181,7 +181,7 @@ function MoneyRequestReportPreview({
         }, []);
     
         const openReportFromPreview = useCallback(() => {
    -        if (!iouReportID || contextMenuRef.current?.isContextMenuOpening) {
    +        if (!iouReportID || isContextMenuOpening()) {
                 return;
             }
     
    @@ -346,7 +346,7 @@ function MoneyRequestReportPreview({
     
         const openTransactionFromPreview = useCallback(
             (transaction: Transaction) => {
    -            if (contextMenuRef.current?.isContextMenuOpening) {
    +            if (isContextMenuOpening()) {
                     return;
                 }

    3. Stabilize useImperativeHandle in PopoverReportActionContextMenu.tsx

    In src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx, supply [isContextMenuOpening] as the dependency array so that background Onyx hydration updates do not detach and reattach the ref on every tick:

    --- a/src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx
    +++ b/src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx
    @@ -510,7 +510,7 @@ function PopoverReportActionContextMenu({ref}: PopoverReportActionContextMenuPr
             contentRef,
             isContextMenuOpening,
             composerToRefocusOnCloseEmojiPicker: composerToRefocusOnClose,
    -    }));
    +    }), [isContextMenuOpening]);
     
         const reportAction = reportActionRef.current;

    What alternative solutions did you explore? (Optional)

    1. Capturing const contextMenu = contextMenuRef.current; locally inside MoneyRequestReportPreview: While locally capturing the ref stops the crash, leaving contextMenuRef exposed violates the component architecture of ReportActionContextMenu, where all callers interact through exported helper functions. Providing isContextMenuOpening() encapsulates the ref correctly across the codebase.
    2. Waiting for contextMenuRef.current to be defined before allowing preview taps: This would introduce an artificial 2-second touch block during the idle deferral window (IDLE_CALLBACK_TIMEOUT_MS in GlobalModals.tsx) when the context menu is still lazily idle-deferred. Calling isContextMenuOpening() handles unmounted, null, or opening states cleanly with zero interaction latency.

    What automated tests can you add to prevent this from re-occurring?

    Add unit tests in tests/ui/MoneyRequestReportPreview.test.tsx verifying:

    1. openTransactionFromPreview executes cleanly when contextMenuRef.current is null (simulating cold-start pre-hydration state).
    2. openTransactionFromPreview safely executes when contextMenuRef.current transitions during mount.
    3. isContextMenuOpening() returns false when contextMenuRef.current is null without throwing any runtime error.

    Contributor details
    Your Expensify account email: sijo0218@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~011091133bbb09cd1c

  11. melvin-bot commented on Oct 29, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  12. jmquero92 commented on Oct 29, 2026

    @jmquero92

    Proposal

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

    On Android, after force-closing and reopening the app in a workspace chat that contains an expense report with multiple transactions, tapping a transaction card in the report preview crashes the app instead of opening the transaction thread report.

    What is the root cause of that problem?

    1. In src/GlobalModals.tsx, LazyPopoverReportActionContextMenu is mounted with
      ef={ReportActionContextMenu.contextMenuRef}. Inside src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx (lines 500-512), useImperativeHandle(ref, () => ({ ... })) is declared without a dependency array while the component subscribes to multiple global Onyx collections (TRANSACTION_VIOLATIONS, VISIBLE_REPORT_ACTIONS, BANK_ACCOUNT_LIST, etc.). During cold-start Onyx hydration after an app restart, each render detaches contextMenuRef.current = null in React's mutation phase before re-attaching the new handle in the layout phase.
    2. Unlike every other consumer of src/pages/inbox/report/ContextMenu/ReportActionContextMenu.ts (which uses encapsulated helper functions), src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx imports contextMenuRef directly and evaluates contextMenuRef.current?.isContextMenuOpening in openReportFromPreview and openTransactionFromPreview. After PR [No QA] Disallow manual memoization in compiled React code #104522 enabled React Compiler on MoneyRequestReportPreview/index.tsx (combined with cjs-inline-requires-loader.mjs on Android Hermes), reading .current?.isContextMenuOpening directly across the inline-required module binding while contextMenuRef.current transitions �alue -> null -> value during cold-start hydration triggers a fatal Android crash unless captured in a local variable / helper function.

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

    1. In src/pages/inbox/report/ContextMenu/ReportActionContextMenu.ts, export a dedicated helper function isContextMenuOpening(): boolean that captures const contextMenu = contextMenuRef.current; return !!contextMenu?.isContextMenuOpening;.
    2. In src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx, replace the direct contextMenuRef.current?.isContextMenuOpening checks in both openReportFromPreview and openTransactionFromPreview with isContextMenuOpening() (or capture const contextMenu = contextMenuRef.current; locally before checking contextMenu?.isContextMenuOpening).
    3. In src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx, stabilize useImperativeHandle so background Onyx hydration renders while the context menu is closed do not repeatedly detach and re-attach contextMenuRef.current.

    What alternative solutions did you explore? (Optional)

    Blocking preview presses when contextMenuRef.current is
    ull was ruled out because GlobalModals.tsx defers mounting LazyPopoverReportActionContextMenu via
    equestIdleCallback (IDLE_CALLBACK_TIMEOUT_MS = 2000), so contextMenuRef.current is legitimately
    ull right after startup. Capturing the ref via isContextMenuOpening() safely returns alse when unmounted or mid-hydration without blocking user taps.

    Contributor details
    Your Expensify account email: jmquero92@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~010b8a98bb82c2f8e6

  13. melvin-bot commented on Oct 29, 2026

    @melvin-bot

    ⚠️ Invalid email. Please make sure to create an Expensify account with this email first here.

  14. 14 remaining items

  15. mountiny commented on Nov 3, 2026

    @mountiny
    Contributor

    (Vit's agent) Sentry tracks this crash as APP-NHA. Fresh numbers:

    • Users (last 14d, production 9.5.25 to 9.5.27): 7 (9.5.25: 5, 9.5.26: 1, 9.5.27: 1)
    • Users (total since first seen): 23
    • First seen: 2026-10-27. It still happens on 9.5.27.
    • Platform: Android HybridApp
    • Error: TypeError: Cannot read property 'isContextMenuOpening' of null, thrown from the report preview onPress at src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx:174
  16. jeffrey-graham commented on Nov 7, 2026

    @jeffrey-graham
  17. melvin-bot commented on Nov 7, 2026

    @melvin-bot
  18. added
    ExternalAdded to denote the issue can be worked on by a contributor
    and removed
    ExternalAdded to denote the issue can be worked on by a contributor
    on Nov 13, 2026
  19. melvin-bot commented on Nov 13, 2026

    @melvin-bot

    Current assignee @dmkt9 is eligible for the External assigner, not assigning anyone new.

  20. melvin-bot commented on Nov 13, 2026

    @melvin-bot

    📣 @dmkt9 You have been assigned to this job!
    Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
    Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs!
    Keep in mind: Code of Conduct | Contributing 📖

  21. mallenexpensify commented on Nov 13, 2026

    @mallenexpensify
    Contributor

    @dmkt9 what's status here? If a C+ is needed, can you unassign yourself, remove then readd External to assign one, then reassign yourself? DM me in Slack if it doesn't work. Thx

  22. dmkt9 commented on Nov 16, 2026

    @dmkt9
    Contributor

    @dmkt9 what's status here? If a C+ is needed, can you unassign yourself, remove then readd External to assign one, then reassign yourself? DM me in Slack if it doesn't work. Thx

    This PR is still open at #105472.
    @mountiny Could you please assign a new C+ reviewer to take a look? Thank you!

  23. mkhutornyi commented on Nov 16, 2026

    @mkhutornyi
    Contributor

    I can help

  24. mountiny commented on Nov 16, 2026

    @mountiny
    Contributor

    @mkhutornyi go ahead please

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 contributorReviewingHas a PR in review

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions