Skip to content

[Due for payment 2026-11-06] [$175] Spend - Select all count is stale after submitting a report #102298

Closed

Description

@MelvinBot

Reported by TaduJR on Paginate live to-do searches instead of rendering every cached row (comment), after that PR was deployed to staging in 9.4.94-0.

Prerequisite

Have more than 25 draft expenses.

Steps to reproduce

  1. Go to Spend > Reports.
  2. Select all and note the "N selected" count.
  3. Deselect all.
  4. Submit one report.
  5. Select all again.

Expected result

The "N selected" count goes down by one.

Actual result

The "N selected" count shows the old, stale value.

Video

Mac-Chrome.mp4

Notes

It isn't confirmed yet whether the PR above caused this or whether it happened before. That PR changed how selection data is capped for the live to-do searches, so check it first.

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @TaduJR

Activity

  1. TaduJR commented on Sep 25, 2026

    @TaduJR
    Contributor

    It isn't confirmed yet whether the PR above caused this or whether it happened before. That PR changed how selection data is capped for the live to-do searches, so check it first.

    Not related with #100941. It's repro on both staging and prod

  2. ashusatyarthi-wq commented on Sep 25, 2026

    @ashusatyarthi-wq

    Proposal

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

    In Spend > Reports (to-do search), after selecting all items, deselecting all, and submitting a report, re-selecting all displays the previous stale "N selected" count instead of decrementing to reflect the submitted report.


    What is the root cause of that problem?

    In live to-do searches (isTodoSearch), results are built dynamically from live Onyx data via useTodoSearchResults.

    1. In src/hooks/useTodoSearchResults.ts (lines 18–54), TodoMetadata and computeMetadata calculate:

      • count (total transactions across all matching reports)
      • total (dollar sum in cents)
      • currency
        However, it never calculates or returns reportCount (reports.length).
    2. In src/components/Search/SearchResultsProvider.tsx (lines 56–61), when constructing searchInfo for live to-do data:

      const searchInfo: SearchResultsInfo = {
          ...(snapshotSearchResults?.search ?? defaultSearchInfo),
          count: liveData.metadata.count,
          total: liveData.metadata.total,
          currency: liveData.metadata.currency,
      };

      Because reportCount is omitted from searchInfo, it falls back to snapshotSearchResults?.search?.reportCount (the server snapshot cached at page load).

    3. When a report is submitted, useTodoSearchResults reactively updates from Onyx collections and removes the submitted report from reports. However, currentSearchResults.search.reportCount remains stuck on the stale server snapshot value.

    4. In src/components/Search/SearchBulkActionsButton.tsx (lines 182–198), for isExpenseReportType:

      const allMatchingReportsCount = currentSearchResults?.search?.reportCount;
      ...
      selectedAllMatchingItemsCount = typeof allMatchingReportsCount === 'number' ? Math.max(allMatchingReportsCount - excludedItemsCount, 0) : selectedItemsCount;
      const selectedBulkActionsCount = areAllMatchingItemsSelected ? selectedAllMatchingItemsCount : selectedItemsCount;

      The selection count directly reads allMatchingReportsCount (currentSearchResults?.search?.reportCount). Because SearchResultsProvider never synchronized reportCount from the live reports array, selectedBulkActionsCount continues to display the stale initial snapshot report count rather than the decremented live count.


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

    1. Expose reportCount in TodoMetadata (src/hooks/useTodoSearchResults.ts):
      Add reportCount: number to TodoMetadata:

      type TodoMetadata = {
          /** Total number of transactions across all reports */
          count: number;
          /** Total number of matching reports */
          reportCount: number;
          /** Sum of all report totals (in cents) */
          total: number;
          /** Currency of the first report, used as reference currency */
          currency: string | undefined;
      };

      In computeMetadata(reports, ...):

      return {count, reportCount: reports.length, total, currency};
    2. Propagate reportCount in SearchResultsProvider.tsx (src/components/Search/SearchResultsProvider.tsx):
      Pass reportCount from liveData.metadata into searchInfo:

      const searchInfo: SearchResultsInfo = {
          ...(snapshotSearchResults?.search ?? defaultSearchInfo),
          count: liveData.metadata.count,
          reportCount: liveData.metadata.reportCount,
          total: liveData.metadata.total,
          currency: liveData.metadata.currency,
      };
    3. Pre-tested Branch:
      The fix is committed and tested on:
      ashusatyarthi-wq/App:fix/stale-select-all-count-102298 (Commit 4284404c5253a550000e49116e176288c26188a5).


    What alternative solutions did you explore? (Optional)

    Re-fetching the server snapshot after submitting a report. This was rejected because to-do searches are designed to run optimistically off live Onyx data without waiting for network round-trips. Properly providing reportCount: reports.length from live metadata ensures immediate, consistent UI updates across all tabs.

  3. ashusatyarthi-wq commented on Sep 25, 2026

    @ashusatyarthi-wq

    Contributor details
    Your Expensify account email: ashusatyarthi@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~010e53044b5828fe60

  4. melvin-bot commented on Sep 25, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  5. TaduJR commented on Sep 28, 2026

    @TaduJR
    Contributor

    I can help with review if C+ is needed since I reported the issue and have the context. LMK 👍

    cc @mountiny

  6. mkhutornyi commented on Sep 28, 2026

    @mkhutornyi
    Contributor

    From the video in OP, it doesn't look like bug.

    In LHN, todo count is 50+ first and after submitting a report, it becomes 50.
    So the Select all count matches LHN badge

  7. mkhutornyi commented on Sep 28, 2026

    @mkhutornyi
    Contributor

    Do you have clear video? The video in OP isn't clear.

  8. TaduJR commented on Sep 28, 2026

    @TaduJR
    Contributor
    Mac-Chrome.mp4

    Have more than 25 draft expenses.

    This should be more than 50. I thought it is repro with more than 25

    From the video in OP, it doesn't look like bug.
    In LHN, todo count is 50+ first and after submitting a report, it becomes 50.
    So the Select all count matches LHN badge

    As you can see on the vid there is inconsistency with 50 > and < so its a bug

  9. melvin-bot commented on Sep 28, 2026

    @melvin-bot

    Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  10. melvin-bot commented on Sep 30, 2026

    @melvin-bot

    Huh... This is 4 days overdue. Who can take care of this?

  11. 57 remaining items

  12. added and removed on Nov 4, 2026
  13. TaduJR commented on Nov 6, 2026

    @TaduJR
    Contributor

    Follow up fixed on main.

  14. TaduJR commented on Nov 6, 2026

    @TaduJR
    Contributor

    Contributor+ Checklist:

    • [Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to the comment on the PR: Label Reports tab "Select all" with matching-report count #99689 (comment)
      Link to the comment on the Issue:

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

    Regression Test Proposal

    Precondition:

    • An account with more than 50 draft reports in a workspace, each with at least one expense.

    Test:

    1. Go to Spend > Drafts.
    2. Press the checkbox at the top of the list and choose "Select all".
    3. Note the number in the "N selected" bar. This is N.
    4. Press the checkbox again to clear the selection.
    5. Press "Submit" on any report row.
    6. Verify the report leaves the list.
    7. Press the checkbox and choose "Select all".
    8. Verify the bar shows N−1.

    Do we agree 👍 or 👎

  15. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    on Nov 6, 2026
  16. changed the title [-][$175] Spend - Select all count is stale after submitting a report[/-] [+][Due for payment 2026-11-06] [$175] Spend - Select all count is stale after submitting a report[/+] on Nov 6, 2026
  17. melvin-bot commented on Nov 6, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  18. mallenexpensify commented on Nov 7, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @TaduJR due $175 via Upwork

    @TaduJR can you please accept the job below? Please reply here and tag me once you have.
    https://www.upwork.com/jobs/~022118857608614079621

  19. TaduJR commented on Nov 7, 2026

    @TaduJR
    Contributor

    Offer Accepted @mallenexpensify

    But the offer is $250, the issue was created after Sept 19, so the correct amount is $175.

    Thanks!

  20. mallenexpensify commented on Nov 9, 2026

    @mallenexpensify
    Contributor

    @TaduJR , thanks for pointing it out, normally I catch the different but was sidetracked when paying.
    Can you accept the refund request for $75 si the total will be $175? Thx
    https://www.upwork.com/jobs/~022118857608614079621

  21. TaduJR commented on Nov 9, 2026

    @TaduJR
    Contributor

    @mallenexpensify

    https://www.upwork.com/jobs/~022118857608614079621

    This link is not working.

    Also going to the workroom and trying to refund requires invoice and does the full refund.

    Should we deduct from another issue payment like #101694 and you can pay $100? wdyt?

  22. TaduJR commented on Nov 9, 2026

    @TaduJR
    Contributor

    @mallenexpensify

    Got it. Found the refund request in Upwork Chat. Sorry first time 😁

    Please check the request I approved the refund.

    Thanks!

  23. mallenexpensify commented on Nov 9, 2026

    @mallenexpensify
    Contributor

    Thanks @TaduJR , confirming the refund was received. Thanks for pointing out it was in the chat too, I'll try to remember that.

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 productionExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions