Skip to content

Paginate live to-do searches instead of rendering every cached row - #100941

Merged
mountiny merged 25 commits into
Expensify:mainfrom
callstack-internal:paginate-live-search-offline
Sep 25, 2026
Merged

mountiny merged 25 commits into
Expensify:mainfrom
callstack-internal:paginate-live-search-offline

Conversation

@TMisiukiewicz

@TMisiukiewicz TMisiukiewicz commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

The four to-do searches (Submit, Approve, Pay, Export) render straight from a live Onyx scan, which hands back every matching row at once. If you have a big local cache, that means hundreds of rows on the very first render.

This PR caps those lists at 50 rows and pages them like any other search.

The cap lives in useSearchSnapshot. We slice the rows after sorting, so the next page picks up right where the current one ends. A few rows get to stay even past the cap: anything you've selected and anything that's being highlighted. Rows that are being deleted don't count toward it while online, since they're hidden anyway. Selection data is capped too, so "select all" only picks what you can actually see. The chart and totals still use the full set.

A small new hook, useLiveRowLimit, decides how many rows to show. It's one page past the last page the server actually answered. It only ever grows, so a refresh (which resets the offset to 0) doesn't suddenly shrink the list — those rows are still sitting in Onyx.

In <Search>, hitting the end of the list now fires a regular Search request instead of bailing out early for live searches. Live paging tracks its own "loading" flag, tied to the offset it asked for, so a refresh on the same query doesn't flash the load-more skeleton. SearchResultsProvider keeps forcing isLoading: false for live searches, because that flag survives a reload and would otherwise leave skeletons stuck on screen.

A few edge cases worth calling out:

  • If the server says it's out of pages but the local cache still has more, we show the next 50 locally. Before the first response comes back we just wait, since hasMoreResults is only a default at that point.
  • Offline, the page request waits and goes out once you're back online.
  • Live results don't carry errors, so we look at responseJsonCode to spot a failed page. It only retries when you scroll to the end again. The list also reports "end reached" whenever its rows rebuild, so we use an actual scroll to tell the two apart.
  • If a page was still loading when <Search> remounted, we wait for it rather than skipping or duplicating its rows, and ask for it once more if a reload left it hanging.

Related to #100409, which removes the live to-do path entirely. This PR keeps it and paginates it instead, so to-dos keep working offline.

Fixed Issues

$ #101061
PROPOSAL:

Tests

  1. Sign in with an account that has:
  • more than 50 reports in one of Draft/Needs approval/Ready to pay/Ready to export category
  • less than 50 reports in one of Draft/Needs approval/Ready to pay/Ready to export category
  1. Go to Spend tab and pick category with more than 50 reports
  2. Verify only the first 50 reports render
  3. Scroll to the end of the list and verify there is skeleton at the end of the list, Search API is being called, and new items appear in the list once it resolves
  4. Tick the select-all checkbox and verify only the rendered reports are selected
  5. Block the Search request in devtools, scroll to the end, and verify the skeleton goes away and no request loop starts
  6. Unblock the request, scroll up and back to the end, and verify the next page loads
  7. Pick category with less than 50 reports
  8. Scroll to the end of the list and verify there is no skeleton at the end of the list
  • Verify that no errors appear in the JS console

Offline tests

  1. Sign in with an account that has:
  • more than 50 reports in one of Draft/Needs approval/Ready to pay/Ready to export category
  • less than 50 reports in one of Draft/Needs approval/Ready to pay/Ready to export category
  1. Go offline
  2. Go to Spend tab
  3. Verify you are able to open Drafts/Needs approval/Ready to pay/Ready to export tabs
  4. Open a category with more than 50 reports and scroll to the end
  5. Verify no load-more skeleton is stuck at the end of the list
  6. Go back online and verify the next page loads

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-09-14.at.10.15.24.mov

@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/components/Search/ChatSearchView.tsx 100.00% <ø> (ø)
src/components/Search/ExpenseFlatSearchView.tsx 100.00% <ø> (ø)
src/components/Search/ExpenseGroupedSearchView.tsx 70.47% <ø> (ø)
src/components/Search/ExpenseReportSearchView.tsx 100.00% <ø> (ø)
src/components/Search/SearchResultsProvider.tsx 100.00% <ø> (+20.68%) ⬆️
src/components/Search/TaskSearchView.tsx 100.00% <ø> (ø)
src/components/Search/hooks/useLiveRowLimit.ts 100.00% <100.00%> (ø)
src/components/Search/hooks/useSearchSnapshot.ts 95.37% <100.00%> (+8.41%) ⬆️
src/components/Search/index.tsx 68.11% <97.77%> (+9.64%) ⬆️
... and 215 files with indirect coverage changes

@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

@TMisiukiewicz
TMisiukiewicz marked this pull request as ready for review September 14, 2026 08:56
@TMisiukiewicz
TMisiukiewicz requested review from a team as code owners September 14, 2026 08:56
@melvin-bot
melvin-bot Bot requested review from TaduJR and heyjennahay and removed request for a team September 14, 2026 08:56
@melvin-bot

melvin-bot Bot commented Sep 14, 2026

Copy link
Copy Markdown

@TaduJR Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team September 14, 2026 08:56

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31b41a449b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/components/Search/index.tsx Resolved
@TaduJR

TaduJR commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android-Native-1.mp4
Android: mWeb Chrome
Android-mWeb-1.mp4
iOS: HybridApp
iOS-Native-2.mp4
iOS: mWeb Safari
MacOS: Chrome / Safari
Mac-Chrome-1.mp4

Comment thread src/components/Search/index.tsx Resolved
Comment thread src/components/Search/index.tsx Resolved
Comment thread src/components/Search/index.tsx Outdated
return;
}

if (!searchResults?.search?.hasMoreResults) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offline, reaching the bottom shows more cached rows, but online the only way past the cap is hasMoreResults. When the server says there's nothing more but the device has more to-do reports, those rows can't be reached online.

Two ways to get there IMO:

  • On a first visit, the tab's Search request fails. To-do tabs don't show the error view, so the list still renders, but hasMoreResults is never set and it stays at 50 rows.
  • The server's list is shorter than the device's. The app and the server don't use exactly the same rules for these tabs.

Before this PR every cached row was visible. Could we also show more cached rows online when hasMoreResults is false?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the ability to reveal additional cached rows while offline, so offline users can only see the rows that have already been synced from the backend. The cache fallback should only be used when hasMoreResults === false in a successful search response. A failed request should not be treated as proof that the server is exhausted, wdyt? 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, a failed request doesn't prove the server has nothing more, so paging should keep going after a failure.

Tho Two things are still open:

  1. On a first visit, if the first page fails, hasMoreResults is never set (the failure data doesn't write it), so fetchMoreResults returns straight away and the list stays at 50 rows until the tab is opened again. The failed page should be asked for again, for example at the next scroll to the bottom.
  2. The fallback for a successful hasMoreResults: false isn't in the code yet. When I made the first page return hasMoreResults: false, the list stayed at 50 of 108 rows.

About offline: Carlos pointed out that to-dos are built from Onyx on purpose so they work offline from slack right, and before this PR every cached row showed. Now offline shows only the pages already loaded (50 of 108 in my test). I'd show more cached rows when the user scrolls to the bottom offline, and after a failed page too, so the list isn't stuck while it waits to retry. Should we defer this for mountiny and luacmartins?

WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on 1 and 2, addressed both in f181fc8 and e3adfc0

On offline, I'd rather not reveal every cached row. For a live search the Search call is the only thing that pulls those reports into Onyx, so after going back online there is no way of recovering the missing API calls. WDYT?

// don't force isLoading off, the load-more skeleton reads it to tell a page is in flight
currentSearchResults = {
search: {...searchInfo, isLoading: false, hasResults},
search: {...searchInfo, hasResults},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since isLoading isn't forced to false anymore, a stale value can leave a to-do tab stuck.

search.isLoading is saved to disk with the snapshot. If the app is closed or reloaded while a page request is running, it stays true. After reopening, nothing sends a request that would clear it:

  • useSearchPageSetup skips to-do tabs
  • the search effect in <Search> returns early while isLoading is true
  • fetchMoreResults and search() return early too

The loading rows stay at the bottom and no more pages load until the sort changes.

To reproduce, on a to-do tab with 50+ reports, run this in the console and reload:

Onyx.merge('snapshot_<hash>', {search: {isLoading: true, offset: 50}})

On main the tab recovers by itself.

useInsightData.ts handles the same case by calling search() with isLoading: false and letting the duplicate check skip a request that's really still running. Could we do something similar here?

This causes this bug

Mac-Chrome.mp4

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for finding this, mind checking again?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fixes a reload while a page request is running, because that request also saves state: 'loading'. A to-do tab can still get stuck in two ways:

  1. First visit. The snapshot only gets its hash when the first answer comes back, so a reload before that fails the new isSnapshotForCurrentQuery check and nothing sends the request again. The effect in <Search> still returns early while isLoading is true, so switching tabs doesn't fix it either. To reproduce, run this and reload:
    Onyx.set('snapshot_<hash>', {search: {isLoading: true, state: 'loading', offset: 0}});
  2. isLoading: true without state. The console line from my first comment does this. So does deleting selected expenses in a report opened from Search, if the app is closed before handlePreventSearchAPI turns loading off again. isSearchPending is false in both cases, so the new check skips them.

A leftover isLoading: true at offset 0 also keeps the footer total as a skeleton, and offline nothing can clear it until the app reconnects.

Since the snapshot's isLoading is shared with other requests, could live results keep isLoading: false like on main, and let to-do paging track its own requests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in b212c4b

@TaduJR

TaduJR commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Bug:

Mac-Chrome-2.mp4

@TMisiukiewicz

Copy link
Copy Markdown
Contributor Author

Bug:

Mac-Chrome-2.mp4

Looks like it's broken on prod too

Screen.Recording.2026-09-15.at.15.05.58.mov

@TMisiukiewicz

Copy link
Copy Markdown
Contributor Author

@TaduJR friendly bump

TaduJR

This comment was marked as duplicate.

TaduJR

This comment was marked as resolved.

@TaduJR

This comment was marked as resolved.

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Code review — 2 things I'd want answered before approving, plus a stale PR description.

The approach is sound: cap data after the sort, let the cap ride the answered offset, keep the live scan's offline behaviour. CI is green apart from the checklist jobs, and test coverage is genuinely good (~1220 added test lines for ~170 src lines). Two spots look like real holes.


1. The local-reveal path is missing the scroll guard — it can un-cap the whole list

You added hasScrolledSinceLastEndRef because "the list also reports an end whenever its rows rebuild". But the guard is read at index.tsx:896-899, which is below the !hasMoreResults early return — so the one path that reveals rows locally never sees it:

index.tsx:885-886

revealNextLivePage() → liveRowLimit +50 → visibleData grows → rows rebuild → onEndReached fires again → !hasMoreResults again → reveal again. By your own comment that loop only stops when liveRowLimit >= allDataLength, i.e. once every cached row is rendered — exactly the regression this PR exists to prevent. Can you confirm whether onEndReached refires here, and if so gate the reveal on hasScrolledSinceLastEndRef too?

2. The selected/highlighted escape hatch in getRowLimitEnd is unbounded

useSearchSnapshot.ts:112 sets end to the last qualifying index, so a single selected or highlighted row at index 900 renders 901 rows. A post-create highlight (newSearchResultKeys) landing on a row that sorts low, or a selected row that drifts down as new data arrives, defeats the cap. Hoisting those rows into the window would be safer than stretching it — or at least bound the stretch.

3. The PR description no longer matches the code

Three claims are stale, which matters since I'm reviewing against them:

  • "SearchResultsProvider no longer forces isLoading: false" — it still does; the diff only adds a comment. (Harmless, since isSearchPending reads state, not isLoading.)
  • "derives the cap from the snapshot cursor … instead of keeping its own page state" — the shipped design is a useLiveRowLimit hook plus livePageOffset and isLivePageAdopted state in <Search>.
  • "filteredData … still read[s] the full set, so selection … [is] unchanged" — filteredData is capped now (useSearchSnapshot.ts:453), which changes totalSelectableItemsCount and select-all on live tabs.

Also worth updating: Read to-do searches from the paginated search snapshot instead of live Onyx is closed unmerged, so "related to" reads oddly.

4. Please add a QA step for select-all

On a live to-do tab with >50 reports, "Select all" now selects only the loaded page. That's consistent with server-paginated search, but it's a user-visible change and none of the listed Tests/QA steps cover it.


Nits
  • filteredData changes shape at the cap boundary. Uncapped it's the pre-sort baseFilteredData sections; capped it's post-sort, highlight-stamped, optimistically-stabilized rows. Counts can shift for reasons unrelated to the cap. Deriving both from the same source would be cleaner.
  • didLastLivePageFail is broad. index.tsx:213 treats any stored responseJsonCode as retryable, including INVALID_SEARCH_QUERY, and bypasses the hasMoreResults gate for as long as the code sits in the snapshot. Consider excluding terminal codes.
  • getRowLimitEnd walks every row on each selection change, plus each group's transactions. rowLimitEnd usually comes back unchanged so the list shouldn't re-render, but it's a wasted O(n) pass per row tap on the large-cache accounts this PR targets. Bounding the stretch (Fix spaces #2) would let it early-exit.
  • useLiveRowLimit(offset, hasUnconfirmedPage) takes a bare positional boolean at the call site; an options object reads better.
  • hasScrolledSinceLastEndRef is reset for non-live searches too (index.tsx:897) even though only the live-failure path reads it. Harmless, but confusing.
What looks good
  • Slicing after the sort and after optimistic stabilization is the right insertion point; chartData and allDataLength correctly stay uncapped.
  • Follows the repo's React Compiler standard — no hand-rolled memoization in the new code, and the compliance check passes.
  • Latching answeredOffset with Math.max so a refresh rewinding offset to 0 can't shrink the window is a nice touch.
  • Comments explain why, which this state machine needs.
  • Test coverage is real, not token: UI + unit across the hook, the provider, and the page. Codecov shows SearchResultsProvider +20.68%, index.tsx +9.70%, useSearchSnapshot +8.41%.

One general note: <Search> now carries four interacting live-only flags (livePageOffset, isLivePageAdopted, didLastLivePageFail, liveRowLimit) on top of two wantedOffsetRef paths, and fetchMoreResults has 19 dependencies. That's a lot of state for one screen to hold correct. Not a blocker, but it's where the next bug will come from.


Reply with @MelvinBot <feedback> to dig into any of these.


view run

TaduJR

This comment was marked as resolved.

@TaduJR

This comment was marked as resolved.

@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

@TaduJR TaduJR left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@melvin-bot
melvin-bot Bot requested a review from mountiny September 24, 2026 14:50
const rowLimitEnd = visibleRowLimit === undefined ? stableSortedData.length : getRowLimitEnd(stableSortedData, visibleRowLimit, selectedTransactions, isOffline);
const isRowLimitApplied = rowLimitEnd < stableSortedData.length;
const visibleData = isRowLimitApplied ? stableSortedData.slice(0, rowLimitEnd) : stableSortedData;
// selection runs off this, so cap it too or "select all" reaches rows that were never rendered; live rows are all report groups

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// selection runs off this, so cap it too or "select all" reaches rows that were never rendered; live rows are all report groups
// selection runs off this, so cap it too or "select all" reaches rows that were never rendered; live rows are all report groups

// Wide layout floats the bulk action bar over the end of the list, so the list has to leave room for it.
const shouldReserveBulkActionBarSpace = useShouldShowBulkActionBar(queryJSON);
const [offset, setOffset] = useState(0);
// a page left running by a previous mount is still in flight, so wait for it rather than revealing or skipping its rows

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// a page left running by a previous mount is still in flight, so wait for it rather than revealing or skipping its rows
// Page left running by a previous mount is still in flight, so wait for it rather than revealing or skipping its rows

const [offset, setOffset] = useState(0);
// a page left running by a previous mount is still in flight, so wait for it rather than revealing or skipping its rows
const isLivePageRunningAtMount = () => shouldUseLiveData && isSearchPending(searchResults) && (searchResults?.search?.offset ?? 0) > 0;
// live paging owns its in-flight flag, keyed to the offset it asked for so other searches on this hash don't read as ours

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// live paging owns its in-flight flag, keyed to the offset it asked for so other searches on this hash don't read as ours
// Live paging owns its in-flight flag, keyed to the offset it asked for so other searches on this hash don't read as ours

wantedOffsetRef.current = nextOffset;
return;
}
// the server has nothing left, but the live scan can still hold rows past the cap: page those in locally

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// the server has nothing left, but the live scan can still hold rows past the cap: page those in locally
// The server has nothing left, but the live scan can still hold rows past the cap: page those in locally

@mountiny
mountiny merged commit 9f36b15 into Expensify:main Sep 25, 2026
35 of 37 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@TaduJR

TaduJR commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@mountiny

Should we create create a new issue for #100941 (comment)?

I can help with the review.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.94-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@TaduJR

TaduJR commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Prerequisite: Have more than 25 Draft Expenses

  1. Go to Spend > Reports
  2. Select All and note "N selected"
  3. Deselect All
  4. Submit one Report
  5. Re-Select All

Expected: N selected is decremented
Actual: N is a stale value

Mac-Chrome.mp4

@mountiny

Copy link
Copy Markdown
Contributor

@MelvinBot can you create an issue for #100941 (comment) in App

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site changes are required for this PR, so I didn't create a docs PR.

This PR changes how the to-do lists on the Spend page (Submit, Approve, Pay, Export) load rows. That is a performance change. It doesn't add or rename any feature, setting, or button.

Why no docs update is needed
  • The to-do lists now show 50 rows and load more as you scroll. Other Spend searches already work this way. No help article says to-do lists load every item at once.
  • Select all on this page now selects only the visible rows. The help site already describes it that way, and describes Select all as the option that matches every report (Search-and-Download-Expenses.md:35, How-to-Export-Reports.md:65-66).
  • Offline access to to-do lists stays the same, and no article covers loading more rows offline.
  • The chart and totals still use the full result set, so Getting-Started-with-the-Spend-Page.md is still accurate.

view run

@MelvinBot

Copy link
Copy Markdown
Contributor

I created Spend - Select all count is stale after submitting a report for TaduJR's report. It includes the repro steps and the video.

I didn't find a duplicate. A related issue is [Bug] Mark as exported processes only the first page after Reports “Select all matching”.

I didn't add labels or an assignee.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.94-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants