Skip to content

[$250] Reports - List does not load more messages when scrolled to the end of list on Reports > Chats #72521

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.2.30-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/TR-1266/41237507/950564907?q=chats&issue_type=jira
Email or phone of affected tester (no customers): applausetester+khcategory19@applause.expensifail.com
Issue reported by: Applause Internal Team
Device used: Mac 15.5 / Chrome
App Component: Search

Action Performed:

Precondition:

  • Account has many messages or expenses.
  1. Go to staging.new.expensify.com
  2. Go to Reports > Chats.
  3. Scroll to the end of the list.

Expected Result:

The list will load more messages.

Actual Result:

The list does not load more messages when scrolled to the end of 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

Bug6974073_1760402130007.Screen_Recording_2025-10-14_at_08.23.41.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021978213110993190254
  • Upwork Job ID: 1978213110993190254
  • Last Price Increase: 2025-10-14
  • Automatic offers:
    • FitseTLT | Reviewer | 109518007
Issue OwnerCurrent Issue Owner: @bernhardoj

Activity

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

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (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. changed the title [-]Reports - List does not load more messages when scrolled to the end of list on Reports > Cha[/-] [+]Reports - List does not load more messages when scrolled to the end of list on Reports > Chats[/+] on Oct 14, 2025
  4. dmkt9 commented on Oct 14, 2025

    @dmkt9
    Contributor

    Proposal

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

    The list does not load more messages when scrolled to the end of list.

    What is the root cause of that problem?

    1. When scrolling to the end of the list, the fetchMoreResults function is triggered to fetch more data.

      const fetchMoreResults = useCallback(() => {

    2. However, inside fetchMoreResults, the condition offset > data.length - CONST.SEARCH.RESULTS_PAGE_SIZE is used for checking:

      if (!isFocused || !searchResults?.search?.hasMoreResults || shouldShowLoadingState || shouldShowLoadingMoreItems || offset > data.length - CONST.SEARCH.RESULTS_PAGE_SIZE) {
      return;
      }

      This condition relies on data.length, but data.length only reflects the number of items currently displayed—not the number of items on the server. That means if some items aren’t actually rendered, the condition will always evaluate as true. As a result, no additional data will ever be fetched.

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

    We already have the value searchResults?.search?.hasMoreResults, so the condition offset > data.length - CONST.SEARCH.RESULTS_PAGE_SIZE is no longer necessary. We can remove it.

  5. bernhardoj commented on Oct 14, 2025

    @bernhardoj
    Contributor

    Proposal

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

    Chat page doesn't load more when reaches bottom.

    What is the root cause of that problem?

    This happen because the offset is bigger than the data length (minus 50). This is so that the search won't be triggered if the offset is already increased but the new data is not fetched yet.

    const fetchMoreResults = useCallback(() => {
    // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
    if (!isFocused || !searchResults?.search?.hasMoreResults || shouldShowLoadingState || shouldShowLoadingMoreItems || offset > data.length - CONST.SEARCH.RESULTS_PAGE_SIZE) {
    return;
    }
    setOffset((prev) => prev + CONST.SEARCH.RESULTS_PAGE_SIZE);

    Each time we load a data, it will be 50 items maximum. However, the data.length contains the filtered data length. So, we receive 50 data from the BE, but then we filtered it out on the FE.

    App/src/libs/SearchUIUtils.ts

    Lines 1316 to 1351 in 276a46a

    for (const key in data) {
    if (isReportActionEntry(key)) {
    const reportActions = Object.values(data[key]);
    const freeTrialMessages = reportActions.filter((action) => {
    const html = getReportActionHtml(action);
    return Parser.htmlToMarkdown(html) === CONST.FREE_TRIAL_MARKDOWN;
    });
    const isDuplicateFreeTrialMessage = freeTrialMessages.length > 1;
    const filteredReportActions = reportActions.filter((action) => !isDuplicateFreeTrialMessage || action.reportActionID !== freeTrialMessages.at(0)?.reportActionID);
    for (const reportAction of filteredReportActions) {
    const from = data.personalDetailsList?.[reportAction.accountID];
    const report = data[`${ONYXKEYS.COLLECTION.REPORT}${reportAction.reportID}`] ?? {};
    const policy = data[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`] ?? {};
    const originalMessage = isMoneyRequestAction(reportAction) ? getOriginalMessage<typeof CONST.REPORT.ACTIONS.TYPE.IOU>(reportAction) : undefined;
    const isSendingMoney = isMoneyRequestAction(reportAction) && originalMessage?.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && originalMessage?.IOUDetails;
    const isReportArchived = isArchivedReport(data[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]);
    const invoiceReceiverPolicy: SearchPolicy | undefined =
    report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS ? data[`${ONYXKEYS.COLLECTION.POLICY}${report.invoiceReceiver.policyID}`] : undefined;
    if (
    !shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction(report, isReportArchived)) ||
    isDeletedAction(reportAction) ||
    isResolvedActionableWhisper(reportAction) ||
    reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED ||
    isCreatedAction(reportAction) ||
    isWhisperActionTargetedToOthers(reportAction) ||
    (isMoneyRequestAction(reportAction) && !!report?.isWaitingOnBankAccount && originalMessage?.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && !isSendingMoney)
    ) {
    continue;
    }
    reportActionItems.push({
    ...reportAction,
    from,
    reportName: getSearchReportName({report, policy, personalDetails: data.personalDetailsList, transactions, invoiceReceiverPolicy, reports, policies, isReportArchived}),
    formattedFrom: from?.displayName ?? from?.login ?? '',
    date: reportAction.created,

    So, offset > data.length - CONST.SEARCH.RESULTS_PAGE_SIZE will always evaluate to true because data.length - 50 will be negative.

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

    To fix it, we need to get the original, unfiltered data length. We can update getReportActionsSections (and others) to also return the total length. For example, in getReportActionsSections,

    let n = 0;
    
    for (const key in data) {
        if (isReportActionEntry(key)) {
            const reportActions = Object.values(data[key]);
            n += reportActions.length;
        ...
    }
    
    return [reportActionItems, n];
    

    Then, in Search/index.ts, use that length instead of data.length.

    const [data, dataLength] = useMemo(() => {
    if (searchResults === undefined || !isDataLoaded) {
    return [[], 0];
    }
    // Group-by option cannot be used for chats or tasks
    const isChat = type === CONST.SEARCH.DATA_TYPES.CHAT;
    const isTask = type === CONST.SEARCH.DATA_TYPES.TASK;
    if (groupBy && (isChat || isTask)) {
    return [[], 0];
    }
    const data1 = getSections(type, searchResults.data, accountID, formatPhoneNumber, groupBy, exportReportActions, searchKey, archivedReportsIdSet, queryJSON);
    return [data1, data1.length];
    }, [searchKey, exportReportActions, groupBy, isDataLoaded, searchResults, type, archivedReportsIdSet, formatPhoneNumber, accountID, queryJSON]);

    const [data, dataLength, allLength] = useMemo(() => {
        ...
        const [filteredData, allLength] = getSections(type, searchResults.data, accountID, formatPhoneNumber, groupBy, exportReportActions, searchKey, archivedReportsIdSet, queryJSON);
        return [filteredData, filteredData.length, allLength];
    }, [searchKey, exportReportActions, groupBy, isDataLoaded, searchResults, type, archivedReportsIdSet, formatPhoneNumber, accountID, queryJSON]);
    

    if (!isFocused || !searchResults?.search?.hasMoreResults || shouldShowLoadingState || shouldShowLoadingMoreItems || offset > data.length - CONST.SEARCH.RESULTS_PAGE_SIZE) {

    offset > allLength - CONST.SEARCH.RESULTS_PAGE_SIZE
    
  6. added
    External
    on Oct 14, 2025
  7. changed the title [-]Reports - List does not load more messages when scrolled to the end of list on Reports > Chats[/-] [+][$250] Reports - List does not load more messages when scrolled to the end of list on Reports > Chats[/+] on Oct 14, 2025
  8. melvin-bot commented on Oct 14, 2025

    @melvin-bot
  9. added
    Help Wanted
    on Oct 14, 2025
  10. melvin-bot commented on Oct 14, 2025

    @melvin-bot

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

  11. mallenexpensify commented on Oct 14, 2025

    @mallenexpensify
    Contributor

    Was able to reproduce. @FitseTLT 👀 on the proposals above. Thx

    2025-10-14_14-34-37.mp4
  12. 40 remaining items

  13. melvin-bot commented on Dec 16, 2025

    @melvin-bot

    This issue has not been updated in over 15 days. @flodnv, @mallenexpensify, @FitseTLT, @bernhardoj eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  14. bernhardoj commented on Dec 16, 2025

    @bernhardoj
    Contributor

    @mallenexpensify looks like the automation failed here. It was deployed to prod 2 weeks ago.

  15. FitseTLT commented on Dec 16, 2025

    @FitseTLT
    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/70211/changes#r2623655608

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

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

    Precondition:

    • Have an account with 50+ report actions (messages/expenses)

    Test:

    1. Go to Reports > Chats
    2. Scroll to the end of the list
    3. Verify more messages are loaded

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-dc51-a2fc-66a4-1a2bd2540234
  16. FitseTLT commented on Dec 16, 2025

    @FitseTLT
    Contributor

    Here is the checklist @mallenexpensify

  17. added
    Daily
    Awaiting Payment
    and removed
    Reviewing
    on Dec 16, 2025
  18. mallenexpensify commented on Dec 16, 2025

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @bernhardoj due $250 via NewDot
    Contributor+: @FitseTLT paid $250 via Upwork

    Test case created ^

    Thx!

  19. bernhardoj commented on Dec 17, 2025

    @bernhardoj
    Contributor

    Requested in ND.

  20. garrettmknight commented on Dec 29, 2025

    @garrettmknight
    Contributor

    $250 approved for @bernhardoj

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