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] [Exploratory] Reports - Modal closes when clicking Next during action flow #86496
Version Number: 9.3.44-2 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack:#85530 Email or phone of affected tester (no customers):applausetester+ap3@applause.expensifail.com Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Windows 11 App Component: Other
Action Performed:
Preconditions
Fresh account or cache cleared
At least 9 reports with different expense states (Rejected, Approved, Submitted, Held, Duplicated)
1.Open staging.newexpensify.com
2.Navigate to Reports
3.Refresh the Reports page
4.Open any report
5.Click the "Next" button repeatedly until the modal closes
Expected Result:
The modal navigates through all expenses without closing unexpectedly.
Actual Result:
The modal closes unexpectedly after clicking "Next" during initial attempts after refreshing the page.
Root Cause: In SearchMoneyRequestReportPage.tsx (lines 93–110), a removal-detection useEffect dismisses the modal when report becomes undefined while the previous render had a money request report. During Next/Prev arrow navigation, the route params update before Onyx resolves the new report data, creating a brief window where report is undefined — which the effect misinterprets as a deletion and calls Navigation.dismissModal().
This is exacerbated after a page refresh because Onyx data loads asynchronously, making the undefined window longer and more likely to be hit by rapid clicks.
Likely Duplicate: This appears to be the same bug as #87784 ("RHP closes unexpectedly when navigating between expense reports using prev/next arrows"), which already has an identified root cause and is being worked on.
Recommended Fix: The removal-detection effect needs to distinguish between "report was deleted" and "route params changed and new report data hasn't loaded yet." One approach is to also check whether the reportID in route params changed — if it did, the undefined state is expected (navigation in progress) and dismissal should be skipped.
Investigation details
The relevant code is in App/src/pages/Search/SearchMoneyRequestReportPage.tsx:
The firstRenderRef guard only protects against the initial mount. It does not protect against subsequent navigations where the reportID changes but Onyx hasn't yet resolved the new report data.
Next Steps: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.
changed the title [-][Exploratory] Reports - Modal closes when clicking Next during action flow[/-][+][$250] [Exploratory] Reports - Modal closes when clicking Next during action flow[/+]on Apr 14, 2026
Please re-state the problem that we are trying to solve in this issue.
After refreshing the Reports page and opening any expense report, rapidly clicking the Next arrow in the report modal causes the modal to close unexpectedly instead of advancing through the remaining reports. The user is dropped back to the Reports list even though more reports are available. The problem is most reproducible immediately after a refresh or on a freshly loaded account where the Onyx cache is cold.
What is the root cause of that problem?
The Next/Prev arrows in MoneyRequestReportNavigation.tsx swap the currently viewed report by updating the right-hand-panel route parameter via Navigation.setParams({reportID: ...}). That causes SearchMoneyRequestReportPage.tsx to re-derive reportIDFromRoute and subscribe useOnyx to a new report key. Until Onyx hands back data for the new key, the report value is transiently undefined.
Right next to this lookup there is a "removal-detection" effect at lines 93–110 whose job is to dismiss the modal when the report the user was viewing gets deleted or merged. Its current condition is:
"the tracked report became empty AND the previous render still held a money request report"
That condition is violated by a switch-in-progress: after setParams the tracked report transiently becomes empty while the usePrevious snapshot still contains the old money-request report. The effect therefore cannot tell "the currently viewed report was deleted" apart from "I am in the middle of navigating to a different report whose data has not landed yet," and in both cases it calls Navigation.dismissModal(). Visually, the modal just closes mid-click.
The bug is aggravated right after a page refresh because the Onyx cache is empty, so the gap between the route change and the new report data arriving is longer and the effect has more opportunity to fire before Onyx catches up.
Note that the guard firstRenderRef that already exists in that effect only suppresses this behavior on the very first mount of the page — it does not help for subsequent in-place report switches driven by Next/Prev, which is exactly the flow exercised by this issue.
What changes do you think we should make in order to solve the problem?
Tighten the removal-detection effect in SearchMoneyRequestReportPage.tsx so that it only treats a missing report as a real removal when the previously tracked report belongs to the same route the user is currently sitting on.
Concretely: extend the existing condition with a check that the prior snapshot's reportID matches the current reportIDFromRoute. When the Next/Prev arrows change the route, the previous snapshot is for the old report, so its reportID will not match the new reportIDFromRoute and the effect will skip dismissal — exactly the behavior we want while Onyx is still resolving the new key. When a user-visible report is actually deleted (or merged away), the route stays pinned to the same reportIDFromRoute, the prior snapshot's reportID still matches it, and the original dismiss-on-removal flow continues to fire as before. reportIDFromRoute must also be added to the effect's dependency array so the updated guard re-evaluates on every route switch.
This is a minimal, surgical change localized to one effect in one file and preserves the original intent of the "member deletes an expense → show Not here" behavior that introduced the effect. It does not touch the Next/Prev navigation handler, useOnyx, or anything about how the report list is fetched, so it has no effect on layouts, data loading, or offline behavior.
What alternative solutions did you explore? (Optional)
Debounce or delay the effect until the next Onyx resolution tick. Rejected: debouncing would also delay a legitimate deletion dismissal, and any chosen delay is a guess against variable Onyx response times.
Broaden firstRenderRef into a generic "skip first render after route change" ref that resets whenever reportIDFromRoute changes. This works but adds a new ref and an extra effect to maintain it; the route-vs-prev-snapshot comparison is simpler and expresses the real invariant directly.
Move the removal detection out of this page entirely and drive it from an Onyx subscription on delete actions. Rejected as out-of-scope: the existing behavior is acceptable for the deletion case the effect was added for, and a refactor would risk regressing the "Not here" flow that PR #54xxx originally solved.
Activity
MelvinBot commentedon Apr 14, 2026
Issue Analysis
Root Cause: In
SearchMoneyRequestReportPage.tsx(lines 93–110), a removal-detectionuseEffectdismisses the modal whenreportbecomesundefinedwhile the previous render had a money request report. During Next/Prev arrow navigation, the route params update before Onyx resolves the new report data, creating a brief window wherereportisundefined— which the effect misinterprets as a deletion and callsNavigation.dismissModal().This is exacerbated after a page refresh because Onyx data loads asynchronously, making the undefined window longer and more likely to be hit by rapid clicks.
Likely Duplicate: This appears to be the same bug as #87784 ("RHP closes unexpectedly when navigating between expense reports using prev/next arrows"), which already has an identified root cause and is being worked on.
Recommended Fix: The removal-detection effect needs to distinguish between "report was deleted" and "route params changed and new report data hasn't loaded yet." One approach is to also check whether the
reportIDin route params changed — if it did, the undefined state is expected (navigation in progress) and dismissal should be skipped.Investigation details
The relevant code is in
App/src/pages/Search/SearchMoneyRequestReportPage.tsx:The
firstRenderRefguard only protects against the initial mount. It does not protect against subsequent navigations where the reportID changes but Onyx hasn't yet resolved the new report data.Next Steps: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.melvin-bot commentedon Apr 14, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @ahmedGaber93 (
External)[-][Exploratory] Reports - Modal closes when clicking Next during action flow[/-][+][$250] [Exploratory] Reports - Modal closes when clicking Next during action flow[/+]melvin-bot commentedon Apr 14, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022044065854848242190
wildan-m commentedon Apr 14, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
After refreshing the Reports page and opening any expense report, rapidly clicking the Next arrow in the report modal causes the modal to close unexpectedly instead of advancing through the remaining reports. The user is dropped back to the Reports list even though more reports are available. The problem is most reproducible immediately after a refresh or on a freshly loaded account where the Onyx cache is cold.
What is the root cause of that problem?
The Next/Prev arrows in
MoneyRequestReportNavigation.tsxswap the currently viewed report by updating the right-hand-panel route parameter viaNavigation.setParams({reportID: ...}). That causesSearchMoneyRequestReportPage.tsxto re-derivereportIDFromRouteand subscribeuseOnyxto a new report key. Until Onyx hands back data for the new key, thereportvalue is transientlyundefined.Right next to this lookup there is a "removal-detection" effect at lines 93–110 whose job is to dismiss the modal when the report the user was viewing gets deleted or merged. Its current condition is:
That condition is violated by a switch-in-progress: after
setParamsthe trackedreporttransiently becomes empty while theusePrevioussnapshot still contains the old money-request report. The effect therefore cannot tell "the currently viewed report was deleted" apart from "I am in the middle of navigating to a different report whose data has not landed yet," and in both cases it callsNavigation.dismissModal(). Visually, the modal just closes mid-click.The bug is aggravated right after a page refresh because the Onyx cache is empty, so the gap between the route change and the new report data arriving is longer and the effect has more opportunity to fire before Onyx catches up.
Note that the guard
firstRenderRefthat already exists in that effect only suppresses this behavior on the very first mount of the page — it does not help for subsequent in-place report switches driven by Next/Prev, which is exactly the flow exercised by this issue.What changes do you think we should make in order to solve the problem?
Tighten the removal-detection effect in
SearchMoneyRequestReportPage.tsxso that it only treats a missingreportas a real removal when the previously tracked report belongs to the same route the user is currently sitting on.Concretely: extend the existing condition with a check that the prior snapshot's
reportIDmatches the currentreportIDFromRoute. When the Next/Prev arrows change the route, the previous snapshot is for the old report, so itsreportIDwill not match the newreportIDFromRouteand the effect will skip dismissal — exactly the behavior we want while Onyx is still resolving the new key. When a user-visible report is actually deleted (or merged away), the route stays pinned to the samereportIDFromRoute, the prior snapshot'sreportIDstill matches it, and the original dismiss-on-removal flow continues to fire as before.reportIDFromRoutemust also be added to the effect's dependency array so the updated guard re-evaluates on every route switch.This is a minimal, surgical change localized to one effect in one file and preserves the original intent of the "member deletes an expense → show Not here" behavior that introduced the effect. It does not touch the Next/Prev navigation handler,
useOnyx, or anything about how the report list is fetched, so it has no effect on layouts, data loading, or offline behavior.Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/86496-reports-modal-closes-during-next-navigation?expand=1
What alternative solutions did you explore? (Optional)
firstRenderRefinto a generic "skip first render after route change" ref that resets wheneverreportIDFromRoutechanges. This works but adds a new ref and an extra effect to maintain it; the route-vs-prev-snapshot comparison is simpler and expresses the real invariant directly.melvin-bot commentedon Apr 17, 2026
@ahmedGaber93 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
ahmedGaber93 commentedon Apr 18, 2026
I agree with Melvin. This duplicate of #87784, the other issue was labeled as
Bugfirst, and callstack experts were assigned to work on it.@vincdargento, do you have the permission to close this issue, or should I ask internally?
melvin-bot commentedon Apr 21, 2026
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
ahmedGaber93 commentedon Apr 21, 2026
Asking on slack for closing this as duplicate https://expensify.slack.com/archives/C02NK2DQWUX/p1776796802510609
mallenexpensify commentedon Apr 21, 2026
Dupe, closing. Thx @ahmedGaber93