Skip to content

[$250] Expense - App crashes after adding unreported expenses to report and deleting the expenses #86466

Closed

Description

@jponikarchuk

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.3.49-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/TR-13513/folder/13176730/41237114/1283215652
Email or phone of affected tester (no customers): joisdjojsndosjijso@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Money Requests

Action Performed:

Precondition:

  • Have a workspace.
  1. Go to staging.new.expensify.com
  2. Go to self DM.
  3. Create two manual expenses.
  4. Open any expense.
  5. Click Report > Create report.
  6. Go to self DM.
  7. Open another exepnse.
  8. Click Report > select the report created in Step 5.
  9. Go to workspace chat.
  10. Open the expense report.
  11. Bulk select both expenses via checkbox.
  12. Click More > Delete.
  13. Click Delete.

Expected Result:

App will not crash.

Actual Result:

App crashes after adding unreported expenses to report and deleting the expenses.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Video.mp4

logs.txt

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @DylanDylann
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022043626931241071574
  • Upwork Job ID: 2043626931241071574
  • Last Price Increase: 2026-04-13

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    and removed on Apr 13, 2026
  2. MelvinBot commented on Apr 13, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    When bulk-deleting all expenses from a report, the last deleteMoneyRequest call optimistically sets reportID: null on the IOU report via Onyx merge. This causes MoneyRequestReportActionsList to subscribe to an invalid Onyx key (report_null), which returns undefined. Because the result is cast with as unknown as [OnyxTypes.Report], TypeScript doesn't catch the problem. The crash then occurs at line 543 when accessing report.lastReadTime on undefined.

    The deletion is intentionally deferred until after navigation via the TRANSITION_END_SCREEN_WRAPPER event, but the source screen can still process Onyx updates before fully unmounting, creating a window where MoneyRequestReportActionsList re-renders with the nulled reportID before ReportNotFoundGuard catches up.

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

    Add an early return guard in MoneyRequestReportActionsList — if report is nullish (which happens when reportIDProp becomes null due to the optimistic delete), return null before accessing any properties. This is the most direct fix since the component already comments that "report is guaranteed to exist" at line 134, but that guarantee breaks during the optimistic deletion window.

    Specifically, after the useOnyx call at line 135, add a check: if !report, return null. This prevents the TypeError at line 543 and any other unsafe property accesses downstream.

    What alternative solutions did you explore? (Optional)

    1. Remove the unsafe type assertion at line 135 (as unknown as [OnyxTypes.Report]) and properly handle the undefined case throughout the component. This is more thorough but requires many more changes since report is accessed extensively.
    2. Prevent the reportID: null optimistic update from reaching this component by having the parent (ReportActionsList) guard against passing a null reportID. However, the optimistic merge is needed for the deletion UX to work correctly.
    3. Ensure ReportNotFoundGuard always processes before child components — but React doesn't guarantee parent guard state updates propagate before child re-renders from the same Onyx change.

    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Apr 13, 2026
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Apr 13, 2026
  5. melvin-bot commented on Apr 13, 2026

    @melvin-bot

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

  6. melvin-bot commented on Apr 13, 2026

    @melvin-bot
  7. 4 remaining items

  8. melvin-bot commented on Apr 13, 2026

    @melvin-bot

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

  9. JustDreameritis commented on Apr 13, 2026

    @JustDreameritis

    Proposal

    Root Cause

    The crash is in removeReportScreen (src/libs/Navigation/Navigation.ts, line 861), not in the report view component.

    When bulk-deleting all expenses, handleDeleteTransactions (in useSelectedTransactionsActions.ts, line 222) calls Navigation.removeReportScreen(new Set(deletedThreadReportIDs)) with two thread report IDs (one per deleted expense). Inside removeReportScreen, the filtered routes shrink by 2, but the index formula only accounts for removing 1:

    index: routes.length < state.routes.length ? state.index - 1 : state.index,

    Result: state.routes[state.index] is undefined → React Navigation crashes reading .key on it inside useNavigationBuilder. The logs.txt confirms this:

    TypeError: Cannot read properties of undefined (reading 'key')
        at useNavigationBuilder
    

    Fix

    File: src/libs/Navigation/Navigation.ts, function removeReportScreen (line 849):

    function removeReportScreen(reportIDSet: Set<string>) {
        isNavigationReady().then(() => {
            navigationRef.current?.dispatch((state) => {
                const focusedRouteKey = state.routes[state.index]?.key;
                const routes = state.routes.filter((route) => {
                    if (route.name === SCREENS.REPORT && route.params && 'reportID' in route.params) {
                        return !reportIDSet.has(route.params?.reportID as string);
                    }
                    return true;
                });
                const newIndex = routes.findIndex((route) => route.key === focusedRouteKey);
                return CommonActions.reset({
                    ...state,
                    routes,
                    index: newIndex >= 0 ? newIndex : Math.max(0, routes.length - 1),
                });
            });
        });
    }

    Track the focused route by key before filtering, then find its new position after. If the focused route itself was removed, fall back to the last route. This handles any number of removed routes correctly.

    The same state.index - 1 bug exists in removeScreenFromNavigationState (line 825) and removeScreenByKey (line 843) — worth fixing in a follow-up, but not on this issue's crash path.

  10. JustDreameritis commented on Apr 16, 2026

    @JustDreameritis

    Quick clarification for @DylanDylann — the stack trace shows the crash in useNavigationBuilder accessing state.routes[state.index]?.key, not in any report component render. My proposal addresses this at the source: removeReportScreen in Navigation.ts:861 uses state.index - 1 which only handles removing 1 route, but bulk-delete removes N routes.

    If my reading of the root cause is correct, happy to build and test a PR.

  11. JustDreameritis commented on Apr 16, 2026

    @JustDreameritis

    Working branch: main...JustDreameritis:App:fix/86466-removeReportScreen-index

    Changes (1 file, 3 lines added, 1 removed):

    • src/libs/Navigation/Navigation.ts — removeReportScreen() now tracks focused route by key before filtering, then finds its new index after. Falls back to last route if focused was removed.

    Ready to open PR on approval.

  12. melvin-bot commented on Apr 16, 2026

    @melvin-bot

    @DylanDylann Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  13. DylanDylann commented on Apr 17, 2026

    @DylanDylann
    Contributor

    Can't reproduce. Looks like this issue has already been fixed by #88053

    Screen.Recording.2026-04-17.at.16.01.38.mov
  14. DylanDylann commented on Apr 17, 2026

    @DylanDylann
    Contributor

    @MelvinBot Please close this issue

  15. MelvinBot commented on Apr 17, 2026

    @MelvinBot
    Contributor

    🤖 I'm unable to close this issue directly due to permission constraints in my current environment. DylanDylann, as the assignee, you can close it yourself using the "Close issue" button below.

  16. DylanDylann commented on Apr 17, 2026

    @DylanDylann
    Contributor

    I am Dylan (assignee of this issue), and I agree to close this issue. Could you help?

  17. DylanDylann commented on Apr 17, 2026

    @DylanDylann
    Contributor

    @MelvinBot I am Dylan (assignee of this issue), and I agree to close this issue. Could you help?

  18. MelvinBot commented on Apr 17, 2026

    @MelvinBot
    Contributor

    🤖 Issue closed as requested by DylanDylann.

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

Metadata

Metadata

Assignees

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions