Skip to content

[Due for payment 2026-01-15] [Due for payment 2026-01-07] [$250] Reports page - The App crashes when switching from withdrawal-id grouping to any other grouping via the dropdown #78278

Closed

Description

@izarutskaya

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.2.85-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @JS00001
Slack conversation (hyperlinked to channel name): #expensify_bugs

Action Performed:

Prerequisites: Need using account with a lot of withdrawal-id expenses

  1. Go to https://staging.new.expensify.com/
  2. Navigate to Reports > in Search type:expense group-by:withdrawal-id
  3. Click "Group by" filter > switch the from withdrawal-id to from > Apply

Expected Result:

User can switch from withdrawal-id to from

Actual Result:

The app crashes

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

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

Screenshots/Videos

Recording.3544.mp4
Image

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022003109092606784237
  • Upwork Job ID: 2003109092606784237
  • Last Price Increase: 2025-12-22
  • Automatic offers:
    • linhvovan29546 | Reviewer | 109902138
    • daledah | Contributor | 109902140
Issue OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @sonialiap

Activity

  1. added
    Daily
    Bug
    on Dec 22, 2025
  2. melvin-bot commented on Dec 22, 2025

    @melvin-bot

    Triggered auto assignment to @sonialiap (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. abbasifaizan70 commented on Dec 22, 2025

    @abbasifaizan70
    Contributor

    Proposal

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

    The app crashes when switching the "Group by" filter from "withdrawal-id" to "from" (or any other groupBy value).

    What is the root cause of that problem?

    The isSearchDataLoaded function in App/src/libs/SearchUIUtils.ts only checks if the type and status match between the search results and the current query. It does not verify that the groupBy parameter also matches.

    This causes a race condition:

    1. User changes groupBy from "withdrawal-id" to "from"
    2. The queryJSON is updated with the new groupBy value
    3. The search results still contain old data (grouped by withdrawal-id)
    4. isSearchDataLoaded returns true because it only checks type and status
    5. The component tries to process withdrawal-id grouped data using the "from" groupBy logic
    6. The getMemberSections function expects data with accountID properties
    7. But it receives SearchWithdrawalIDGroup objects with entryID and accountNumber properties instead
    8. This causes a crash when accessing undefined properties

    Current code:

    https://github.com/Expensify/App/blob/main/src/libs/SearchUIUtils.ts#L2884-L2895

    function isSearchDataLoaded(searchResults: SearchResults | undefined, queryJSON: SearchQueryJSON | undefined) {
        const {status} = queryJSON ?? {};
    
        const sortedSearchResultStatus = !Array.isArray(searchResults?.search?.status)
            ? searchResults?.search?.status?.split(',').sort().join(',')
            : searchResults?.search?.status?.sort().join(',');
        const sortedQueryJSONStatus = Array.isArray(status) ? status.sort().join(',') : status;
        const isDataLoaded = searchResults?.data !== undefined && searchResults?.search?.type === queryJSON?.type && sortedSearchResultStatus === sortedQueryJSONStatus;
        // ❌ Missing check: groupBy is not validated
    
        return isDataLoaded;
    }

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

    1. Add groupBy property to SearchResultsInfo type

    https://github.com/Expensify/App/blob/main/src/types/onyx/SearchResults.ts#L39-L70

    type SearchResultsInfo = {
        offset: number;
        type: SearchDataTypes;
        status: SearchStatus;
        groupBy?: string;  // ✅ Add this property
        hasMoreResults: boolean;
        hasResults: boolean;
        isLoading: boolean;
        count?: number;
        total?: number;
        currency?: string;
    };

    2. Create helper function to detect groupBy from data structure

    https://github.com/Expensify/App/blob/main/src/libs/SearchUIUtils.ts#L2884

    Since the backend doesn't return groupBy, we need to detect it from the data structure:

    function detectGroupByFromData(data: SearchResults['data'] | undefined): SearchGroupBy | null | undefined {
        if (!data) {
            return undefined;
        }
    
        let hasAnyData = false;
        let hasGroupEntries = false;
    
        for (const key in data) {
            if (key === 'personalDetailsList') {
                continue;
            }
    
            hasAnyData = true;
    
            if (isGroupEntry(key)) {
                hasGroupEntries = true;
                const groupData = data[key] as SearchMemberGroup | SearchCardGroup | SearchWithdrawalIDGroup;
    
                // Check for withdrawal ID group (has entryID and accountNumber)
                if ('entryID' in groupData && 'accountNumber' in groupData) {
                    return CONST.SEARCH.GROUP_BY.WITHDRAWAL_ID;
                }
    
                // Check for card group (has cardID)
                if ('cardID' in groupData) {
                    return CONST.SEARCH.GROUP_BY.CARD;
                }
    
                // Check for member group (has accountID but no cardID or entryID)
                if ('accountID' in groupData) {
                    return CONST.SEARCH.GROUP_BY.FROM;
                }
            }
        }
    
        // If there's data but no group entries, return null (ungrouped search)
        if (hasAnyData && !hasGroupEntries) {
            return null;
        }
    
        // No data yet
        return undefined;
    }

    3. Update isSearchDataLoaded function

    https://github.com/Expensify/App/blob/main/src/libs/SearchUIUtils.ts#L2917

    function isSearchDataLoaded(searchResults: SearchResults | undefined, queryJSON: SearchQueryJSON | undefined) {
        const {status, groupBy} = queryJSON ?? {};
    
        const sortedSearchResultStatus = !Array.isArray(searchResults?.search?.status)
            ? searchResults?.search?.status?.split(',').sort().join(',')
            : searchResults?.search?.status?.sort().join(',');
        const sortedQueryJSONStatus = Array.isArray(status) ? status.sort().join(',') : status;
    
        // Basic type and status check
        const basicMatch = searchResults?.data !== undefined && searchResults?.search?.type === queryJSON?.type && sortedSearchResultStatus === sortedQueryJSONStatus;
    
        if (!basicMatch) {
            return false;
        }
    
        // Detect the groupBy from the data structure if backend doesn't provide it
        const detectedGroupBy = detectGroupByFromData(searchResults?.data);
        const dataGroupBy = searchResults?.search?.groupBy ?? detectedGroupBy;
    
        // If we can't detect groupBy (returns undefined), the data is empty
        // Empty data is safe to display - no crash risk
        if (detectedGroupBy === undefined) {
            return true;
        }
    
        // Verify groupBy matches
        const normalizedQueryGroupBy = groupBy ?? null;
        const normalizedDataGroupBy = dataGroupBy ?? null;
    
        return normalizedDataGroupBy === normalizedQueryGroupBy;
    }

    What alternative solutions did you explore? (Optional)

    None

    Demo

    Image
  4. self-assigned this
    on Dec 22, 2025
  5. added
    External
    Help Wanted
    on Dec 22, 2025
  6. changed the title [-]Reports page - The App crashes when switching from `withdrawal-id` grouping to any other grouping via the dropdown[/-] [+][$250] Reports page - The App crashes when switching from `withdrawal-id` grouping to any other grouping via the dropdown[/+] on Dec 22, 2025
  7. melvin-bot commented on Dec 22, 2025

    @melvin-bot
  8. melvin-bot commented on Dec 22, 2025

    @melvin-bot

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

  9. daledah commented on Dec 22, 2025

    @daledah
    Contributor

    Proposal

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

    The app crashes

    What is the root cause of that problem?

    In getMemberSections and getCardSections, the code accessed data.personalDetailsList[accountID] without checking if personalDetailsList exists. When switching groupBy, personalDetailsList can be undefined, causing a crash.

    App/src/libs/SearchUIUtils.ts

    Lines 1912 to 1913 in 5685a5f

    const cardGroup = data[key] as SearchCardGroup;
    const personalDetails = data.personalDetailsList[cardGroup.accountID];

    App/src/libs/SearchUIUtils.ts

    Lines 1871 to 1872 in 5685a5f

    const memberGroup = data[key] as SearchMemberGroup;
    const personalDetails = data.personalDetailsList[memberGroup.accountID];

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

    We should add optional chaining and a fallback to emptyPersonalDetails in both functions like we did with other functions here, here, ...

         const personalDetails = data.personalDetailsList?.[memberGroup.accountID] ?? emptyPersonalDetails;
    

    App/src/libs/SearchUIUtils.ts

    Lines 1871 to 1872 in 5685a5f

    const memberGroup = data[key] as SearchMemberGroup;
    const personalDetails = data.personalDetailsList[memberGroup.accountID];

         const personalDetails = data.personalDetailsList?.[cardGroup.accountID] ?? emptyPersonalDetails;
    

    App/src/libs/SearchUIUtils.ts

    Lines 1912 to 1913 in 5685a5f

    const cardGroup = data[key] as SearchCardGroup;
    const personalDetails = data.personalDetailsList[cardGroup.accountID];

    What alternative solutions did you explore? (Optional)

    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.

  10. linhvovan29546 commented on Dec 23, 2025

    @linhvovan29546
    Contributor

    Thanks for the proposals I think @daledah's proposal is correct. Since personalDetailsList is can be undefinedbut the current type doesn't allow it, so i think we should update the personalDetailsList type to support undefined as well. This will help catch the crash earlier.

    Record<typeof ONYXKEYS.PERSONAL_DETAILS_LIST, Record<string, PersonalDetails>> &

    Record<typeof ONYXKEYS.PERSONAL_DETAILS_LIST, Record<string, PersonalDetails> | undefined> &

    🎀 👀 🎀 C+ reviewed

  11. 28 remaining items

  12. daledah commented on Jan 6, 2026

    @daledah
    Contributor

    @linhvovan29546 we have the follow up PR here

  13. added
    Daily
    Weekly
    and removed
    Weekly
    Daily
    on Jan 6, 2026
  14. changed the title [-][Due for payment 2026-01-07] [$250] Reports page - The App crashes when switching from `withdrawal-id` grouping to any other grouping via the dropdown[/-] [+][Due for payment 2026-01-15] [Due for payment 2026-01-07] [$250] Reports page - The App crashes when switching from `withdrawal-id` grouping to any other grouping via the dropdown[/+] on Jan 8, 2026
  15. removed
    Reviewing
    on Jan 8, 2026
  16. melvin-bot commented on Jan 8, 2026

    @melvin-bot

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

  17. melvin-bot commented on Jan 8, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.2.95-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 2026-01-15. 🎊

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

  18. melvin-bot commented on Jan 8, 2026

    @melvin-bot

    @linhvovan29546 @sonialiap 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]

  19. linhvovan29546 commented on Jan 14, 2026

    @linhvovan29546
    Contributor

    BugZero Checklist:

    • [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/67802/changes#r2690428215

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

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

    Regression Test Proposal

    Precondition:

    • Need using account with a lot of withdrawal-id expenses

    Test:

    1. Open ND
    2. Navigate to Reports > in Search type:expense group-by:withdrawal-id
    3. Click "Group by" filter > switch the from withdrawal-id to From or Card > Apply
    4. Verify that: User can switch from withdrawal-id to From or Card

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-56a7-a53f-a203-24190c175814
  20. sonialiap commented on Jan 15, 2026

    @sonialiap
    Contributor

    Payment summary:
    @linhvovan29546 $250 paid in upwork
    @daledah $250 paid in upwork

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

Metadata

Metadata

Labels

Awaiting PaymentBugExternalWeekly

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions