Skip to content

[Due for payment 2026-05-11] [$500] DM chat cannot be exited after deleting an expense and tapping back button #88499

Closed

Description

@mitarachim

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.61-0
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #88053
Email or phone of affected tester (no customers): N/A
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: iPhone 15 iOS 26,3,1
App Component: Money Requests

Action Performed:

  1. Sign in to ND with a new account
  2. Create a 1:1 chat with another user
  3. Create an expense in the chat
  4. Open the expense and tap the parent chat link in the header
  5. Tap the expense again, tap “More options,” and then tap “Delete.”
  6. Tap Back button

Expected Result:

User is able to navigate away from the chat after deleting an expense

Actual Result:

User is stuck in the DM chat. On Prod the app crashes

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7135240_1776824714228.Test_2.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @mallenexpensify
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022047380710386412184
  • Upwork Job ID: 2047380710386412184
  • Last Price Increase: 2026-04-23

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    DeployBlockerIndicates it should block deploying the API
    on Apr 22, 2026
  2. melvin-bot commented on Apr 22, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #88053

  3. melvin-bot commented on Apr 22, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. github-actions commented on Apr 22, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  5. MelvinBot commented on Apr 22, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    The delete-expense flow in MoneyRequestHeaderSecondaryActions (line 438-450) calls onBackButtonPress() synchronously and defers the actual deletion via InteractionManager.runAfterInteractions. This leaves stale navigation stack entries for the deleted report. When the user taps back from the DM, they navigate to one of these stale entries.

    The safety mechanisms that should handle this scenario all fail:

    1. deleteTransactionNavigateBackUrl suppresses the NotFound guard (ReportNotFoundGuard.tsx:54): The URL is set before deletion and only cleared by DeleteTransactionNavigateBackHandler when its host screen loses focus. The DM screen is focused after the delete, so it doesn't clear the URL. When the user navigates backward to the deleted report, the URL is still set, suppressing the NotFound page.

    2. isOptimisticDelete permanently hides the deleted transaction thread: The transaction thread gets statusNum: CLOSED during optimistic deletion (DeleteMoneyRequest.ts), making isOptimisticDelete = true. In ReportNotFoundGuard.tsx:51, reportExists = !!reportID || isOptimisticDelete || userLeavingStatus evaluates to true even though reportID is null. This was designed to prevent a brief NotFound flash during the deletion transition, but it also prevents NotFound from ever showing when the user navigates back to the deleted screen.

    3. useReportWasDeleted can't detect already-deleted reports (useReportWasDeleted.ts:56): The isOptimisticDelete guard causes an early return, so wasDeleted stays false. The "Navigate on deletion" effect in ReportNavigateAwayHandler.tsx:187-209 never fires.

    4. "Navigate on removal" skips first render (ReportNavigateAwayHandler.tsx:129): When the stale screen remounts, firstRender.current = true causes the effect to skip, and on second render prevOnyxReportID was undefined (from the loading state), so wasReportRemoved is false.

    The user ends up on a screen showing a deleted report with all escape mechanisms bypassed, making the back button non-functional or causing a crash (on prod).

    PR #88053 exacerbated this by changing MoneyRequestReportActionsList to source reportID from route.params instead of props. This means the component maintains its Onyx subscription to the deleted report key (REPORT_{id}) even after the report's reportID is set to null, causing it to operate on a partially-deleted object with a forced type cast hiding the undefined state (line 101: as unknown as [OnyxTypes.Report]).

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

    Fix the ReportNotFoundGuard to not treat isOptimisticDelete as proof of report existence when the reportID is null AND deleteTransactionNavigateBackUrl has been cleared (or is absent). This makes the NotFound page show correctly for stale navigation entries while still preventing the flash during active deletion:

    In ReportNotFoundGuard.tsx:51, change:

    const reportExists = !!reportID || isOptimisticDelete || userLeavingStatus;
    

    to:

    const reportExists = !!reportID || (isOptimisticDelete && !!deleteTransactionNavigateBackUrl) || userLeavingStatus;
    

    This ties the isOptimisticDelete suppression to the active deletion flow (indicated by deleteTransactionNavigateBackUrl being set). Once the URL is cleared (after the deletion transition completes), a deleted report with statusNum: CLOSED and reportID: null will correctly show the NotFound page, allowing the user to navigate away.

    What alternative solutions did you explore? (Optional)

    • Clean stale entries from navigation stack on deletion: More invasive — would require deleteMoneyRequest to inspect and manipulate the React Navigation state, which couples deletion logic to navigation internals.
    • Make useReportWasDeleted detect already-deleted reports on mount: Would require removing the isOptimisticDelete early return, but this could reintroduce the NotFound flash that the flag was designed to prevent.
    • Clear deleteTransactionNavigateBackUrl more aggressively (e.g., on a timer): Fragile and timing-dependent; doesn't fix the isOptimisticDelete permanently hiding deleted reports.

    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.

  6. DylanDylann commented on Apr 22, 2026

    @DylanDylann
    Contributor

    @MelvinBot Before moving the logic to ReportNotFoundGuard component in #86720. We also use reportID from report in src/pages/inbox/ReportScreen.tsx

    const reportExists = !!reportID || (!isDeletedTransactionThread && isOptimisticDelete) || userLeavingStatus;
    

    So I don't think your statement is valid

    PR #88053 exacerbated this by changing MoneyRequestReportActionsList to source reportID from route.params instead of props. This means the component maintains its Onyx subscription to the deleted report key (REPORT_{id}) even after the report's reportID is set to null, causing it to operate on a partially-deleted object with a forced type cast hiding the undefined state (line 101: as unknown as [OnyxTypes.Report]).

  7. MelvinBot commented on Apr 22, 2026

    @MelvinBot
    Contributor

    You're right — I retract the claim about PR #88053. The reportExists check at ReportNotFoundGuard.tsx:47-51 uses report?.reportID from Onyx, not route params, and the same was true in the old ReportScreen.tsx. The change to route-sourced reportID in MoneyRequestReportActionsList doesn't affect this guard.

    The rest of the analysis still holds: the core issue is that stale navigation stack entries for deleted reports aren't properly caught. Specifically:

    1. deleteTransactionNavigateBackUrl suppresses the outer NotFound guard (ReportNotFoundGuard.tsx:54) and prevents the inner guard from running (line 100: !deleteTransactionNavigateBackUrl && isReportTransactionThread(report)). The URL persists because DeleteTransactionNavigateBackHandler only clears it when its host screen loses focus.

    2. For transaction threads, isOptimisticDelete (statusNum === CLOSED) makes reportExists = true at line 51, so even after the URL is cleared, the outer guard doesn't fire. The inner guard (ReportNotFoundInnerGuard) should then catch it via isParentActionDeleted, but only once the URL is cleared.

    I've updated my proposal above to remove the PR #88053 claim. The recommended fix at line 51 remains the same — tying isOptimisticDelete to the active deletion window:

    const reportExists = !!reportID || (isOptimisticDelete && !!deleteTransactionNavigateBackUrl) || userLeavingStatus;
    

    This ensures that once the deletion transition completes (URL cleared), a deleted report with statusNum: CLOSED and reportID: null falls through to the inner guard for transaction threads, or shows NotFound directly for other report types.


    Next Steps: Reply with @MelvinBot <your feedback> to refine this analysis.

  8. 55 remaining items

  9. DylanDylann commented on May 6, 2026

    @DylanDylann
    Contributor

    BugZero Checklist:

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

      Link to the comment on the PR: Can't find out exactly the offending PR. I guess that it's mixed up while refactoring the navigation system
      Link to the comment on the Issue:

    • [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:

    • [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.

    • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

      Link to issue: https://github.com/Expensify/Expensify/issues/635925

    Regression Test Proposal

    Test:

    1. Sign in to ND with a new account
    2. Create a 1:1 chat with another user
    3. Create an expense in the chat
    4. Open the expense and tap the parent chat link in the header
    5. Tap the expense again, tap “More options,” and then tap “Delete.”
    6. Tap Back button

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-f47a-ab6c-786e-0335c49794c4
  10. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on May 6, 2026
  11. melvin-bot commented on May 10, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  12. melvin-bot commented on May 11, 2026

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@mallenexpensify)

    • (if NewFeature) I have created a PR for any necessary HelpDot updates, or I confirmed no updates are necessary.
    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/2047380710386412184/hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  13. mallenexpensify commented on May 12, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @truph01 due $500 via NewDot
    Contributor+: @DylanDylann due $500 via NewDot

    ^ Test case created

    Thx

  14. quinthar commented on May 30, 2026

    @quinthar
    Contributor

    Approved $500 to @DylanDylann

  15. garrettmknight commented on Jul 10, 2026

    @garrettmknight
    Contributor

    $500 approved for @truph01

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