Skip to content

[Due for payment 2025-08-19] [$250] Search - Expense report is displayed as "Deleted report" in Recent chats list #65253

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.73-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://expensify.testrail.io/index.php?/tests/view/6406704
Email or phone of affected tester (no customers): sddsoisjndosjo@gmail.com
Issue reported by: Applause Internal Team
Device used: Mac 15.5 / Chrome
App Component: Search

Action Performed:

Precondition:

  • Disable all the features in Workflows.
  • Admin invites member to the workspace.
  1. Go to staging.new.expensify.com
  2. [Member] Go to workspace chat.
  3. [Member] Submit an expense to the workspace chat.
  4. [Admin] Click search icon on the top right.

Expected Result:

Expense report will show the report title in Recent chats list.

Actual Result:

Expense report is displayed as "Deleted report" in Recent chats list.

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

Bug6874751_1751376363892.20250701_212248.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021944684972626962129
  • Upwork Job ID: 1944684972626962129
  • Last Price Increase: 2025-07-21
  • Automatic offers:
    • thelullabyy | Contributor | 108210390
Issue OwnerCurrent Issue Owner: @dylanexpensify

Activity

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

    @melvin-bot

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

    @dylanexpensify
    Contributor

    reviewing!

  4. thelullabyy commented on Jul 2, 2025

    @thelullabyy
    Contributor

    Proposal

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

    Expense report is displayed as "Deleted report" in Recent chats list.

    What is the root cause of that problem?

    Here is the place that we generate recent chats list

    useEffect(() => {
    if (!changedReportActions || !areOptionsInitialized.current) {
    return;
    }
    setOptions((prevOptions) => {
    const changedReportActionsEntries = Object.entries(changedReportActions);
    if (changedReportActionsEntries.length === 0) {
    return prevOptions;
    }
    const updatedReportsMap = new Map(prevOptions.reports.map((report) => [report.reportID, report]));
    changedReportActionsEntries.forEach(([key, reportAction]) => {
    if (!reportAction) {
    return;
    }
    const reportID = key.replace(ONYXKEYS.COLLECTION.REPORT_ACTIONS, '');
    const {reportOption} = processReport(updatedReportsMap.get(reportID)?.item, personalDetails);
    if (reportOption) {
    updatedReportsMap.set(reportID, reportOption);
    }
    });
    return {
    ...prevOptions,
    reports: Array.from(updatedReportsMap.values()),
    };
    });
    }, [changedReportActions, personalDetails]);

    The title of expense report is generate wrong by the below function since transactions value at the time it is triggered is not up to date. Therefore, it returns Deleted report

    function isClosedExpenseReportWithNoExpenses(report: OnyxEntry<Report>, transactions?: SearchTransaction[] | Array<OnyxEntry<Transaction>>): boolean {

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

    We need to add transactions value as dependency of the useEffect that handle reports changes and then pass down to the function isClosedExpenseReportWithNoExpenses where the bug occurs.
    The transactions value should be from the parent component instead of using Onyx.connect. Here is how we get the transactions value

        const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true});

    }, [changedReportActions, personalDetails]);

    Also we need to update the hook to get option list value, we should update the function shallowOptionsListCompare to have deep compare, so that the recent chats list component can re-render to show latest display value of report

    useEffect(() => {
    if (!prevOptions.current) {
    prevOptions.current = optionsList;
    setInternalOptions(optionsList);
    return;
    }
    /**
    * optionsList reference can change multiple times even the value of its arrays is the same. We perform shallow comparison to check if the options have truly changed.
    * This is necessary to avoid unnecessary re-renders in components that use this context.
    */
    const areOptionsEqual = shallowOptionsListCompare(prevOptions.current, optionsList);
    prevOptions.current = optionsList;
    if (areOptionsEqual) {
    return;
    }
    setInternalOptions(optionsList);
    }, [optionsList]);

        for (let i = 0; i < a.reports.length; i++) {
            const aReport = a.reports.at(i);
            const bReport = b.reports.at(i);
            if (aReport?.reportID !== bReport?.reportID || aReport?.text !== bReport?.text) {
                return false;
            }
        }

    for (let i = 0; i < a.reports.length; i++) {
    if (a.reports.at(i)?.reportID !== b.reports.at(i)?.reportID) {
    return false;
    }

    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.

  5. nabi-ebrahimi commented on Jul 3, 2025

    @nabi-ebrahimi

    🚨 Edited by proposal-police: This proposal was edited at 2025-07-21 12:06:12 UTC.

    Proposal

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

    Search - Expense report is displayed as "Deleted report" in Recent chats list

    What is the root cause of that problem?

    The first time, focus on the browser tap and click on search, the newest transaction is not loaded yet. inside getReportNameInternal function, this condition is true.

    App/src/libs/ReportUtils.ts

    Lines 5225 to 5227 in 11ff1d3

    if (isClosedExpenseReportWithNoExpenses(report, transactions)) {
    return translateLocal('parentReportAction.deletedReport');
    }

    Because the transaction with the specified reportID is not loaded yet. so hasExpenses return false

    App/src/libs/ReportUtils.ts

    Lines 2021 to 2036 in 11ff1d3

    /**
    * Whether the provided report has expenses
    */
    function hasExpenses(reportID?: string, transactions?: SearchTransaction[]): boolean {
    if (transactions) {
    return !!transactions?.find((transaction) => transaction?.reportID === reportID);
    }
    return !!Object.values(allTransactions ?? {}).find((transaction) => transaction?.reportID === reportID);
    }
    /**
    * Whether the provided report is a closed expense report with no expenses
    */
    function isClosedExpenseReportWithNoExpenses(report: OnyxEntry<Report>, transactions?: SearchTransaction[]): boolean {
    return report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED && isExpenseReport(report) && !hasExpenses(report.reportID, transactions);
    }

    So, it shows Deleted Report

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

    We should update the recentOptionList when a new transaction is loaded.

    useEffect(() => {
    if (!changedReportActions || !areOptionsInitialized.current) {
    return;
    }
    setOptions((prevOptions) => {
    const changedReportActionsEntries = Object.entries(changedReportActions);
    if (changedReportActionsEntries.length === 0) {
    return prevOptions;
    }
    const updatedReportsMap = new Map(prevOptions.reports.map((report) => [report.reportID, report]));
    changedReportActionsEntries.forEach(([key, reportAction]) => {
    if (!reportAction) {
    return;
    }
    const reportID = key.replace(ONYXKEYS.COLLECTION.REPORT_ACTIONS, '');
    const {reportOption} = processReport(updatedReportsMap.get(reportID)?.item, personalDetails);
    if (reportOption) {
    updatedReportsMap.set(reportID, reportOption);
    }
    });
    return {
    ...prevOptions,
    reports: Array.from(updatedReportsMap.values()),
    };
    });
    }, [changedReportActions, personalDetails]);

    We can get the length of transactions and add it as a dependency to the above useEffect. So when a new transaction is added, the recent options are updated as well.

        const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true});
    
    
      useEffect(() => {
            if (!changedReportActions || !areOptionsInitialized.current) {
                return;
            }
    
            setOptions((prevOptions) => {
                const changedReportActionsEntries = Object.entries(changedReportActions);
                if (changedReportActionsEntries.length === 0) {
                    return prevOptions;
                }
    
                const updatedReportsMap = new Map(prevOptions.reports.map((report) => [report.reportID, report]));
                changedReportActionsEntries.forEach(([key, reportAction]) => {
                    if (!reportAction) {
                        return;
                    }
    
                    const reportID = key.replace(ONYXKEYS.COLLECTION.REPORT_ACTIONS, '');
                    const {reportOption} = processReport(updatedReportsMap.get(reportID)?.item, personalDetails);
    
                    if (reportOption) {
                        updatedReportsMap.set(reportID, reportOption);
                    }
                });
    
                return {
                    ...prevOptions,
                    reports: Array.from(updatedReportsMap.values()),
                };
            });
        }, [changedReportActions, personalDetails, Object.keys(transactions ?? {}).length]);
    

    If the search list is already open, it still shows the Deleted Report. Therefore, we need to check both the report text and reportID in the shallowOptionsListCompare function.

    for (let i = 0; i < a.reports.length; i++) {
    if (a.reports.at(i)?.reportID !== b.reports.at(i)?.reportID) {
    return false;
    }

    update to this

        for (let i = 0; i < a.reports.length; i++) {
            if (a.reports.at(i)?.reportID !== b.reports.at(i)?.reportID || a.reports.at(i)?.text !== b.reports.at(i)?.text) {
                return false;
            }
        }

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

    None

    What alternative solutions did you explore? (Optional)

    Demo

    searched-compressed-record.mp4
  6. melvin-bot commented on Jul 7, 2025

    @melvin-bot

    @dylanexpensify Eep! 4 days overdue now. Issues have feelings too...

  7. dylanexpensify commented on Jul 9, 2025

    @dylanexpensify
    Contributor

    Confirming behavior internally

  8. dylanexpensify commented on Jul 11, 2025

    @dylanexpensify
    Contributor

    posted to confirm

  9. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jul 14, 2025
  10. 31 remaining items

  11. changed the title [-][$250] Search - Expense report is displayed as "Deleted report" in Recent chats list[/-] [+][Due for payment 2025-08-19] [$250] Search - Expense report is displayed as "Deleted report" in Recent chats list[/+] on Aug 12, 2025
  12. melvin-bot commented on Aug 12, 2025

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  13. melvin-bot commented on Aug 12, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.1.92-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-08-19. 🎊

    For reference, here are some details about the assignees on this issue:

  14. melvin-bot commented on Aug 12, 2025

    @melvin-bot

    @alitoshmatov @dylanexpensify The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  15. dylanexpensify commented on Aug 18, 2025

    @dylanexpensify
    Contributor

    Tomorrow!

  16. alitoshmatov commented on Aug 18, 2025

    @alitoshmatov
    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: Couldn't pinpoint exact PR since it was hard to catch, transactions dependency technically wasn't required for that useEffect

    • [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: No discussion was started

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

    I don't think this requires regression, very edge case.

  17. dylanexpensify commented on Aug 19, 2025

    @dylanexpensify
    Contributor

    Payment summary:

    Contributor: @thelullabyy $250 via Upwork
    Contributor+: @alitoshmatov $250 via NewDot

    Please apply/request!

  18. garrettmknight commented on Aug 20, 2025

    @garrettmknight
    Contributor

    $250 approved for @alitoshmatov

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