Skip to content

[Due for payment 2025-09-19] [$250] Reports - Deleted expense is unselected before disappearing #66028

Closed

Description

@mitarachim

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.80-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: #65727
Email or phone of affected tester (no customers): N/A
Issue reported by: Applause Internal Team
Device used: Samsung Galaxy A52s 5G / Android 14, Apple iPhone 12 Pro / iOS 18.5
App Component: Search

Action Performed:

  1. Open the app
  2. Log in with a new expensifail account
  3. Tap on "Reports"
  4. Tap on FAB - Create expense - Manual
  5. Create an expense with a Gmail account
  6. Select the expense
  7. Tap on the "1 selected" button
  8. Tap on "Delete"
  9. Tap on the "Delete" button

Expected Result:

Deleted expense should disappear instantly.

Actual Result:

Deleted expense is unselected before disappearing.

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

Bug6885109_1752264729853.az_recorder_20250711_220103.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021945012587501504085
  • Upwork Job ID: 1945012587501504085
  • Last Price Increase: 2025-07-22
Issue OwnerCurrent Issue Owner: @lydiabarclay

Activity

  1. added
    Daily
    Bug
    on Jul 14, 2025
  2. melvin-bot commented on Jul 14, 2025

    @melvin-bot

    Triggered auto assignment to @lydiabarclay (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. mohammadjafarinejad commented on Jul 14, 2025

    @mohammadjafarinejad
    Contributor

    Proposal

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

    Deleted expense is unselected before disappearing.

    What is the root cause of that problem?

    The deleteMoneyRequestOnSearch() function does not optimistically update the transaction list.

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

    Also, we clear the selection immediately after the user confirms deletion, but the item stays on the screen until the backend responds. This causes a brief moment where the item is deselected but still visible.

    deleteMoneyRequestOnSearch(hash, selectedTransactionsKeys);
    // Translations copy for delete modal depends on amount of selected items,
    // We need to wait for modal to fully disappear before clearing them to avoid translation flicker between singular vs plural
    InteractionManager.runAfterInteractions(() => {
    clearSelectedTransactions();
    });

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

    We can update the deleteMoneyRequestOnSearch() to include optimistic data:

    function deleteMoneyRequestOnSearch(hash: number, transactionIDList: string[]) {
        const {optimisticData, failureData, finallyData} = getOnyxLoadingData(hash);
    
        const createOnyxData = (update: Partial<SearchTransaction> | Partial<SearchReport>): OnyxUpdate[] => [
            {
                onyxMethod: Onyx.METHOD.MERGE,
                key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`,
                value: {
                    data: Object.fromEntries(
                        transactionIDList.map((transactionID) => [
                            `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
                            update,
                        ])
                    ) as Partial<SearchTransaction>,
                },
            },
        ];
    
        optimisticData.push(...createOnyxData({pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}));
        finallyData.push(...createOnyxData({pendingAction: null}));
    
        API.write(WRITE_COMMANDS.DELETE_MONEY_REQUEST_ON_SEARCH, {hash, transactionIDList}, {optimisticData, failureData});
    }

    Also we should call deleteMoneyRequestOnSearch() next to clearSelectedTransactions(), so both updates happens at the same time

    InteractionManager.runAfterInteractions(() => {
        deleteMoneyRequestOnSearch(hash, selectedTransactionsKeys);
        clearSelectedTransactions();
    });

    If we want deleted items (those with pendingAction) to disappear from the search results immediately, I believe that’s already being handled in this PR. If not, we can handle it here after that PR is merged.

    Here’s a demo of the fix:

    Fix.66028.mp4

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

    What alternative solutions did you explore? (Optional)

    • Delaying the clearing of selection until after backend confirmation.
  4. bernhardoj commented on Jul 14, 2025

    @bernhardoj
    Contributor

    Proposal

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

    When deleting expense from search, the item is deselected first for a while before it's removed from the list.

    What is the root cause of that problem?

    We currently only optimistically update the loading data.

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

    Even though we already wrap the clearSelectedTransactions in runAfterInteractions, it's still executed earlier before the API response that delete the transaction data from the snapshot.

    const handleDeleteExpenses = () => {
    if (selectedTransactionsKeys.length === 0 || !hash) {
    return;
    }
    setIsDeleteExpensesConfirmModalVisible(false);
    deleteMoneyRequestOnSearch(hash, selectedTransactionsKeys);
    // Translations copy for delete modal depends on amount of selected items,
    // We need to wait for modal to fully disappear before clearing them to avoid translation flicker between singular vs plural
    InteractionManager.runAfterInteractions(() => {
    clearSelectedTransactions();
    });
    };

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

    First, we need to optimistically update the transaction data in the snapshot.

    const {optimisticData: loadingOptimisticData, finallyData} = getOnyxLoadingData(hash);
    const optimisticData: OnyxUpdate[] = [
        ...loadingOptimisticData,
        {
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`,
            value: { 
                data:Object.fromEntries(transactionIDList.map((transactionID) => [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}])) as Partial<SearchTransaction>
            },
        },
    ]

    (and the failure data that removes the pending action when fail)

    Next, we need to move deleteMoneyRequestOnSearch inside the runAfterInteractions too, otherwise, the expense is deleted earlier before the item is unselected (which will show 1 selected even though the expense is not shown anymore).

    const handleDeleteExpenses = () => {
    if (selectedTransactionsKeys.length === 0 || !hash) {
    return;
    }
    setIsDeleteExpensesConfirmModalVisible(false);
    deleteMoneyRequestOnSearch(hash, selectedTransactionsKeys);
    // Translations copy for delete modal depends on amount of selected items,
    // We need to wait for modal to fully disappear before clearing them to avoid translation flicker between singular vs plural
    InteractionManager.runAfterInteractions(() => {
    clearSelectedTransactions();
    });
    };

    Last, we need to update isSearchResultsEmpty to filter out pending delete transactions.

    function isSearchResultsEmpty(searchResults: SearchResults) {
        return !Object.values(searchResults?.data).some((data) => 'transactionID' in data && (data as SearchTransaction)?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
    }
    

    With all these changes, when deleting expense, the empty view will show immediately (when no expense left)

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

    We can test Search.deleteMoneyRequestOnSearch and assert all the transaction pendingAction is set to delete

  5. added
    External
    on Jul 15, 2025
  6. melvin-bot commented on Jul 15, 2025

    @melvin-bot
  7. changed the title [-]Reports - Deleted expense is unselected before disappearing[/-] [+][$250] Reports - Deleted expense is unselected before disappearing[/+] on Jul 15, 2025
  8. added
    Help Wanted
    on Jul 15, 2025
  9. Beamanator commented on Jul 15, 2025

    @Beamanator
    Contributor

    Looks like an external issue! (sorry for randomly popping in 😅 )

  10. melvin-bot commented on Jul 15, 2025

    @melvin-bot

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

  11. hoangzinh commented on Jul 17, 2025

    @hoangzinh
    Contributor

    Thank you for posting proposals, @bernhardoj @mohammadjafarinejad. I will review them soon

  12. 70 remaining items

  13. added
    Daily
    and removed
    Weekly
    on Sep 18, 2025
  14. lydiabarclay commented on Sep 19, 2025

    @lydiabarclay
    Contributor

    Payment Summary

    Contributor: @bernhardoj due $250 via NewDot
    Contributor+: @hoangzinh due $250 via NewDot

    ✅ Regression test filed

  15. melvin-bot commented on Sep 19, 2025

    @melvin-bot

    Issue is ready for payment but no BZ is assigned. @OfstadC you are the lucky winner! Please verify the payment summary looks correct and complete the checklist. Thanks!

  16. deleted a comment from melvin-bot on Sep 19, 2025
  17. bernhardoj commented on Sep 20, 2025

    @bernhardoj
    Contributor

    Requested in ND.

  18. hoangzinh commented on Sep 22, 2025

    @hoangzinh
    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/44385/files#r2368969588

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

      It's small UX issue that I think we don't need a regression test for it.

  19. hoangzinh commented on Sep 22, 2025

    @hoangzinh
    Contributor

    Thanks @lydiabarclay. I requested in ND

  20. quinthar commented on Oct 12, 2025

    @quinthar
    Contributor

    Approved $250 to @bernhardoj

  21. quinthar commented on Oct 18, 2025

    @quinthar
    Contributor

    Approved $250 to @hoangzinh

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

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions