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
[Due for payment 2026-05-20][$250] RHP closes unexpectedly when navigating between expense reports using prev/next arrows #87784
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
Run a search filtered to Expense Reports with several results
Open one of the expense reports (RHP opens)
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: @mallenexpensifyUpwork Automation - Do Not Edit
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.
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
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.
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.
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.
[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.
@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
Activity
leshniak commentedon Apr 13, 2026
@Julesssss thanks for creating a ticket. I'm already working on this, there is an internal discussion around the proposal.
MelvinBot commentedon Apr 13, 2026
Proposal
What is the root cause of that problem?
SearchMoneyRequestReportPagehas a removal-detection effect (SearchMoneyRequestReportPage.tsx:94-110) that callsNavigation.dismissModal()whenreportbecomesundefinedwhileprevReportwas a money request report.During prev/next arrow navigation,
MoneyRequestReportNavigation.tsx:63-70callsNavigation.setParams({reportID: newId}), which synchronously updates the route params. This causesuseOnyxto subscribe to a new Onyx key (report_newID). If the new report data isn't in Onyx's cache yet,reportis brieflyundefined— and the effect misinterprets this transient loading state as a deletion, dismissing the RHP.The existing
firstRenderRefguard 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
reportIDFromRouteand 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 — theundefinedreport 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
prevReportIDFromRouteis compared toreportIDFromRouteforisInitialMountRef.What alternative solutions did you explore? (Optional)
Resetting
firstRenderRef.current = truewhenreportIDFromRoutechanges 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 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 - @suneox (
External)[-]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[/+]melvin-bot commentedon Apr 13, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022043758139918298894
trasnake87 commentedon Apr 13, 2026
trasnake87 commentedon Apr 13, 2026
Contributor details
Your Expensify account email: trasnake87@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/~010f770315ab181656
melvin-bot commentedon Apr 13, 2026
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
wildan-m commentedon Apr 13, 2026
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-L110treats every render wherereportis falsy andprevReportwas a money-request report as a deletion, and unconditionally callsNavigation.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
prevReportandreportIDFromRouteadvancing out of lockstep. On an arrow click,reportIDFromRouteflips first — the route params are updated inline by the click handler. TheuseOnyxcall at line 77 then re-subscribes to the newreport_<id>key and emitsundefinedfor the render that follows, because the new report has not hydrated yet. MeanwhileprevReportfromusePrevious(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 seesreport=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
prevReportstill corresponds to the active route:reportIDFromRoutedoes not change, soprevReport.reportIDstill equalsreportIDFromRoute.prevReport.reportIDis now the previous id whilereportIDFromRouteis the new id — they disagree for exactly one render, which is the render the effect is currently mis-firing on.The existing
firstRenderRefguard 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-L110so that a falsyreportis only treated as a deletion whenprevReport?.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:
prevReportstill describes the previous one. The new equality check fails, the effect returns without invokingNavigation.dismissModal(), and the RHP stays open. A render later Onyx hands back the next report's data,reportbecomes defined again, and the screen continues as normal.reportIDFromRoutenever changed,prevReport.reportIDstill 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.reportIDFromRouteshould 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>viauseOnyxand 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 anduseOnyxreturnsundefinedindefinitely — 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 = truewheneverreportIDFromRoutechanges 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 betweenprevReport?.reportIDandreportIDFromRouteexpresses the same constraint in one place without that conceptual stretch.51 remaining items
aimane-chnaif commentedon May 20, 2026
@MelvinBot find offending PR
MelvinBot commentedon May 20, 2026
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
useEffectinSearchMoneyRequestReportPage.tsxthat callsNavigation.dismissModal()when the report becomesundefinedafter 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 briefundefinedwindow that the effect misinterprets as a deletion.aimane-chnaif commentedon May 20, 2026
BugZero Checklist:
[Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to comment: https://github.com/Expensify/App/pull/81620/changes#r3245076713
[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/639888
Regression Test Proposal
Test:
Case 1:
Case 2:
Case 3:
Do we agree 👍 or 👎
Zapier Logs
Run ID: 00040eee-4521-a784-14e8-4984c1a30714aimane-chnaif commentedon May 20, 2026
I reviewed 2 different PRs linked to this issue.
@Julesssss can you please confirm?
melvin-bot commentedon May 20, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
mallenexpensify commentedon May 22, 2026
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.
aimane-chnaif commentedon May 26, 2026
@mallenexpensify I am paid via updwork
mallenexpensify commentedon May 26, 2026
@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
aimane-chnaif commentedon May 27, 2026
@mallenexpensify accepted offer
mallenexpensify commentedon May 27, 2026
@aimane-chnaif paid, summary updated above. Thx.