Skip to content

[Due for payment 2025-09-26] [$250] Reports - Infinite loading of deleted expense on report preview if deleting several expenses #68601

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.1.95-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail: https://test-management.browserstack.com/projects/2219752/test-runs/TR-289/folder/13176670/41237092/842125070
Email or phone of affected tester (no customers): ibellicotest+1606@gmail.com
Issue reported by: Applause Internal Team
Device used: Motorola MotoG60 / Android 12 / Chrome ( mWeb / Hybrid app) - Windows 10 / Chrome
App Component: Search

Action Performed:

Prerequisite: Account has at least one workspace available.

  1. Open the staging.new.expensify.com website.
  2. Open any workspace chat.
  3. Create three manual expenses.
  4. Navigate to "Reports" > "Expenses"
  5. Select and delete two of the created expenses.
  6. Return to workspace chat.
  7. Note that report preview shows the remaining expense details and also shows the preview of another expense, with infinite loading in it.

Expected Result:

Expenses deleted from a report, should automatically disappear from report preview and only the remaining ones should be visible.

Actual Result:

When deleting several expenses from a report while on "Reports" section and returning to workspace chat, one of the deleted expenses, still appears on report preview displaying infinite loading.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

bug.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021957222947228774567
  • Upwork Job ID: 1957222947228774567
  • Last Price Increase: 2025-08-31
Issue OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @jliexpensify

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Aug 15, 2025
  2. melvin-bot commented on Aug 15, 2025

    @melvin-bot

    Triggered auto assignment to @jliexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. lorretheboy commented on Aug 15, 2025

    @lorretheboy
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-08-25 15:53:44 UTC.

    Proposal

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

    Reports - Infinite loading of deleted expense on report preview if deleting several expenses

    What is the root cause of that problem?

    The deleteMoneyRequestOnSearch function only updated search snapshot loading states but didn't optimistically mark individual transactions as deleted. While the regular deleteMoneyRequest function properly sets pendingAction: DELETE on transactions
    The filtering logic in useReportWithTransactionsAndViolations only filters out transactions with pendingAction: DELETE when online. Without the DELETE pending action, deleted transactions remained visible in report previews until the server response arrived (But in this case, there is no data since it is already deleted)

    function deleteMoneyRequestOnSearch(hash: number, transactionIDList: string[]) {
    const {optimisticData, finallyData} = getOnyxLoadingData(hash);
    API.write(WRITE_COMMANDS.DELETE_MONEY_REQUEST_ON_SEARCH, {hash, transactionIDList}, {optimisticData, finallyData});
    }

    The reason why it doesn't happen on regular deletion process is that it is already handle the optimistically mark transactions as deleted

    value: {...transaction, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE},

    The regular deleteMoneyRequest sets pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE as well as sets transaction violations to null on the transaction immediately

    App/src/libs/actions/IOU.ts

    Lines 8155 to 8167 in 8fc238f

    const optimisticData: OnyxUpdate[] = [
    {
    onyxMethod: Onyx.METHOD.SET,
    key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
    value: {...transaction, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE},
    },
    ];
    optimisticData.push({
    onyxMethod: Onyx.METHOD.SET,
    key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`,
    value: null,
    });

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

    Updated the deleteMoneyRequestOnSearch function to optimistically mark transactions as deleted, similar to the regular deletion process

    function deleteMoneyRequestOnSearch(hash: number, transactionIDList: string[]) {
        const {optimisticData, finallyData} = getOnyxLoadingData(hash);
    
        const transactionOptimisticData: OnyxUpdate[] = transactionIDList.map((transactionID) => ({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
            value: {
                pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
            },
        }));
    
        const violationOptimisticData: OnyxUpdate[] = transactionIDList.map((transactionID) => ({
            onyxMethod: Onyx.METHOD.SET,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`,
            value: null,
        }));
    
        const allOptimisticData = [...optimisticData, ...transactionOptimisticData, ...violationOptimisticData];
    
        API.write(WRITE_COMMANDS.DELETE_MONEY_REQUEST_ON_SEARCH, {hash, transactionIDList}, {optimisticData: allOptimisticData, finallyData});
    }

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    NA

    What alternative solutions did you explore? (Optional)

    NA

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  4. thelullabyy commented on Aug 16, 2025

    @thelullabyy
    Contributor

    Proposal

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

    • When deleting multiple expenses from a report in the Reports section and then returning to the workspace chat, one of the deleted expenses still appears in the report preview and shows an infinite loading state.

    What is the root cause of that problem?

    • Deletions performed via the search flow correctly set the corresponding transactions_ entries to null in BE. However, the report preview is driven by reportTransactionsAndViolations, and the derived computation that updates this state after transactions_ changes is flawed:

      if (previousReportID && previousReportID !== reportID && reportTransactionsAndViolations[previousReportID]) {
      delete reportTransactionsAndViolations[previousReportID].transactions[transactionKey];
      const transactionID = previousTransaction?.transactionID;
      if (transactionID) {
      delete reportTransactionsAndViolations[previousReportID].violations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`];
      }
      }

    • Walkthrough:

    • In short: the logic that updates previousTransactions replaces the entire map, causing loss of historical entries needed to correctly detect deletions across successive compute passes.

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

    // Before:
    // previousTransactions = transactions;
    
    // After:
    previousTransactions = { ...previousTransactions, ...transactions };
    • With this change, previousTransactions preserves all known transaction keys and values while incorporating the newest snapshot.

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    • NA

    What alternative solutions did you explore? (Optional)

    • In here we can add logic to:
                if (transactionsUpdates?.[transactionKey] === undefined) {
                    // Find which report currently contains this transactionKey in currentValue
                    for (const [reportID, bucket] of Object.entries(reportTransactionsAndViolations)) {
                        if (bucket?.transactions && transactionKey in bucket.transactions) {
                            delete reportTransactionsAndViolations[reportID].transactions[transactionKey];
                        }
                    }
                  
                }

    It checks whether the transaction has been deleted, locates the report that contains it, and then removes the transaction from that report.

  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Aug 17, 2025
  6. changed the title [-]Reports - Infinite loading of deleted expense on report preview if deleting several expenses[/-] [+][$250] Reports - Infinite loading of deleted expense on report preview if deleting several expenses[/+] on Aug 17, 2025
  7. melvin-bot commented on Aug 17, 2025

    @melvin-bot
  8. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Aug 17, 2025
  9. melvin-bot commented on Aug 17, 2025

    @melvin-bot

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

  10. 64 remaining items

  11. jjcoffee commented on Sep 26, 2025

    @jjcoffee
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [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/65247/files#r2381349576

    • [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: N/A

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

    Regression Test Proposal

    Test:

    1. Create 3 expenses in a workspace chat
    2. Open Report > Expenses
    3. Delete 2 of the expenses
    4. Go back to WS chat
    5. Verify there is no extra expense with skeleton on the report preview

    Do we agree 👍 or 👎

  12. melvin-bot commented on Sep 26, 2025

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@jliexpensify)

    • (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/1957222947228774567/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. jliexpensify commented on Sep 28, 2025

    @jliexpensify
    Contributor

    Payment Summary

  14. lorretheboy commented on Sep 29, 2025

    @lorretheboy
    Contributor

    Actually, my solution can fixed the issue mentioning in this OP. However, after I open PR, we decided to fix another related issue so we go with @bernhardoj solution since it is more completed.

    @jliexpensify May I ask if it makes sense to me to get full payment? Thank you

  15. jliexpensify commented on Sep 29, 2025

    @jliexpensify
    Contributor

    Got it, thanks for the extra context - in this case, since your PR solves the original issue and you did open a PR, that is fine!

  16. jliexpensify commented on Sep 29, 2025

    @jliexpensify
    Contributor
  17. lorretheboy commented on Sep 29, 2025

    @lorretheboy
    Contributor

    Thanks @jliexpensify, I have approved it

  18. jliexpensify commented on Sep 29, 2025

    @jliexpensify
    Contributor

    Paid, job closed.

    Payment Summary

  19. bernhardoj commented on Sep 29, 2025

    @bernhardoj
    Contributor

    Requested in ND.

  20. trjExpensify commented on Sep 29, 2025

    @trjExpensify
    Contributor

    approved $250 for @bernhardoj.

  21. trjExpensify commented on Sep 30, 2025

    @trjExpensify
    Contributor

    approved $250 for @jjcoffee

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