App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-11-30] [$175] Android – App crashes when opening a transaction from a report preview after restarting the app.

Open m-natarajan opened this issue 1 month ago • 31 comments

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:

  • [x] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [ ] Windows: Chrome
  • [ ] MacOS: Chrome / Safari

Note:

crash occurs here: https://github.com/Expensify/App/blob/2a41126adf50ac064cc1956926538aba203c2603/src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx#L333-L335 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

https://github.com/user-attachments/assets/3a0173b6-b4b4-4567-97e2-542e1f9eaca3

https://github.com/user-attachments/assets/56a10764-931a-4c9d-b783-75dba6f96236

View all open jobs on GitHub

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

m-natarajan avatar Oct 29 '26 15:10 m-natarajan

⚠️ 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

MelvinBot avatar Oct 29 '26 15:10 MelvinBot

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

melvin-bot[bot] avatar Oct 29 '26 15:10 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022115827795513184215

melvin-bot[bot] avatar Oct 29 '26 15:10 melvin-bot[bot]

Proposal

Audit verdict: insufficient evidence for a defensible fix proposal. No root cause, TypeScript patch, or passing regression test has been verified.

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

On Android version 9.5.25-0, opening a transaction through a report preview after fully closing and reopening the app reportedly crashes the application. The transaction report should open successfully.

What is the root cause of that problem?

Undetermined. The supplied material contains reproduction steps but no source snippets, exception message, stack trace, or reproducible test fixture.

During verification:

  • No Expensify checkout was found in the workspace.
  • The linked crash logs and video attachments could not be retrieved.
  • The affected version’s source could not be retrieved.
  • The original GitHub issue and its existing proposals were not located, leaving duplicate and prior-fix status unverified.

Cold-start state hydration, stale transaction references, navigation restoration, and native rendering failures are investigation hypotheses only. The restart dependency does not establish any of them.

Exact source paths and line numbers cannot be responsibly attributed without inspecting the affected revision and correlating it with the crash.

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

No production change is justified yet. An exact TypeScript diff here would fabricate both the failing code and the necessary correction.

The minimum evidence needed to select a surgical fix is:

  1. Reproduce on 9.5.25-0 and record the Android version, build identifier, and exact app-termination method.
  2. Capture timestamped adb logcat output covering termination, relaunch, preview selection, and failure. Obtain a symbolicated JavaScript stack or native crash trace as applicable.
  3. Trace the exception to the affected source revision and preserve the smallest sanitized state fixture that reproduces it.
  4. Add a regression test that fails for the observed reason before applying the smallest corrective change.

Expensify’s contribution guidelines require reproduction before proceeding with a proposal.

What alternative solutions did you explore? (Optional)

No MelvinBot proposal was supplied, so there is no specific implementation to rebut.

Blanket optional chaining, swallowed exceptions, startup delays, and clearing persisted storage lack demonstrated justification. They could suppress symptoms, leave navigation broken, or remove state without correcting the cause.

There is also no evidence supporting a security classification or CVSS score.

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

Proposed coverage; not implemented or executed:

  • Android lifecycle regression: create a report with two distinct transactions, terminate and relaunch the app using the reproduced termination method, open each transaction through the preview, and verify the correct transaction renders and remains usable.
  • Targeted Jest regression: once the failing function or component is identified, replay the captured state and event sequence. Assert successful navigation and the correct transaction identifier. Demonstrate failure before the patch and success afterward.

A Jest test alone cannot establish that an Android native process crash is fixed; device or emulator verification remains necessary.

Contributor details
Your Expensify account email: [email protected]
Upwork Profile Link: https://www.upwork.com/freelancers/~01b60d704ba377be83

camesenin avatar Oct 29 '26 15:10 camesenin

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

melvin-bot[bot] avatar Oct 29 '26 15:10 melvin-bot[bot]

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

sonofkratos92 avatar Oct 29 '26 15:10 sonofkratos92

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: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~011091133bbb09cd1c

sijo0218 avatar Oct 29 '26 16:10 sijo0218

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

melvin-bot[bot] avatar Oct 29 '26 16:10 melvin-bot[bot]

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 #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: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~010b8a98bb82c2f8e6

jmquero92 avatar Oct 29 '26 17:10 jmquero92

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

melvin-bot[bot] avatar Oct 29 '26 17:10 melvin-bot[bot]

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

melvin-bot[bot] avatar Oct 29 '26 17:10 melvin-bot[bot]

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

melvin-bot[bot] avatar Oct 29 '26 17:10 melvin-bot[bot]

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

melvin-bot[bot] avatar Oct 30 '26 11:10 melvin-bot[bot]

📣 @marufsharifi We're missing your Upwork ID to automatically send you an offer for the Reviewer role. Once you apply to the Upwork job, your Upwork ID will be stored and you will be automatically hired for future jobs!

melvin-bot[bot] avatar Oct 30 '26 18:10 melvin-bot[bot]

📣 @marufsharifi We're missing your Upwork ID to automatically send you an offer for the Reviewer role. Once you apply to the Upwork job, your Upwork ID will be stored and you will be automatically hired for future jobs!

melvin-bot[bot] avatar Oct 30 '26 18:10 melvin-bot[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 📖

melvin-bot[bot] avatar Oct 30 '26 18:10 melvin-bot[bot]

Sorry, wrong issue Mariusz

mountiny avatar Oct 30 '26 18:10 mountiny

(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

mountiny avatar Nov 03 '26 04:11 mountiny

Proposal

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

On Android, after force-closing and restarting the app while viewing a workspace chat that contains an expense report preview with multiple transactions, tapping a transaction card inside the report preview crashes the app (TypeError: Cannot read property 'isContextMenuOpening' of null) instead of opening the transaction thread.

What is the root cause of that problem?

  1. In src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx (around line 174), the transaction preview press handler directly dereferences ReportActionContextMenu.contextMenuRef.current.isContextMenuOpening without optional chaining (contextMenuRef.current?.isContextMenuOpening).
  2. In src/GlobalModals.tsx (lines 31–62), LazyPopoverReportActionContextMenu is mounted lazily with ref={ReportActionContextMenu.contextMenuRef}. On Android cold start while Onyx is hydrating large collections (TRANSACTION_VIOLATIONS, REPORT_ACTIONS, etc.), LazyPopoverReportActionContextMenu either has not finished mounting its imperative handle yet or temporarily detaches/re-attaches contextMenuRef.current across re-renders in PopoverReportActionContextMenu.tsx, leaving ReportActionContextMenu.contextMenuRef.current as null when the user taps a transaction card in MoneyRequestReportPreview.
  3. Dereferencing .isContextMenuOpening on null throws an unhandled TypeError on the UI/JS thread and crashes the Android app.

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

  1. In src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx (line 174) and any other callers accessing ReportActionContextMenu.contextMenuRef.current, use optional chaining (Boolean(ReportActionContextMenu.contextMenuRef.current?.isContextMenuOpening)) or expose a null-safe helper isContextMenuOpening() in src/pages/inbox/report/ContextMenu/ReportActionContextMenu.ts.
  2. In src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx, memoize the dependencies of useImperativeHandle so contextMenuRef.current is not needlessly torn down on unrelated Onyx collection updates during cold-start hydration.

What alternative solutions did you explore? (Optional)

We considered eagerly mounting PopoverReportActionContextMenu instead of using React.lazy in GlobalModals.tsx, but lazy loading improves startup performance, and making contextMenuRef.current access null-safe eliminates the crash without sacrificing startup bundle splitting.

jeffrey-graham avatar Nov 07 '26 08:11 jeffrey-graham

📣 @jeffrey-graham! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 07 '26 08:11 melvin-bot[bot]