Skip to content

[Due for payment 2026-05-20][$250] RHP closes unexpectedly when navigating between expense reports using prev/next arrows #87784

Closed

Description

@Julesssss

Connection/timing

Discovered during review of #86238 but reproduces on staging independently of those changes.

Description

When viewing an expense report opened from search results, rapidly clicking the prev/next navigation arrows causes the RHP to dismiss unexpectedly. The panel closes as if the report was deleted, even though the user is simply navigating to the next report in the list.

Steps to reproduce

  1. Run a search filtered to Expense Reports with several results
  2. Open one of the expense reports (RHP opens)
  3. Rapidly click the next (or prev) arrow multiple times

Expected behavior

The RHP stays open and displays each successive report.

Actual behavior

The RHP closes mid-navigation, returning the user to the search results list.

Root cause (high level)

SearchMoneyRequestReportPage has a removal-detection effect that dismisses the modal when the report becomes undefined while the previous report was a money request report. During arrow navigation, the route params update before Onyx resolves the new report data, creating a brief window where the report is undefined — which the effect misinterprets as a deletion.

Platform

Reproduces on web (staging). Likely affects all platforms.

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

Activity

  1. self-assigned this
    on Apr 13, 2026
  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Apr 13, 2026
  3. leshniak commented on Apr 13, 2026

    @leshniak
    Contributor

    @Julesssss thanks for creating a ticket. I'm already working on this, there is an internal discussion around the proposal.

  4. MelvinBot commented on Apr 13, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    SearchMoneyRequestReportPage has a removal-detection effect (SearchMoneyRequestReportPage.tsx:94-110) that calls Navigation.dismissModal() when report becomes undefined while prevReport was a money request report.

    During prev/next arrow navigation, MoneyRequestReportNavigation.tsx:63-70 calls Navigation.setParams({reportID: newId}), which synchronously updates the route params. This causes useOnyx to subscribe to a new Onyx key (report_newID). If the new report data isn't in Onyx's cache yet, report is briefly undefined — and the effect misinterprets this transient loading state as a deletion, dismissing the RHP.

    The existing firstRenderRef guard only protects the initial mount and is never reset on subsequent navigations.

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

    Track the previous reportIDFromRoute and skip the dismissal when the route ID just changed (i.e., navigation is in progress, not a deletion):

    In the removal-detection effect, add a check: if prevReportIDFromRoute !== reportIDFromRoute, return early — the undefined report is due to a route change, not a report removal.

    There is already a precedent for this pattern in the same file at line 211 where prevReportIDFromRoute is compared to reportIDFromRoute for isInitialMountRef.

    What alternative solutions did you explore? (Optional)

    Resetting firstRenderRef.current = true when reportIDFromRoute changes was considered but is less explicit — it overloads the "first render" concept to also mean "first render after navigation." Comparing route IDs directly makes the intent clearer.


    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.

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

    @melvin-bot

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

  8. changed the title [-]RHP closes unexpectedly when navigating between expense reports using prev/next arrows[/-] [+][$250] RHP closes unexpectedly when navigating between expense reports using prev/next arrows[/+] on Apr 13, 2026
  9. melvin-bot commented on Apr 13, 2026

    @melvin-bot
  10. trasnake87 commented on Apr 13, 2026

    @trasnake87
  11. trasnake87 commented on Apr 13, 2026

    @trasnake87
    Contributor

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

  12. melvin-bot commented on Apr 13, 2026

    @melvin-bot

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

  13. wildan-m commented on Apr 13, 2026

    @wildan-m
    Contributor

    Proposal

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

    Rapidly clicking the next/prev navigation arrows on an expense report opened from search causes the RHP to close unexpectedly. The user is returned to the search results list mid-navigation, as if the report had been deleted.

    What is the root cause of that problem?

    The deletion-detection effect at SearchMoneyRequestReportPage.tsx#L94-L110 treats every render where report is falsy and prevReport was a money-request report as a deletion, and unconditionally calls Navigation.dismissModal(). But the same (report=undefined, prevReport=<money request>) pairing can arise from a step of arrow-navigation between two money-request reports, and the effect has no signal to tell those cases apart.

    The ambiguity comes from prevReport and reportIDFromRoute advancing out of lockstep. On an arrow click, reportIDFromRoute flips first — the route params are updated inline by the click handler. The useOnyx call at line 77 then re-subscribes to the new report_<id> key and emits undefined for the render that follows, because the new report has not hydrated yet. Meanwhile prevReport from usePrevious(report) at line 89 still holds whatever report was visible on the prior render — i.e. the previously-displayed report, not the one the URL now points at. On this in-between render the effect sees report=undefined, prevReport=<old money request report>, and fires the dismissal even though the URL has already moved on to the next report.

    What distinguishes the two cases is whether prevReport still corresponds to the active route:

    • When a viewed money-request report is actually removed elsewhere (the scenario this effect was originally introduced to handle — a member deleting an expense while someone else is viewing the report), reportIDFromRoute does not change, so prevReport.reportID still equals reportIDFromRoute.
    • When the user clicks an arrow, the route advances one step ahead of the data, so prevReport.reportID is now the previous id while reportIDFromRoute is the new id — they disagree for exactly one render, which is the render the effect is currently mis-firing on.

    The existing firstRenderRef guard only disarms after the first mount of this screen and is never re-armed, so it cannot protect later in-place navigation steps.

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

    Tighten the removal condition in the effect at SearchMoneyRequestReportPage.tsx#L94-L110 so that a falsy report is only treated as a deletion when prevReport?.reportID === reportIDFromRoute. In plain English: only dismiss the modal when the report that just went undefined is the report the URL still points at.

    With that change:

    • When the next arrow is clicked, the route moves to the new id but prevReport still describes the previous one. The new equality check fails, the effect returns without invoking Navigation.dismissModal(), and the RHP stays open. A render later Onyx hands back the next report's data, report becomes defined again, and the screen continues as normal.
    • When an open money-request report is genuinely removed by another member, reportIDFromRoute never changed, prevReport.reportID still matches it, both the existing !report && isMoneyRequestReport(prevReport) condition and the new equality condition are satisfied, and the dismissal happens exactly as it does today.

    reportIDFromRoute should also be added to the effect's dependency array so that the closure reads the current route on each re-run.

    The fix stays entirely inside the page that misclassifies the state, requires no new Onyx subscriptions, and does not block the arrow buttons or gate clicks on cache hydration — so navigating to a report that has never been opened on this device continues to work.

    Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/87784-rhp-nav-deletion-guard?expand=1

    What alternative solutions did you explore? (Optional)

    Subscribing the navigation component to report_<nextId>/report_<prevId> via useOnyx and disabling each arrow until its target report's subscription resolves was considered. It has a hard edge case: if the next or previous report has never been opened on this device, that Onyx key is empty and useOnyx returns undefined indefinitely — the button would stay disabled and the user would be unable to advance to any uncached report. Addressing the misinterpretation at the target-side effect avoids that trap, because it lets navigation proceed immediately and only corrects how the destination page reads the one-render gap before data arrives.

    Resetting firstRenderRef.current = true whenever reportIDFromRoute changes was also considered, but it requires a second effect whose only job is to keep the ref in sync with the route, and it overloads "first render" to also mean "first render after a route change." A direct equality check between prevReport?.reportID and reportIDFromRoute expresses the same constraint in one place without that conceptual stretch.

  14. 51 remaining items

  15. aimane-chnaif commented on May 20, 2026

    @aimane-chnaif
    Contributor

    @MelvinBot find offending PR

  16. MelvinBot commented on May 20, 2026

    @MelvinBot
    Contributor

    The offending PR is #81620 by paulnjs, merged 2026-02-17. It was fixing issue #80893 ("Not here page is displayed when a member deletes an expense").

    That PR added a useEffect in SearchMoneyRequestReportPage.tsx that calls Navigation.dismissModal() when the report becomes undefined after previously being a money request report. The intent was to auto-dismiss when a report is deleted by another member, but during prev/next arrow navigation the route params update before Onyx resolves the new report data — creating a brief undefined window that the effect misinterprets as a deletion.

  17. aimane-chnaif commented on May 20, 2026

    @aimane-chnaif
    Contributor

    BugZero Checklist:

    Regression Test Proposal

    Test:

    Case 1:

    1. Navigate to Search → Reports (expense reports)
    2. Click on any expense report row to open it in the RHP
    3. Verify the navigation arrows are visible and show "X of Y" counter
    4. Use the prev/next arrows to navigate between reports
    5. Verify the arrows remain visible and functional after each navigation
    6. Verify the counter updates correctly
    7. Navigate past 75% of results and verify more results are prefetched (arrows continue working)
    8. Close the RHP and return to search results

    Case 2:

    1. Sign in to ND
    2. Create a workspace, add a couple of expenses
    3. Navigate to Spend tab/ Expenses
    4. In the search field type merchant:[anything with no results], apply the filter
    5. Click on the expand button on filter chip, click "Reset"
    6. Open Workspaces tab
    7. Open Spend tab
    8. Verify: Full expenses list is displayed, filter chip does not appear on the page

    Case 3:

    1. Navigate to Search → Reports (expense reports)
    2. Click on any expense report row to open it in the RHP
    3. Verify the RHP opens and shows the report content (not "Hmm... it's not there")
    4. Use the prev/next navigation arrows to navigate between reports
    5. Verify the RHP stays open and shows a skeleton loader briefly during transitions
    6. Verify no unexpected dismissal occurs during rapid arrow clicking

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-4521-a784-14e8-4984c1a30714
  18. aimane-chnaif commented on May 20, 2026

    @aimane-chnaif
    Contributor

    I reviewed 2 different PRs linked to this issue.

    @Julesssss can you please confirm?

  19. melvin-bot commented on May 20, 2026

    @melvin-bot

    Payment Summary

    Upwork Job

    • Contributor: @leshniak does not require payment (Contractor)
    • ROLE: @aimane-chnaif paid $(AMOUNT) via Upwork (LINK)

    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/2043758139918298894/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
  20. mallenexpensify commented on May 22, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @aimane-chnaif paid $500 via Upwork

    ^ Test case created. Thx

    Thanks for the breakdown/links @aimane-chnaif , it looks correct to me.

  21. aimane-chnaif commented on May 26, 2026

    @aimane-chnaif
    Contributor

    @mallenexpensify I am paid via updwork

  22. mallenexpensify commented on May 26, 2026

    @mallenexpensify
    Contributor

    @aimane-chnaif can you please accept the job below? Please reply here and tag me once you have.
    If you're not sent an offer in Upwork when you're assigned to an issue, and an Upwork job exists, please submit a proposal.
    https://www.upwork.com/jobs/~022059395288356089070

  23. aimane-chnaif commented on May 27, 2026

    @aimane-chnaif
    Contributor

    @mallenexpensify accepted offer

  24. mallenexpensify commented on May 27, 2026

    @mallenexpensify
    Contributor

    @aimane-chnaif paid, summary updated above. Thx.

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.DailyKSv2InternalRequires API changes or must be handled by Expensify staff

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions