You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[$250] Expense - App crashes after adding unreported expenses to report and deleting the expenses #86466
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)
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.
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.
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.
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:
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.
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.
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.
🤖 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.
Activity
MelvinBot commentedon Apr 13, 2026
Proposal
What is the root cause of that problem?
When bulk-deleting all expenses from a report, the last
deleteMoneyRequestcall optimistically setsreportID: nullon the IOU report via Onyx merge. This causesMoneyRequestReportActionsListto subscribe to an invalid Onyx key (report_null), which returnsundefined. Because the result is cast withas unknown as [OnyxTypes.Report], TypeScript doesn't catch the problem. The crash then occurs at line 543 when accessingreport.lastReadTimeonundefined.The deletion is intentionally deferred until after navigation via the
TRANSITION_END_SCREEN_WRAPPERevent, but the source screen can still process Onyx updates before fully unmounting, creating a window whereMoneyRequestReportActionsListre-renders with the nulledreportIDbeforeReportNotFoundGuardcatches up.What changes do you think we should make in order to solve the problem?
Add an early return guard in
MoneyRequestReportActionsList— ifreportis nullish (which happens whenreportIDPropbecomesnulldue to the optimistic delete), returnnullbefore 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
useOnyxcall at line 135, add a check: if!report, returnnull. This prevents the TypeError at line 543 and any other unsafe property accesses downstream.What alternative solutions did you explore? (Optional)
as unknown as [OnyxTypes.Report]) and properly handle theundefinedcase throughout the component. This is more thorough but requires many more changes sincereportis accessed extensively.reportID: nulloptimistic 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.ReportNotFoundGuardalways 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 thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.melvin-bot commentedon Apr 13, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @DylanDylann (
External)melvin-bot commentedon Apr 13, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022043626931241071574
4 remaining items
melvin-bot commentedon Apr 13, 2026
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
JustDreameritis commentedon Apr 13, 2026
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(inuseSelectedTransactionsActions.ts, line 222) callsNavigation.removeReportScreen(new Set(deletedThreadReportIDs))with two thread report IDs (one per deleted expense). InsideremoveReportScreen, the filtered routes shrink by 2, but the index formula only accounts for removing 1:Result:
state.routes[state.index]isundefined→ React Navigation crashes reading.keyon it insideuseNavigationBuilder. Thelogs.txtconfirms this:Fix
File:
src/libs/Navigation/Navigation.ts, functionremoveReportScreen(line 849):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 - 1bug exists inremoveScreenFromNavigationState(line 825) andremoveScreenByKey(line 843) — worth fixing in a follow-up, but not on this issue's crash path.JustDreameritis commentedon Apr 16, 2026
Quick clarification for @DylanDylann — the stack trace shows the crash in
useNavigationBuilderaccessingstate.routes[state.index]?.key, not in any report component render. My proposal addresses this at the source:removeReportScreeninNavigation.ts:861usesstate.index - 1which 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.
JustDreameritis commentedon Apr 16, 2026
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.
melvin-bot commentedon Apr 16, 2026
@DylanDylann Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
DylanDylann commentedon Apr 17, 2026
Can't reproduce. Looks like this issue has already been fixed by #88053
Screen.Recording.2026-04-17.at.16.01.38.mov
DylanDylann commentedon Apr 17, 2026
@MelvinBot Please close this issue
MelvinBot commentedon Apr 17, 2026
🤖 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.DylanDylann commentedon Apr 17, 2026
I am Dylan (assignee of this issue), and I agree to close this issue. Could you help?
DylanDylann commentedon Apr 17, 2026
@MelvinBot I am Dylan (assignee of this issue), and I agree to close this issue. Could you help?
MelvinBot commentedon Apr 17, 2026
🤖 Issue closed as requested by
DylanDylann.