Skip to content

[$250] [Exploratory] Reports - Modal closes when clicking Next during action flow #86496

Closed

Description

@vincdargento

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

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

bug.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @ahmedGaber93
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022044065854848242190
  • Upwork Job ID: 2044065854848242190
  • Last Price Increase: 2026-04-21

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    and removed on Apr 14, 2026
  2. MelvinBot commented on Apr 14, 2026

    @MelvinBot
    Contributor

    Issue Analysis

    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:

    // Lines 93-110
    useEffect(() => {
        if (firstRenderRef.current) {
            firstRenderRef.current = false;
            return;
        }
        const isRemovalExpectedForReportType = !report && isMoneyRequestReport(prevReport);
        if (isRemovalExpectedForReportType) {
            if (!isFocused) {
                return;
            }
            Navigation.dismissModal();
        }
    }, [report, isFocused, prevReport]);

    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.

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

    @melvin-bot

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

  6. 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
  7. melvin-bot commented on Apr 14, 2026

    @melvin-bot
  8. wildan-m commented on Apr 14, 2026

    @wildan-m
    Contributor

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

    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)

    • 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.
  9. melvin-bot commented on Apr 17, 2026

    @melvin-bot

    @ahmedGaber93 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  10. ahmedGaber93 commented on Apr 18, 2026

    @ahmedGaber93
    Contributor

    I agree with Melvin. This duplicate of #87784, the other issue was labeled as Bug first, and callstack experts were assigned to work on it.

    @vincdargento, do you have the permission to close this issue, or should I ask internally?

  11. melvin-bot commented on Apr 21, 2026

    @melvin-bot

    📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

  12. ahmedGaber93 commented on Apr 21, 2026

    @ahmedGaber93
    Contributor

    Asking on slack for closing this as duplicate https://expensify.slack.com/archives/C02NK2DQWUX/p1776796802510609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions