[$250] Auto -Spend - "Next" arrow is disabled when user reaches 50 of 50 report
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: 9.4.81-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/74236221/folder/54000978/51874675/1766787876?sort=%2Bidentifier Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: Windows 11 Home/Chrome App Component: Search
Action Performed:
Preconditions:
- Use this account: [email protected]
- Open https://staging.new.expensify.com/
- Go to Spend > Reports
- Click on the first report
- Click the "Next" navigation arrow repeatedly to cycle through the reports until you reach the 50th report
- Click the "Next" arrow again to navigate to report number 51
Expected Result:
Verify it is possible to click the "Next" arrow again to navigate to report number 51
Actual Result:
"Next" arrow is disabled and unable to click
Workaround:
Unknown
Platforms:
- [x] Android: App
- [ ] Android: mWeb Chrome
- [x] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [ ] MacOS: Chrome / Safari
Screenshots/Videos
https://github.com/user-attachments/assets/1455c3a2-5dd8-44ee-bdf0-24fc0d7d6851
Issue Owner
Current Issue Owner: @yusufdeveloper2903Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022121294038183507904
- Upwork Job ID: 2121294038183507904
- Last Price Increase: 2026-11-13
Proposal
What is the root cause of that problem?
The arrows and the search results read two different lists, and only one of them grows when page 2 loads.
MoneyRequestReportNavigation walks sortedReportIDs from the app-level Search context, and it prefers that list whenever it is non-empty and no page is in flight — MoneyRequestReportNavigation.tsx:127-129. The only writer of that list is useSaveSortedReportIDs.ts:17-29, called from the Search list screen at Search/index.tsx:811.
Opening a report puts that Search screen behind a right-hand modal, where FreezeWrapper freezes it. Its effects stop running, so sortedReportIDs is stuck at the 50 IDs captured before you opened the first report — 50 being CONST.SEARCH.RESULTS_PAGE_SIZE.
The arrow does fetch page 2 (:207-223) and those reports do land in the Onyx snapshot — but the list that can see them (useSearchSections) is only mounted while loading (:242). The moment the page arrives, loading flips false and the component reverts to the frozen 50.
So at report 50, :149 disables the button, and the label reads "50 of 50" because the count is re-synced from that same frozen list.
Two secondary defects that make this worse
1. The tail wraps instead of advancing. :225 computes (currentIndex + 1) % effectiveAllReports.length. There is no "wait for the next page" path — so with >100 matching reports the button stays enabled but throws you back to report 1. Report 51 is unreachable either way.
2. hasMoreResults can be erased permanently. saveLastSearchParams uses Onyx.set, not merge. Search.ts:1244-1251 writes that key before the request without hasMoreResults, wiping it. It is restored only in .then() and only when both response.search.offset and prevReportsLength are truthy (:1287-1315); the .catch() restores nothing. One failed request and the flag stays undefined, which permanently disables the arrow with no retry — unlike the list view, which re-arms via wantedOffsetRef (Search/index.tsx:883-890).
Note the Search list's own infinite scroll never writes this key — shouldUpdateLastSearchParams defaults to false and only the arrow passes true. So the arrows' entire pagination ability rests on a single snapshot read taken at the instant you clicked the report row (Search/index.tsx:697-705).
What changes do you think we should make in order to solve the problem?
-
Make the snapshot the source of truth for the arrow list. Stop preferring the frozen Search-context list. Either mount the
useSearchSectionslist unconditionally inMoneyRequestReportNavigation, or prefer whichever list is longer. The context list is a render-time cache of a screen that is frozen for the entire time the arrows are on screen, so it can never be authoritative. -
Don't wrap at the tail. Replace the modulo at
:225with a bounds check: if there is no next item and a page is in flight, hold position (show a loading state on the arrow) and advance once the list grows. -
Read
hasMoreResultsandoffsetstraight off the snapshot, the wayfetchMoreResultsalready does (Search/index.tsx:836-880), instead of the separately-persisted copy inREPORT_NAVIGATION_LAST_SEARCH_QUERY. That removes the whole wipe-and-restore class of bug. -
If that duplicated key must stay, change
saveLastSearchParamsto merge and restore the flag in.catch()too.
Fix 1 alone unblocks report 51. Fixes 2-4 stop it regressing in the failure and >100-report cases.
Add a regression test: today MoneyRequestReportNavigation.test.tsx asserts which list is picked, but never that the list grows after a page lands — which is exactly the untested gap.
What alternative solutions did you explore? (Optional)
- Raising
RESULTS_PAGE_SIZE— moves the wall to 100 instead of removing it. - Un-freezing the Search screen while the report modal is open — fixes the symptom but costs re-renders of the full search list on every arrow click, and leaves defects 2-4 in place.
- Backend not reporting more results — considered and set aside: the Search list's own infinite scroll does load past 50 for the same query, so the server is reporting
hasMoreResults: true.
Confidence and what I did not verify
High confidence on the mechanism, the code paths, and the disabled condition — two independent investigations converged on the same lines, and I re-read them directly.
Not verified:
- I did not reproduce this live. It needs an account with 51+ matching expense reports, which the test account available to me does not have.
- Whether the user-visible symptom is disabled (51-100 reports) or wraps to report 1 (>100 reports) depends on the server's
hasMoreResultsafter the offset-50 request. The report says disabled, which fits 51-100. - I could not run
git blameto pin an introducing PR (shallow checkout), so I am not attributing this to a specific merge.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/101453) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @marufsharifi (External)
Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.
🆘 C+ Help Wanted
Proposal
What is the root cause of that problem?
The Next arrow and "50 of 50" counter are rendered by MoneyRequestReportNavigationContent → PrevNextButtons / the count Text (MoneyRequestReportNavigation.tsx#L243-L253). Both read effectiveAllReports, and that list caps at the first 50 IDs.
The component has two sources for the list. The fast path is the Search-context list contextReports; the slow path is standaloneReports, lifted from a child that mounts useSearchSections and reads the live snapshot. Which one wins is decided by one line (:127):
const shouldUseContextReports = contextReports.length > 0 && !isSearchLoading;
Walk the repro. On report ~38 the arrow correctly fetches page 2 (:209-222). While it's in flight isSearchLoading is true, so the standalone child mounts and — because useSearchSections builds its list straight from currentSearchResults.data, which pagination merges into (useSearchSections.ts#L47-L74) — standaloneReports correctly grows to the full set (say 60). The moment the page lands, isSearchLoading flips false, shouldUseContextReports flips back to true, and allReports reverts to contextReports. That context list is frozen at the 50 IDs captured before the report opened (the Search list screen behind the RHP no longer updates it), so the 10 reports the arrow just paged in are thrown away.
At report 50 that leaves currentIndex === effectiveAllReports.length - 1 with hasMoreResults now false (page 2 was the last page for a 51–100 account), so the disabled condition fires (:149), and the label is "50 of 50" because previousLengthOfResults was persisted as the stale prevReportsLength (50) on the page-2 response (Search.ts#L1295-L1299). The list the arrow can see never grows past page 1, even though the snapshot did.
So !isSearchLoading is the wrong gate: it's a transient signal, and once it clears we hand authority back to a list that pagination has already made stale.
What changes do you think we should make in order to solve the problem?
Layer: the source-selection in the content component (hook/render), not the data or the API.
Latch the source on an explicit "have we paginated" signal instead of the transient loading flag. lastSearchQuery.offset starts at 0 for a page-1 result set (Search/index.tsx#L165 → saved at the report row click, #L699-L705) and only ever grows once a page is pulled. So at :127:
// offset > 0 means the result set was extended past page 1; the frozen context list is now stale.
const hasPaginated = (lastSearchQuery?.offset ?? 0) > 0;
const shouldUseContextReports = contextReports.length > 0 && !isSearchLoading && !hasPaginated;
Once you've paged, shouldUseContextReports stays false, so the standalone child stays mounted (:242) and keeps standaloneReports in sync with the snapshot as further pages land. Report 51 becomes reachable, and the counter self-corrects because the recount effect notices effectiveAllReports.length changed and rewrites previousLengthOfResults (:168) — so "50 of 50" turns into "50 of 60" and only disables at the true last report.
This is race-free: it doesn't depend on whether the page-2 response lands before or after isSearchLoading toggles. The frozen list is structurally removed from the pipeline the instant pagination begins, rather than being preferred again on the next render. It also preserves the #86238 fast-path optimization untouched for the common case (≤50 reports never paginate, so offset stays 0 and the heavy subscriptions never mount).
Verification: I traced the full save/restore sequence at the issue SHA but could not run jest in this environment (the App node_modules aren't provisioned here), so I'm giving the concrete regression instead of a fabricated number. Add to tests/unit/components/MoneyRequestReportNavigation.test.tsx, whose helper mirrors line 127: a case where the context list is frozen at 50, the snapshot list is 60, not loading, and offset = 50. Against main's selection it resolves to the 50-item context list (allReports length 50, report 55 absent) — fails; with the !hasPaginated gate it resolves to the 60-item standalone list (report 55 reachable) — passes. The four existing path-selection/cache tests are unaffected: they run with no pagination (offset undefined → hasPaginated false), so the fast path they assert is unchanged.
What alternative solutions did you explore? (Optional)
Selecting whichever list is longer is the other obvious fix, but it reverses the existing "uses fast path" assertion at test #L91-L99 (a longer standalone list would win on the pure fast path) and leans on a stale retained value rather than an explicit signal — the offset latch keeps both the test and the perf gate intact.
Growing the Search-context sortedReportIDs while the RHP is open — rejected: the list screen is frozen behind the modal on purpose, and un-freezing it re-renders the whole search list on every arrow click for no benefit the snapshot path doesn't already give us.
One thing my fix deliberately doesn't touch: the % effectiveAllReports.length wrap at :225 can still bounce you to report 1 on a 100+ account where hasMoreResults stays true at the tail. That's a distinct bounds-check bug on a different code path from this "disabled at 50" report, so I'd keep it out of scope here rather than fold two fixes into one.
🚨 Edited by proposal-police: This proposal was edited at 2026-10-09 11:16:11 UTC.
Proposal
Please re-state the problem that we are trying to solve.
When navigating through paginated expense reports in Search, the report Prev/Next controls can become unreliable at page boundaries.
Examples include:
- The Next button becomes disabled at
50 of 50, although more reports exist. - A rapid Next click at the loaded tail is dropped instead of advancing after the next page arrives.
- Controls disappear after moving to a later report because the active report is absent from a transient 50-item source.
- An unfocused Search auto-refetch can replace an expanded snapshot with page-one data and discard later loaded pages.
What is the root cause of that problem?
Several independent asynchronous flows update the same search state.
- Pagination metadata was replaced during a page request
saveLastSearchParams() uses Onyx.set(). A pagination request supplied only partial navigation data, which replaced fields retained from the previous response, including hasMoreResults and previousLengthOfResults.
While the request was in flight, the navigation component could read:
lastSearchQuery.hasMoreResults === undefined;
This made the Next button look terminal even though the previous page had confirmed more results exist.
- A paginated report can temporarily read an incomplete list
sortedReportIDs is the lightweight Search-context list. It is suitable for the first page, but it can temporarily contain only the first 50 IDs during page transitions.
If the active report is, for example, report 51, choosing that 50-item list makes:
allReports.indexOf(reportID) === -1;
Since the controls require a valid current index, the counter and arrows disappear.
- Next at a page boundary had no durable intent
At the tail of the currently loaded list, the next report ID does not yet exist locally. A click must be retained until the next page arrives. Without a scoped pending intent, the click is lost; without query scoping, a delayed response could navigate the user in a different search.
- Concurrent page requests can race
Rapid navigation near a prefetch threshold can request multiple pagination offsets for the same query before the earlier request settles. Responses can then arrive out of order and overwrite report-navigation metadata.
- An unfocused auto-refetch can discard loaded pages
useSearchAutoRefetch can issue an offset-zero refresh while an RHP report is open. An offset-zero response replaces the search snapshot collection, which can discard previously loaded page-two-and-beyond records.
What changes do you think we should make in order to solve the problem?
1. Merge incremental report-navigation state instead of replacing it
Add mergeLastSearchParams() in ReportNavigation.ts:
function mergeLastSearchParams(value: Partial<LastSearchParams>) {
Onyx.merge(ONYXKEYS.REPORT_NAVIGATION_LAST_SEARCH_QUERY, value);
}
Keep saveLastSearchParams() with Onyx.set() for creating a new Search session, where replacing the old query state remains correct.
Use mergeLastSearchParams() for pagination request and response updates in Search.ts. This preserves hasMoreResults and previousLengthOfResults while a subsequent page is loading.
2. Preserve standard offset-zero recount behavior The response handler must preserve the existing distinction between an initial Search response and report-navigation pagination:
const isReportNavigationPagination = shouldUpdateLastSearchParams && offset !== undefined && offset > 0;
For a successful offset-zero response:
- Count returned report entries for
previousLengthOfResults. - Set
allowPostSearchRecount: true.
For report-navigation pagination:
- Preserve the supplied
prevReportsLength. - Set
allowPostSearchRecount: false.
const reportCount =
offset === 0
? Object.keys(response?.data ?? {}).filter((key) => key.startsWith(ONYXKEYS.COLLECTION.REPORT)).length
: undefined;
mergeLastSearchParams({
queryJSON,
offset,
...(hasMoreResults !== undefined && {hasMoreResults}),
...(prevReportsLength !== undefined && {previousLengthOfResults: prevReportsLength}),
...(reportCount !== undefined && prevReportsLength === undefined && {previousLengthOfResults: reportCount}),
allowPostSearchRecount: !isReportNavigationPagination,
searchKey,
});
The pre-request update must keep allowPostSearchRecount: false, so stale data cannot trigger a recount before the request succeeds.
3. Serialize report-navigation pagination per query Extend the existing in-flight Search request registry with request metadata:
type InFlightSearchRequest = {
queryHash: number;
isReportNavigationPagination: boolean;
// Existing fields
};
Before starting a report-navigation pagination request, prevent another pagination request for the same query hash from starting:
const hasInFlightReportNavigationPagination = [...inFlightSearchRequests.values()].some(
(request) => request.isReportNavigationPagination && request.queryHash === queryJSON.hash,
);
if (isReportNavigationPagination && hasInFlightReportNavigationPagination) {
return;
}
Use the existing request cleanup path in both request completion and write-queue failure handling. This avoids a second module-level cache and prevents stale locks.
4. Select a list that contains the active report Continue using the lightweight Search-context list only when it covers the loaded offset:
const shouldUseContextReports = contextReports.length > (lastSearchQuery?.offset ?? 0) && !isSearchLoading;
When the preferred source does not contain the active report, select another available source that does:
const preferredReports = shouldUseContextReports ? contextReports : standaloneReports;
let allReports = preferredReports;
if (!preferredReports.includes(reportID)) {
if (standaloneReports.includes(reportID)) {
allReports = standaloneReports;
} else if (contextReports.includes(reportID)) {
allReports = contextReports;
} else if (lastValidReports?.includes(reportID)) {
allReports = lastValidReports;
}
}
This prevents a temporary empty standalone list or first-page context list from making currentIndex become -1.
5. Queue Next navigation at a boundary, scoped to the current search and report Replace the boolean pending state with a query-scoped intent:
type PendingNextNavigation = {
queryHash: number;
reportID: string;
};
At the loaded tail, retain the click only if more results are expected:
setPendingNextNavigation({queryHash, reportID});
When the list expands, consume the intent only if both the active query and active report still match:
if (pendingNextNavigation.queryHash !== queryHash || pendingNextNavigation.reportID !== reportID) {
setPendingNextNavigation(null);
return;
}
Cancel the intent on request failure, terminal results, or Previous navigation. This prevents lost Next clicks while ensuring an old response cannot advance a new search session.
6. Defer unfocused refreshes for expanded search snapshots
In useSearchAutoRefetch, do not issue an offset-zero refresh while Search is unfocused and the snapshot already contains later pages:
const hasLoadedAdditionalPages = (searchResults?.search?.offset ?? 0) > 0;
if (!isFocused && (!hasAGenuinelyNewID || hasLoadedAdditionalPages)) {
hasPendingSearchRef.current = true;
return;
}
The deferred refresh runs when Search is focused again. This preserves page-two-and-beyond snapshot data while the user navigates reports in the RHP.
What alternative solutions did you explore? (Optional)
Always use useSearchSections()
This avoids source handoff, but it mounts expensive subscriptions for every first-page report view and regresses the existing lightweight fast path.
Use a separate module-level pagination map A separate mutable map can serialize requests, but it duplicates the existing in-flight request lifecycle and creates unnecessary cleanup/test-leak risk. Extending the existing request registry keeps ownership and cleanup in one place.
Only defer non-new-item auto-refetches This still allows a genuinely new transaction created while an RHP report is open to trigger an offset-zero refresh and truncate an expanded snapshot. Expanded snapshots must defer all unfocused refreshes.
Test plan
- Open an expense-report Search with more than 100 reports.
- Navigate slowly and rapidly across the
50 → 51and100 → 101boundaries. - Verify the Next click at a boundary advances automatically when the next page arrives.
- Verify the counter and Prev/Next controls remain visible throughout navigation.
- Navigate backward across a page boundary and verify no delayed Next intent changes the route.
- Create or modify an expense while a later-page report is open in the RHP, then confirm loaded pages remain available for navigation.
- Return to the Search page and verify the deferred refresh is applied.
- Verify a standard offset-zero Search response still enables post-search recount behavior.
Proposal
What is the root cause of that problem?
I found that the navigation switches between two report lists. contextReports comes from the Search screen, while standaloneReports is rebuilt from the live Onyx snapshot. Once loading finishes, shouldUseContextReports becomes true again and the navigation discards the newly paginated standalone list.
https://github.com/Expensify/App/blob/e8445e0db782b8ed9732e7f8ef33f64f211588e4/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L117-L129
The context list is populated by an effect in the Search screen:
https://github.com/Expensify/App/blob/e8445e0db782b8ed9732e7f8ef33f64f211588e4/src/hooks/useSaveSortedReportIDs.ts#L14-L29
That screen is frozen while the report RHP is open, so the effect does not copy page 2 into the context. The snapshot-derived component is mounted only during loading and immediately unmounted afterward:
https://github.com/Expensify/App/blob/e8445e0db782b8ed9732e7f8ef33f64f211588e4/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L238-L248
As a result, page 2 can be fetched successfully, but effectiveAllReports returns to the original 50 context IDs. At report 50, that stale list makes the next button disabled:
https://github.com/Expensify/App/blob/e8445e0db782b8ed9732e7f8ef33f64f211588e4/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L145-L151
The existing test also codifies the faulty transition by expecting the shorter context list whenever loading is false, even when the snapshot list contains more reports:
https://github.com/Expensify/App/blob/e8445e0db782b8ed9732e7f8ef33f64f211588e4/tests/unit/components/MoneyRequestReportNavigation.test.tsx#L90-L99
What changes do you think we should make in order to solve the problem?
I think we should latch MoneyRequestReportNavigationContent onto the standalone source after it first enters that path. This keeps useSearchSections mounted after pagination, allowing later snapshot additions and removals to continue updating the carousel. The lightweight context path remains unchanged for report views that never paginate.
For example, the source selection would follow this small change:
+const hasUsedStandalonePath = useRef(false);
+hasUsedStandalonePath.current ||= isSearchLoading;
-const shouldUseContextReports = contextReports.length > 0 && !isSearchLoading;
+const shouldUseContextReports =
+ contextReports.length > 0 && !isSearchLoading && !hasUsedStandalonePath.current;
I would add a test that starts with 50 context reports, enters the loading state with an expanded standalone list, then finishes loading while the context remains at 50. It should continue using the standalone list and enable navigation to report 51. I would also verify that removing a report from the snapshot updates this list after pagination.
This avoids a regression in the normal fast path: useSearchSections and its heavier subscriptions still remain unmounted when no pagination or fallback has occurred. Once the live source is needed, it stays subscribed rather than retaining a stale one-time copy.
What alternative solutions did you explore? (Optional)
Always mounting useSearchSections would fix pagination, but it would remove the intentional lightweight path and subscribe every report view to the heavier Search data. Choosing whichever list is longer would fix the first append, but the standalone child would remain unmounted after loading, so its cached list would not receive later deletions or other same-length changes.
Proposal
Please re-state the problem that we are trying to solve in this issue.
On Spend > Reports, opening a report and using the header's "Next" arrow to page through the search results works fine until the 50th report. At that point "Next" becomes disabled and the user cannot advance to report #51, even though more reports exist in the underlying search results.
What is the root cause of that problem?
The report header's carousel arrows are rendered by MoneyRequestReportNavigationContent. Its "Next" disabled state is not a simple index >= length check — it also depends on whether more results are known to exist on the server:
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L148-L149
lastSearchQuery.hasMoreResults is read from the REPORT_NAVIGATION_LAST_SEARCH_QUERY Onyx key. goToNextReport is supposed to keep this key accurate by prefetching the next page of results once the user is 75% of the way through the currently-loaded page (50 items, CONST.SEARCH.RESULTS_PAGE_SIZE):
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L203-L227
That prefetch calls search() with shouldUpdateLastSearchParams: true. This is the only call site in the whole codebase that passes shouldUpdateLastSearchParams: true — every other caller (useInsightData, useRecentlyAddedData, useYourSpendData) passes false. Inside search(), before the request is even sent, this flag triggers an immediate "optimistic" save:
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/libs/actions/Search.ts#L1244-L1251
Note this object only contains queryJSON, offset, allowPostSearchRecount, and searchKey — it omits hasMoreResults and previousLengthOfResults. saveLastSearchParams writes this with Onyx.set, a full overwrite (not a merge):
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/libs/actions/ReportNavigation.ts#L6-L8
So the instant the prefetch for page 2 is dispatched, hasMoreResults is wiped from Onyx to undefined (falsy). It is only restored once the network response actually resolves, inside the .then() handler:
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/libs/actions/Search.ts#L1287-L1314
If that response is slow, gets rejected (see the .catch a few lines below, which applies failure/finally Onyx updates for the snapshot but never restores hasMoreResults on REPORT_NAVIGATION_LAST_SEARCH_QUERY), or otherwise doesn't land before the user reaches the last item in the currently-loaded 50, lastSearchQuery.hasMoreResults is still falsy at that render. Combined with currentIndex === effectiveAllReports.length - 1 being true at report #50, hideNextButton evaluates to true — the arrow disables even though the backend genuinely has more reports. Because nothing ever re-triggers a fresh save of hasMoreResults after a failed/interrupted prefetch, this can remain stuck disabled indefinitely, which matches the reported "Workaround: Unknown."
What changes do you think we should make in order to solve the problem?
The premature save at Search.ts lines 1244-1251 is unnecessary: it exists solely to bump offset ahead of the request, but since it is exclusively used by this one prefetch call site, and the authoritative, complete save (with the real hasMoreResults, offset, and previousLengthOfResults) already happens in the .then() handler at lines 1287-1314, this pre-request write only serves to destructively clear pagination state that the UI depends on while the fetch is in flight. Removing it closes the whole race: lastSearchQuery.hasMoreResults simply keeps its last known-good value until the new page's response legitimately updates it, so "Next" stays correctly enabled while page 2 loads, and if the request fails, the button remains usable and the next click will naturally retry the fetch (the request's dedupeKey is cleared in the existing .finally() block regardless of success/failure).
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/libs/actions/Search.ts#L1244-L1251
function search({
queryJSON,
searchKey,
offset,
shouldCalculateTotals = false,
prevReportsLength,
isLoading,
shouldUpdateLastSearchParams = false,
skipWaitForWrites = false,
shouldSaveRecentSearch = false,
}: {
...
Remove the if (shouldUpdateLastSearchParams) { saveLastSearchParams({...}); } block entirely (the four lines shown above at 1245-1250), leaving the rest of search() unchanged. The parameter shouldUpdateLastSearchParams is still used further down to gate the post-response save at lines 1287-1314, so it stays meaningful — only the redundant, data-dropping pre-request write is deleted.
This keeps the fix minimal and confined to the one code path that actually causes the regression, without touching saveLastSearchParams's Onyx.set semantics (which other callers, e.g. Search/index.tsx and MoneyRequestReportNavigation.tsx's own effects, rely on for full-object replacement when starting a genuinely new query).
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Spend > Reports, stepping through reports with the header's "Next" arrow works until the 50th report. There the arrow becomes disabled and the counter is stuck at "50 of 50", even though the account has more reports and the arrows themselves have already requested the next pages.
What is the root cause of that problem?
Three defects interlock: the arrows walk a list that can never grow, the pagination they trigger outruns the result set and flips hasMoreResults to false, and a failed page request latches the arrows off permanently.
Defect 1 — the arrow list is frozen at the first 50 IDs, and every page the arrows fetch is discarded.
The component prefers the Search-context list whenever it is non-empty and no page is in flight:
https://github.com/Expensify/App/blob/e8f224879b8ca1f15a0cd806c018e9a3e237ef56/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L127-L129
The only writer of that context list is an effect of the Search list screen:
https://github.com/Expensify/App/blob/e8f224879b8ca1f15a0cd806c018e9a3e237ef56/src/hooks/useSaveSortedReportIDs.ts#L17-L29
Opening a report covers that screen, FreezeWrapper freezes it, the effect never re-runs, so the context list is pinned to the 50 rows (RESULTS_PAGE_SIZE) captured at row click. The only list that can see later pages is the snapshot-backed one, but it is mounted solely while isSearchLoading:
https://github.com/Expensify/App/blob/e8f224879b8ca1f15a0cd806c018e9a3e237ef56/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L240-L242
The page-2 rows and isLoading: false arrive in the same response batch, so on the next render shouldUseContextReports is true again: the standalone child unmounts before its effect can lift the grown list, and even when it does lift it inside the loading window, the selection above snaps straight back to the 50-row context list. Every page the arrows fetch lands in the snapshot and is thrown away.
The counter agrees with the frozen list because the response handler persists previousLengthOfResults: prevReportsLength, which is the stale effectiveAllReports.length of 50 the arrow passed in:
https://github.com/Expensify/App/blob/e8f224879b8ca1f15a0cd806c018e9a3e237ef56/src/libs/actions/Search.ts#L1294-L1307
Defect 2 — the persisted offset walks past the end of the result set and poisons hasMoreResults.
From index 37 on (threshold min(50 * 0.75, 48) = 37.5), every press that sees hasMoreResults fires a search with newOffset = persisted offset + 50:
https://github.com/Expensify/App/blob/e8f224879b8ca1f15a0cd806c018e9a3e237ef56/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L203-L227
The pre-request write is an Onyx.set that omits hasMoreResults, which accidentally serializes the requests (a press during an in-flight page is gated off because the flag is blank), but each completed response restores the flag, so the offset still advances one full page per response while the list stays at 50 (defect 1):
https://github.com/Expensify/App/blob/e8f224879b8ca1f15a0cd806c018e9a3e237ef56/src/libs/actions/Search.ts#L1247-L1254
The threshold therefore stays satisfied for all 13 presses between index 37 and 49: the offset walks 50, 100, 150... past the end of the result set, each page merged into the snapshot and discarded, until a response reports hasMoreResults: false and the disable condition becomes true at index 49:
https://github.com/Expensify/App/blob/e8f224879b8ca1f15a0cd806c018e9a3e237ef56/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L148-L149
This is why the symptom is "disabled at 50" regardless of account size — the >100-report modulo wrap at L225 is rarely reachable because the flag is already dead before index 49. The Search list itself guards against exactly this drift by deriving the next page from the snapshot's own cursor instead of a persisted offset; the arrows have no such guard:
https://github.com/Expensify/App/blob/e8f224879b8ca1f15a0cd806c018e9a3e237ef56/src/components/Search/index.tsx#L843-L851
Defect 3 — one failed page request disables the arrows forever.
saveLastSearchParams is Onyx.set, the wipe happens before the request, and the .catch applies the snapshot failure data but never restores the flag, so after a single failed page request hasMoreResults stays undefined with no retry path:
https://github.com/Expensify/App/blob/e8f224879b8ca1f15a0cd806c018e9a3e237ef56/src/libs/actions/Search.ts#L1322-L1329
Unlike the list view, which re-arms itself via wantedOffsetRef:
https://github.com/Expensify/App/blob/e8f224879b8ca1f15a0cd806c018e9a3e237ef56/src/components/Search/index.tsx#L886-L899
What changes do you think we should make in order to solve the problem?
All in MoneyRequestReportNavigationContent, plus one hardening in the action.
1. Keep the snapshot-backed list mounted once the arrows have paged past the context list, and let the longer list win. The context list is a render-time cache of a frozen screen; once lastSearchQuery.offset reaches its length it is provably incomplete:
// The context list is a render-time cache of the frozen Search screen. Once the arrows
// have requested a page beyond it, only the snapshot-backed standalone list is complete.
const hasPaginatedPastContext = (lastSearchQuery?.offset ?? 0) >= contextReports.length;
const shouldUseContextReports = contextReports.length > 0 && !isSearchLoading && standaloneReports.length <= contextReports.length;
{(!shouldUseContextReports || hasPaginatedPastContext) && <MoneyRequestReportNavigationStandalone onReportsChange={setStandaloneReports} />}
For accounts that never hit the page boundary, offset stays below the rows the list screen had loaded (it is saved on row click at Search/index.tsx#L700-L706), so the standalone child never mounts and the lightweight fast path from #86238/#94928 is untouched. Once page 2 lands, the child lifts the 100-row list, the recount effect rewrites the counter to "of 100", and the arrow stays enabled through report 51.
2. Derive the next page from the snapshot cursor, mirroring fetchMoreResults, and skip pages that are already loaded or in flight. The component already subscribes to the snapshot with a lightweight selector for isLoading; extend it to also return search.offset, then in goToNextReport:
const nextOffset = snapshotOffset + CONST.SEARCH.RESULTS_PAGE_SIZE;
const isPageCoveredOrInFlight = isSearchLoading || nextOffset <= (lastSearchQuery.offset ?? 0);
if (currentIndex + 1 >= threshold && lastSearchQuery?.hasMoreResults && !isPageCoveredOrInFlight) {
// fire search({..., offset: nextOffset, ...}) as today
}
A run of presses now requests at most the one page the snapshot does not cover yet, so the offset can never outrun the result set and hasMoreResults is never flipped false by an overrun request.
3. Never wrap at the tail. Replace the modulo in goToNextReport with a bounds check: if currentIndex + 1 is past the end of the list, stay put while the page is in flight and advance once the list grows, instead of teleporting back to report 1.
const nextIndex = currentIndex + 1;
if (nextIndex >= effectiveAllReports.length) {
// Next page still in flight; the list will grow and the arrow re-enables.
return;
}
goToReportId(effectiveAllReports.at(nextIndex));
4. Make the flag survive the request. Carry the previous hasMoreResults through the pre-request saveLastSearchParams write and restore it in the .catch, so a network blip leaves the arrow enabled and the next press retries. This is safe once change 2 guards re-fires.
Change 1 fixes the reported repro (report 51 reachable, counter correct); changes 2-4 remove the overrun and failure modes that would otherwise re-disable the arrow at any later page boundary.
Working branch with the fix and the regression tests: fix/101453-next-arrow-pagination (compare). The three new pagination tests fail on current main and pass with the fix; typecheck, lint and the React Compiler compliance check pass.
What specific scenarios should we cover in automated tests to prevent reintroducing the issue?
The existing tests/unit/components/MoneyRequestReportNavigation.test.tsx asserts which list is picked but never that the list grows after a page lands — exactly the untested gap. Implemented on fix/101453-next-arrow-pagination — they render the real component against a seeded Onyx store; the first three fail on current main and all pass with the fix:
- Given a 50-row context list with page 2 requested and landed in the snapshot, then the carousel adopts the grown list: Next stays enabled at index 49, the count is re-persisted as 100, and pressing Next opens report 51.
- Given a persisted offset that has run ahead of the snapshot cursor, when Next fires a page request, then it targets the first page the snapshot does not cover (cursor + page size), never persisted offset + page size.
- Given the next page is still in flight, when Next is pressed on the last loaded report, then no duplicate request fires and the carousel holds position instead of wrapping to report 1.
- Given results that fit one page (
offset0), the standalone child never mounts, preserving the fast path from #86238/#94928.
What alternative solutions did you explore? (Optional)
- Only stop preferring the context list once
offsetreaches its length, with no cursor guard. Unblocks the reported repro (the standalone list survives and lifts page 2) but keeps defects 2-3: the persisted offset still advances ahead of what is loaded, a press landing at the boundary mid-flight shows a disabled arrow, and one failed page request still kills navigation with no retry. - Mount
useSearchSectionsunconditionally, or unfreeze the Search screen behind the modal. Correct but re-adds the heavy card-feed/report-NVP/bank-account subscriptions on every report open that the fast path from #86238/#94928 exists to avoid. - Raise
RESULTS_PAGE_SIZE. Moves the wall from 50 to N without removing it.
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Spend > Reports, opening the first report and then clicking the "Next" navigation arrow repeatedly works until the 50th report. At that point the "Next" arrow is disabled, so report 51 can never be opened, and the counter still reads "50 of 50" even though the search has more results.
What is the root cause of that problem?
50 is exactly one search page, so the failure happens precisely at the first page boundary:
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/CONST/index.ts#L7213-L7214
The report carousel picks its list of reports here, always preferring the search-context list whenever that list is non-empty and no page is in flight:
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L127-L129
That context list is written only from inside the Search list component:
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/hooks/useSaveSortedReportIDs.ts#L17-L29
While a report is open on top of the search list, that list screen is covered and suspended, so the effect above never re-runs. The context therefore stays pinned to the 50 report IDs of page one, and it is stored in provider state, so it survives and keeps winning over the live list. As a result effectiveAllReports.length stays 50 even after the carousel's own pagination request has merged page two into the search snapshot.
That frozen length then makes the prefetch condition permanently true. The threshold is Math.min(50 * 0.75, 50 - 2) = 37.5, so from index 37 onward every single "Next" press re-fires a search, and each one derives the next page by adding a page size to the previously persisted offset:
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L203-L227
Because the persisted offset advances with every response but the list never grows, the offset walks 50, 100, 150 and so on — one page per press — and runs past the end of the result set long before the user reaches index 49. The last of those responses persists hasMoreResults: false, and at report 50 the disable condition becomes true:
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L148-L151
So the arrow is disabled while the carousel still holds only the first 50 reports, which is also why the counter never moves past "of 50".
The Search list itself already guards against exactly this drift by deriving the next page from the snapshot's own cursor rather than a locally held offset; the carousel does not:
https://github.com/Expensify/App/blob/920d6272af93fcedd1f9bfa46ffeba46d1b99177/src/components/Search/index.tsx#L842-L849
What changes do you think we should make in order to solve the problem?
Two changes in src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx.
First, let the carousel list grow beyond the frozen context list. Keep the cheap context fast path for the normal case, but once the current index reaches the prefetch threshold of the context list, also render the standalone source that derives the list from the search snapshot, and stop preferring the context list when the standalone list is longer. In practice that means computing the threshold from the context list length (so the choice is not circular), rendering MoneyRequestReportNavigationStandalone when the index has reached that threshold and the search still reports more results, as well as on the existing slow path, and adding "the standalone list is not longer than the context list" to the condition that selects the context list. Reports fetched by pagination then actually appear in the carousel list, so the counter reflects the real total and hideNextButton no longer fires at report 50.
Second, stop the requested offset from outrunning what is loaded. In the next-report handler, derive the next page from the search snapshot's own cursor for the current query hash plus one page size — the same rule the Search list uses — instead of adding a page size to the previously persisted offset, and skip the request when a page covering that offset is already loaded or already in flight. A single press then advances pagination by at most one page, so repeated presses near the end of a page can no longer skip past the end of the result set and persist a false hasMoreResults.
With both changes, by the time the user reaches report 50 page two is present in the carousel list, the arrow stays enabled, and clicking it opens report 51.
Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/101453-report-carousel-page-boundary?expand=1
What alternative solutions did you explore? (Optional)
Only relaxing the disable condition, for example never disabling the arrow once hasMoreResults has been true during the session. That hides the symptom but the carousel would still hold only 50 reports, so the arrow would wrap around to report 1 instead of opening report 51.
Refreshing the stored sorted report IDs from the report view itself. That would require the report screen to recompute the sorted sections that the list screen owns, duplicating that work on a navigation hot path; reusing the existing standalone slow path is cheaper and keeps a single source for that computation.
Always mounting the standalone source instead of gating it. This is correct but re-introduces the heavy subscriptions on every report view that the context fast path was added to avoid; gating it on the prefetch threshold keeps that performance win for the common case where the user never reaches the end of the first page.
Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Spend > Reports, stepping through reports with the Next arrow stops at "50 of 50": the arrow is disabled even though the account has more than 50 reports and page 2 was already requested.
What is the root cause of that problem?
- The arrows walk
effectiveAllReports, which on the fast path iscontextReports, i.e.sortedReportIDsfrom the app-level Search context (L127-L129, L270-L271). - The only writer of
sortedReportIDsisuseSaveSortedReportIDs, an effect of the Search list screen (useSaveSortedReportIDs.ts#L14-L29, called at Search/index.tsx#L811). It holds the 50 rows loaded when the row was clicked (RESULTS_PAGE_SIZE= 50). The report opens in an RHP over that screen; while the modal is up the list behind it does not re-run that effect, so the context list stays at those 50 IDs the whole time we are in the report. The QA video shows exactly that: the counter never leaves 50. goToNextReportdoes request page 2 at 75% (L207-L223) and the response merges 50 more reports into the snapshot and writeshasMoreResults/previousLengthOfResultsback (Search.ts#L1287-L1315). But the component only reads the snapshot-backed list (MoneyRequestReportNavigationStandalone->useSearchSections, L102-L112) whileisSearchLoadingis true (L242). The instant the page lands,isLoadingflips false in the same Onyx batch,shouldUseContextReportsis true again, the standalone child is unmounted before its effect can lift the 100-row list, andallReportssnaps back to the stale 50.- Structural cause: the fast/slow switch keys on "is a page in flight", not on "does the context list still cover the pages we have loaded". Every page fetched from the report view is fetched and immediately discarded.
- So at index 49,
hideNextButton = !hasMoreResults && currentIndex === 49(L149) is true (page 2 answeredhasMoreResults: false, the account has at most 100 reports), the count effect (L168-L173) keepspreviousLengthOfResultsat 50, and we see "50 of 50" with report 51 unreachable. With more than 100 reports the button stays enabled but(currentIndex + 1) % length(L225) wraps to report 1: same cause, report 51 still unreachable.
Affected paths: one component, one caller (MoneyReportHeaderMoreContent.tsx#L98). Narrow vs wide only toggles the counter text (L245); all layouts and platforms share this one .tsx. The Prev arrow (L229-L236) walks the same list, so the fix covers it too.
What changes do you think we should make in order to solve the problem?
One condition in MoneyRequestReportNavigationContent (L127): stop preferring the context list once the report view has paged past what the context holds. lastSearchQuery.offset is exactly that signal: search() writes it the moment the arrow requests a page (Search.ts#L1244-L1251) and the response keeps it (L1295-L1301).
// The context list is a snapshot of the Search screen. Once the report view has
// paged past it, the snapshot-backed standalone list is the only complete one.
const contextCoversLoadedPages = contextReports.length > (lastSearchQuery?.offset ?? 0);
const shouldUseContextReports = contextCoversLoadedPages && !isSearchLoading;
Repro walk-through: offset becomes 50 when page 2 is requested; the context has 50 IDs, so 50 > 50 is false, the standalone child stays mounted, its effect lifts the 100-row useSearchSections list when the page lands, the count effect rewrites previousLengthOfResults to 100 ("39 of 100"), Next stays enabled through 51 and is only disabled at 100 of 100 when hasMoreResults is really false. With more than 100 reports the next page is requested at 75 and the list grows again.
Regression safety: when no page was fetched from the report view, offset is the value the Search screen saved on row click (Search/index.tsx#L697-L705), always below the rows it had loaded, so the fast path and the perf intent of #94928 / #86238 (heavy subscriptions only on the slow path) are untouched; lastValidReports (L141-L145) and the existing unit tests keep working because contextReports.length > 0 is implied.
Secondary (optional): L225 and L234 use modulo, so a click on the last item while the next page is still in flight (slow network) jumps to report 1 instead of waiting; a bounds check after the fetch (if (currentIndex + 1 >= effectiveAllReports.length) return;) makes that click a no-op until the page lands. Not needed for the reported repro, where the page is requested at 75% and lands long before 50.
Why the obvious spot fixes do not work:
- Carrying
hasMoreResultsthrough the optimisticsaveLastSearchParamsinsearch()(or switching it toOnyx.merge): the flag is only blank between request and response; the response writes it back (L1295-L1301) as false because nothing exists beyond 100. The list is still 50 long, so at index 49 the button is disabled exactly as before. - Not disabling Next while
isSearchLoading: after the page lands, loading is false and the list is still 50, so nothing changes.
What alternative solutions did you explore? (Optional)
- Always mount
MoneyRequestReportNavigationStandalone/ "prefer the longer list": prefer-longer is a no-op as written, because the standalone child is unmounted on the fast path andstandaloneReportscan never grow; always mounting works but re-adds the card-feed / report-NVP / bank-account subscriptions on every report open that#94928removed on purpose. - Un-freezing the Search screen behind the modal: re-renders the whole list on every arrow click and keeps the report view dependent on a screen it cannot see.
- Raising
RESULTS_PAGE_SIZE: moves the wall from 50 to N.
🤖 ProposalPolice™ is tracking duplicate proposals for this issue using an OpenAI Conversation. This comment stores that Conversation's ID and can be safely ignored.
Proposal updated — added compare branch with implementation.
Proposal
What is the root cause of that problem?
When a user opens a report from Spend > Reports and clicks Next through the first page, the Next arrow turns off at "50 of 50" and report 51 cannot be opened.
The arrows walk sortedReportIDs from Search context. MoneyRequestReportNavigationContent prefers that list whenever it is non-empty and no search is in flight:
https://github.com/Expensify/App/blob/8d18287c9aee3af5a127e82a0e0ca186adb0eeac/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L127-L129
The only writer of that list is useSaveSortedReportIDs, called from the Search list screen:
https://github.com/Expensify/App/blob/8d18287c9aee3af5a127e82a0e0ca186adb0eeac/src/hooks/useSaveSortedReportIDs.ts#L17-L29
https://github.com/Expensify/App/blob/8d18287c9aee3af5a127e82a0e0ca186adb0eeac/src/components/Search/index.tsx#L811
Opening a report covers that screen with the report panel. FreezeWrapper then stops its effects, so the IDs from page 1 stay stuck at CONST.SEARCH.RESULTS_PAGE_SIZE (50):
https://github.com/Expensify/App/blob/8d18287c9aee3af5a127e82a0e0ca186adb0eeac/src/libs/Navigation/AppNavigator/FreezeWrapper/index.tsx#L15-L17
https://github.com/Expensify/App/blob/8d18287c9aee3af5a127e82a0e0ca186adb0eeac/src/CONST/index.ts#L7235
Clicking Next still requests page 2:
https://github.com/Expensify/App/blob/8d18287c9aee3af5a127e82a0e0ca186adb0eeac/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L207-L223
search() merges the new rows into the Onyx snapshot, but it does not write sortedReportIDs. The snapshot list from useSearchSections is mounted only while isSearchLoading is true, then dropped, so it never fills that gap either.
At report 50, currentIndex is the last item of the frozen list, so hideNextButton disables the arrow:
https://github.com/Expensify/App/blob/8d18287c9aee3af5a127e82a0e0ca186adb0eeac/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L149
The context picker is doing what it was built to do. Pagination never writes the IDs that picker reads.
What changes do you think we should make in order to solve the problem?
- In
MoneyRequestReportNavigationContent, keep the standaloneuseSearchSectionschild mounted after the arrows have fetched past page 1, not only whileisSearchLoadingis true.
https://github.com/Expensify/App/blob/8d18287c9aee3af5a127e82a0e0ca186adb0eeac/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L242
Today that child unmounts as soon as page 2 arrives, so nothing can copy the new IDs into context. Use the offset the arrows already persist on lastSearchQuery:
const hasFetchedNextPage = (lastSearchQuery?.offset ?? 0) > 0;
const shouldMountStandalone = !shouldUseContextReports || hasFetchedNextPage;
That leaves a live snapshot reader on screen once the result set has grown past the frozen page-1 list.
- In that standalone child, call
useSaveSortedReportIDswith the snapshot-derived report IDs, the same hook the Search list uses.
https://github.com/Expensify/App/blob/8d18287c9aee3af5a127e82a0e0ca186adb0eeac/src/hooks/useSaveSortedReportIDs.ts#L17-L29
useSaveSortedReportIDs(standaloneReports);
Leave shouldUseContextReports unchanged. After page 2 lands, the hook writes the longer ID list into Search context. The existing picker then walks 51+ reports, hideNextButton stays off until the real last report, and the recount around line 168 updates the "N of M" label.
This writes back into the list the arrows already trust, from a component that is not frozen. search(), FreezeWrapper, and the Next modulo stay as they are.
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.
Proposal
What is the root cause of that problem?
The disable is not decided by the snapshot, so re-sourcing it there changes nothing. hideNextButton ANDs lastSearchQuery.hasMoreResults — the persisted REPORT_NAVIGATION_LAST_SEARCH_QUERY copy — with a position test:
https://github.com/Expensify/App/blob/56a14aaaa34d8a8680b043a6d8d521558f8cced4/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L148-L149
With 51–100 matching reports that flag is false truthfully: page 2 was fetched and was the last page; the snapshot agrees. The bug is not a stale flag but a pagination signal ANDed with a position signal computed over a list that never absorbed the page it just fetched.
"Prefer whichever list is longer" cannot fire. standaloneReports is fed only by the child mounting useSearchSections, itself gated on the fast path losing:
https://github.com/Expensify/App/blob/56a14aaaa34d8a8680b043a6d8d521558f8cced4/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L127
While the context path wins, standaloneReports is [], so that comparison is 50 against 0 and never flips. The tie must break on a signal available without that subscription.
Repro trace:
threshold = Math.min(50 * 0.75, 48) = 37.5, so from report 38 the arrow fires page 2 atoffset = 50:
https://github.com/Expensify/App/blob/56a14aaaa34d8a8680b043a6d8d521558f8cced4/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L207-L226
- Page 2 returns the tail with
hasMoreResults: false, persisted alongsidepreviousLengthOfResults: prevReportsLength— the length before the fetch, 50, so the counter's right-hand number never moves:
https://github.com/Expensify/App/blob/56a14aaaa34d8a8680b043a6d8d521558f8cced4/src/libs/actions/Search.ts#L1290-L1305
- They land in the snapshot, but when
isSearchLoadingflips false the component swaps back tocontextReports, written only from the Search list screen (useSaveSortedReportIDs) — frozen behind the report modal, so it cannot have absorbed page 2.
At report 50: index 49 is the last index of the pinned list, hasMoreResults is honestly false, the arrow disables, and the label reads "50 of 50". Pagination succeeded and the arrow still reports end-of-results.
With >100 reports, threshold derives from effectiveAllReports.length, which never grows, so every click past 38 re-satisfies it, and newOffset = (lastSearchQuery.offset ?? 0) + 50 advances per click, not per page appended — 50, 100, 150… The cursor walks off the result set, the first empty tail page returns hasMoreResults: false, and it is pinned there.
What changes do you think we should make in order to solve the problem?
All edits are in MoneyRequestReportNavigation.tsx; the pagination one ports the Search list's infinite scroll, whose comment names the drift:
https://github.com/Expensify/App/blob/56a14aaaa34d8a8680b043a6d8d521558f8cced4/src/components/Search/index.tsx#L837-L853
1. Widen the snapshot selector (same idiom as buildSnapshotGuardSelector), so the cheap path gains a pagination cursor without mounting useSearchSections:
type SearchMeta = {isLoading: boolean; offset: number; hasMoreResults: boolean};
const searchMetaSelector = (snapshot: OnyxEntry<SearchResults>): SearchMeta => ({
isLoading: !!snapshot?.search?.isLoading,
offset: snapshot?.search?.offset ?? 0,
hasMoreResults: !!snapshot?.search?.hasMoreResults,
});
2. Retire the context list once pagination has started (line 127). A non-zero snapshot cursor means a page landed the frozen screen could not have written, so the context list is stale by construction:
const shouldUseContextReports = contextReports.length > 0 && !searchMeta.isLoading && searchMeta.offset === 0;
Users who never paginate keep the cheap path, preserving the fast path #86238 added. Once the list grows, the effect at :168 rewrites previousLengthOfResults and the counter self-corrects to "50 of 63".
3. Anchor the next offset to the snapshot cursor and the data length (lines 207–210), as fetchMoreResults does, so a click cannot request a page the list has not reached:
const canFetchNextPage = searchMeta.offset <= effectiveAllReports.length - CONST.SEARCH.RESULTS_PAGE_SIZE;
if (currentIndex + 1 >= threshold && searchMeta.hasMoreResults && canFetchNextPage && !searchMeta.isLoading) {
const newOffset = searchMeta.offset + CONST.SEARCH.RESULTS_PAGE_SIZE;
It also drops the dependence on lastSearchQuery.offset, which saveLastSearchParams (an Onyx.set) rewrites pre-flight at Search.ts:1247-1253.
4. Stop wrapping at the tail (line 225). (currentIndex + 1) % length throws the user from report 50 back to report 1 while a page is in flight:
const nextIndex = currentIndex + 1;
if (nextIndex >= effectiveAllReports.length) {
return;
}
goToReportId(effectiveAllReports.at(nextIndex));
Test: MoneyRequestReportNavigation.test.tsx asserts only which list is picked, never that it grows after a page lands. Add a case seeding a 50-ID context list plus a 63-report snapshot at search.offset: 50, hasMoreResults: false, asserting Next is enabled at index 49 and the label reads "50 of 63".
What alternative solutions did you explore? (Optional)
Un-freezing the Search screen while the report modal is open. Rejected: it re-renders the whole search list on every arrow click and leaves the per-click offset escalation — the part that makes the >100-report case unrecoverable rather than merely stuck.
Proposal updated. Traced Search.ts deeper, the root cause now covers why the arrow disables at 50 on any account size (the persisted offset outruns the results one page per response and poisons hasMoreResults) plus the failed page request case that bricks the arrows permanently. Fix reworked to page from the snapshot cursor the way the list view already does.
Implemented and verified on a working branch: https://github.com/dilshodmackbook-sketch/App/tree/fix/101453-next-arrow-pagination (compare). The three new regression tests fail on current main and pass with the fix.
🚨 Edited by proposal-police: This proposal was edited at 2026-10-09 12:15:41 UTC.
Proposal
What is the root cause of that problem?
The carousel does load page 2, but two things stop the user from reaching it.
1. A page-1 refresh from the Search list behind the report overwrites page 2.
At report 38 the arrow requests offset 50, and the response merges into the snapshot:
https://github.com/Expensify/App/blob/6a1b74cc1fec1a445bc849de22ed6b75fa1c6a1d/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L215-L234
The Search list stays mounted under the report RHP. Its refetch hook fires whenever a displayed transaction gets a new Onyx object:
https://github.com/Expensify/App/blob/6a1b74cc1fec1a445bc849de22ed6b75fa1c6a1d/src/hooks/useSearchAutoRefetch.ts#L110-L117
Opening a report runs OpenReport, which rewrites its transactions (on my account only taxCode: "" → null), so the check reports an edit. Search is unfocused but still the topmost fullscreen route, so the hook refetches at once, with the list's own offset of 0:
https://github.com/Expensify/App/blob/6a1b74cc1fec1a445bc849de22ed6b75fa1c6a1d/src/hooks/useSearchAutoRefetch.ts#L118-L126
https://github.com/Expensify/App/blob/6a1b74cc1fec1a445bc849de22ed6b75fa1c6a1d/src/hooks/useSearchAutoRefetch.ts#L163-L168
The offset-0 response is onyxMethod: "set" on snapshot_<hash>, so it replaces the snapshot and drops page 2. At report 50 the list is back to 50 items and Next is disabled:
https://github.com/Expensify/App/blob/6a1b74cc1fec1a445bc849de22ed6b75fa1c6a1d/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L161
2. The page-2 request waits behind the write queue.
search() saves ReportNavigationLastSearchQuery without hasMoreResults right away, then waits for every queued write before it sends the request:
https://github.com/Expensify/App/blob/6a1b74cc1fec1a445bc849de22ed6b75fa1c6a1d/src/libs/actions/Search.ts#L1358-L1365
https://github.com/Expensify/App/blob/6a1b74cc1fec1a445bc849de22ed6b75fa1c6a1d/src/libs/actions/Search.ts#L1466-L1484
Every Next press queues an OpenReport write. When the user clicks quickly, the page-2 request sits behind all of them, and at report 50 Next stays disabled until the queue drains (about a minute in the C+ video).
I reproduced both on web against the production backend (account with 100+ reports). On main: "50 of 50", Next still disabled after 150s, 36 offset-0 refetches during the walk. With only fix 1 and each OpenReport delayed by 1.5s: "50 of 50", Next disabled for 75s, then "50 of 100".
Verified on web; the path has no platform fork, so Android and iOS will be verified in the PR. More than 50 reports are needed because only a second page can be lost. Cause 1 started with #98558 (2026-08-14), which added the identity check.
What changes do you think we should make in order to solve the problem?
- In
useSearchAutoRefetch, when the refetch is about to fire while Search is not focused and nothing new appeared, defer it with the flag the hook already uses for inactive Search:
const hasAGenuinelyNewID = (isChat ? reportActionsIDs : addedTransactionIDs).some((id) => !existingSearchResultIDsSet.has(id));
+ if (!isFocused && !hasAGenuinelyNewID) {
+ hasPendingSearchRef.current = true;
+ return;
+ }
+
This refetch only updates rows the RHP covers; the existing pending path runs it once Search is focused again. New entries created from an RHP (the case the L118-L121 comment protects) still refetch at once.
- Send the carousel's page request without waiting for the write queue. The flag already exists for searches that must not sit behind the queue, and a Search response only writes the snapshot key, so it can't overwrite pending optimistic data:
isLoading: isSearchLoading,
shouldUpdateLastSearchParams: true,
+ skipWaitForWrites: true,
});
Results (web, production backend, Next about once a second, each OpenReport delayed by 1.5s to match the C+ video):
| At report 50 | |
|---|---|
| main | "50 of 50", Next disabled for good |
| fix 1 only | "50 of 50", Next disabled for 75s, then "50 of 100" |
| fix 2 only | "50 of 50", Next disabled (page-1 refetch still wipes page 2) |
| both | "50 of 100", Next enabled, reached 70; page 2 sent 0.3s after report 38 |
Without the delay, both changes also go 1 → 70 without stopping, at 0.9s and at 0.4s between clicks, with one search() call in the whole walk.
Regression safety:
- Back on the list after the walk (run): the deferred refetch fired, so edits made in the report still refresh the list.
- New expense created from an RHP over Search (read from code):
hasAGenuinelyNewIDis true, so the refetch stays immediate. - Focused, offline and non-topmost cases (read from code): unchanged; existing tests mock
useIsFocusedas true. - Page request skipping the queue (read from code): the query comes from results already on screen, so it doesn't depend on data a queued write delivers.
- Limitation: on wide layout, a total edited inside the RHP updates when the RHP closes, not while it is open.
Tests:
- A result transaction changes while
useIsFocusedis false →searchis not called; it is called once after focus returns. - A transaction that is not in the results is added while unfocused →
searchis called immediately. - Pressing Next past the threshold calls
searchwithskipWaitForWrites: true.
Demo branch: https://github.com/yusufdeveloper2903/App/compare/6a1b74cc1fec1a445bc849de22ed6b75fa1c6a1d...proposal/101453-v2
What alternative solutions did you explore? (Optional)
- Keep the carousel on the snapshot list once it has paged (a latch on
lastSearchQuery.offset, or my earlierhasFetchedMorePagesflag). Applied on the same account, each reached "40 of 100" / "40 of 60", fell back to "41 of 50" and ended "50 of 50" with Next disabled: they read the snapshot the refresh overwrites. - Refetch at the snapshot's offset instead of 0. A page-1 refresh already in flight when page 2 is requested can still land last and wipe it, and the three calls per report open remain.
- Only skip the write queue (fix 2 alone). Tested: page 2 arrives quickly but the page-1 refetch still replaces it, so it ends at "50 of 50".
Proposal
Please re-state the problem that we are trying to solve in this issue.
Paging through Spend > Reports with the header's "Next" arrow works up to the 50th report; there the arrow is disabled and the counter is stuck at "50 of 50", so report 51 can never be opened even though the arrow has already fetched the next page of results into the search snapshot.
What is the root cause of that problem?
50 is exactly CONST.SEARCH.RESULTS_PAGE_SIZE, so the failure is at the first page boundary.
MoneyRequestReportNavigationContent has two sources for the list the arrows walk: the pre-computed sortedReportIDs from the Search context (contextReports), and standaloneReports, lifted from the child that mounts useSearchSections and reads the live snapshot. One line in src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx decides which wins:
const shouldUseContextReports = contextReports.length > 0 && !isSearchLoading;
const allReports = shouldUseContextReports ? contextReports : standaloneReports;
contextReports can only be written by useSaveSortedReportIDs, an effect of the Search list screen (src/components/Search/index.tsx). Opening a report covers that screen and FreezeWrapper freezes it, so for the whole time the arrows are on screen that list is pinned to the 50 IDs loaded when the row was clicked.
goToNextReport does fetch page 2 at the 75% threshold and search() merges those reports into the snapshot, so standaloneReports is correct — but only while isSearchLoading is true. The rows and isLoading: false arrive in the same Onyx batch, so on the next render shouldUseContextReports is true again, the standalone child unmounts and allReports snaps back to the frozen 50. Every page the arrows fetch is fetched and thrown away.
At report 50 that leaves currentIndex === effectiveAllReports.length - 1 while page 2 answered hasMoreResults: false (51–100 reports), so
const hideNextButton = !lastSearchQuery?.hasMoreResults && currentIndex === effectiveAllReports.length - 1;
is true and the arrow disables. The counter shows "50 of 50" because previousLengthOfResults was persisted as the stale prevReportsLength (50) in Search.ts, and the component's own recount effect cannot correct it while effectiveAllReports.length is still 50.
So !isSearchLoading is the wrong gate: it is a transient signal, and when it clears authority is handed back to a list that pagination has already made stale.
What changes do you think we should make in order to solve the problem?
Two changes, both in MoneyRequestReportNavigationContent.
1. Stop preferring the context list once the report view has paged past what that list holds. lastSearchQuery.offset is the exact signal: it is the offset the result set was last extended to, written by search() and persisted across renders in Onyx, so it survives the report-to-report Navigation.setParams transitions that component-local state does not.
// The Search list screen that writes contextReports is frozen behind the report view, so it can
// never absorb the pages the arrows fetch. Once the persisted offset has reached the end of the
// context list, that list no longer covers the loaded results.
const hasPaginatedPastContextReports = (lastSearchQuery?.offset ?? 0) >= contextReports.length;
const shouldUseContextReports = contextReports.length > 0 && !isSearchLoading && !hasPaginatedPastContextReports;
Comparing the offset against the context length (rather than testing offset > 0) matters for performance: the Search list also persists its own offset when a row is clicked (saveLastSearchParams in src/components/Search/index.tsx), so a user who scrolled the list to offset 100 before opening a report has 150 complete IDs in the context. offset > 0 would drop that user onto the heavy useSearchSections path for no reason, undoing the fast path from #86238; 100 >= 150 is false, so the cheap path is kept. The moment the arrow requests offset 150, the condition flips and the snapshot-backed list takes over for good.
No flicker on the switch: for the one render before the standalone child lifts its list, allReports is empty, liveCurrentIndex is -1 and the existing lastValidReports cache keeps effectiveAllReports at the previous list, so the arrows never disappear.
Once the list grows, everything downstream self-corrects: the recount effect rewrites previousLengthOfResults ("50 of 63"), hideNextButton only fires on the real last report, and the 75% prefetch threshold now grows with the list, so the persisted offset advances one page per page appended instead of one page per click — which is what makes the offset run past the end of the result set on larger accounts today.
2. Don't wrap at the tail. goToNextReport ends with (currentIndex + 1) % effectiveAllReports.length, so on an account with more than 100 reports pressing Next on the last loaded report while its page is still in flight throws the user back to report 1 instead of forward:
const nextIndex = currentIndex + 1;
if (nextIndex >= effectiveAllReports.length) {
return;
}
goToReportId(effectiveAllReports.at(nextIndex));
The button is only enabled at the tail while more results are expected, so holding position until the page lands is the correct behaviour there.
Nothing else changes: search(), saveLastSearchParams, FreezeWrapper and the Search list are untouched, and goToPrevReport walks the same list so it benefits from the same fix.
Verified locally: the change passes the test in tests/unit/components/MoneyRequestReportNavigation.test.tsx, and that test fails on main without it. Comparison branch: https://github.com/Expensify/App/compare/e8f224879b8ca1f15a0cd806c018e9a3e237ef56...sangnv00452:Expensify-App:proposal/101453
What specific scenarios should we cover in automated tests?
- Context list frozen at the 50 first-page IDs, snapshot/standalone list holding 63 reports, lastSearchQuery with offset 50 and hasMoreResults false, current report 50: the next arrow is enabled, the recount persists previousLengthOfResults 63, the label reads '50 of 63' and pressing Next navigates to report 51 (added; fails on main, where the arrow is disabled).
- Search list already scrolled to offset 100 with 150 context IDs before the report was opened: the component stays on the cheap context path and useSearchSections is never mounted, guarding the fast path from #86238 (added).
- Current report is the last loaded one while hasMoreResults is true: pressing Next does not call Navigation.setParams, i.e. it holds position instead of wrapping back to the first report (added; fails on main, which navigates to report 1).
- Existing source-selection and lastValidReports cache tests still pass: fast path when the context list is non-empty and not loading, standalone path when the context is empty or a page is in flight, and the cached list surviving the isSearchLoading toggle after the current report drops out.
What alternative solutions did you explore? (Optional)
Gating on offset > 0 alone: simplest, but it also fires for a Search list that was paginated before the report was opened, where the context list is complete. That mounts the heavy useSearchSections subscriptions on the report view for no benefit.
Latching the standalone path with a useRef/useState flag once loading was ever seen: any unrelated search refresh (for example after submitting a report) latches it permanently, and component state is not guaranteed to survive the report-header subtree being recreated on route changes. The persisted offset has neither problem.
Preferring whichever list is longer: standaloneReports is only populated while the standalone child is mounted, and the child is only mounted when the context path loses, so the comparison is 50 against 0 and never flips.
Writing the paginated IDs back into the Search context from the report view: it makes the report view a writer of a list the Search screen owns, and the context list would still be a copy that can go stale; reading the snapshot directly keeps one source of truth.
Removing the pre-request saveLastSearchParams write in Search.ts (so hasMoreResults is not cleared while a page is in flight): that write is a real wart, but it is not what produces this bug — with 51–100 reports the completed page-2 response legitimately persists hasMoreResults: false, and the arrow still disables because the list never grew. Changing it alone leaves report 51 unreachable, and it touches an action shared with other search callers.
Proposal
What is the root cause of that problem?
The Next arrow goes out because the arrow's own prefetch erases hasMoreResults the moment the request is sent, and it stays erased until that response has been processed. A user who reaches the last loaded report before page 2 comes back finds the arrow disabled.
The arrow is disabled by this check:
https://github.com/Expensify/App/blob/a26a5631a50f1f9790afc109212e3cb9254d575b/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L148-L149
Around report 38 the arrow asks for the next page:
https://github.com/Expensify/App/blob/a26a5631a50f1f9790afc109212e3cb9254d575b/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L207-L223
Before that request goes out, search() saves the navigation key again, without hasMoreResults:
https://github.com/Expensify/App/blob/a26a5631a50f1f9790afc109212e3cb9254d575b/src/libs/actions/Search.ts#L1247-L1253
and saveLastSearchParams is an Onyx.set, so the whole object is replaced and the flag is gone:
https://github.com/Expensify/App/blob/a26a5631a50f1f9790afc109212e3cb9254d575b/src/libs/actions/ReportNavigation.ts#L6-L8
It only comes back once the response has been processed:
https://github.com/Expensify/App/blob/a26a5631a50f1f9790afc109212e3cb9254d575b/src/libs/actions/Search.ts#L1290-L1306
So while page 2 is in flight, line 149 evaluates to:
!undefined && currentIndex === effectiveAllReports.length - 1 // 49 === 49 → Next disabled, "50 of 50"
On an account big enough to reach report 50, Search is slow enough for someone clicking through to get there first, which is the report. If the request fails, .catch() restores nothing, so the flag stays erased and the arrow stays off:
https://github.com/Expensify/App/blob/a26a5631a50f1f9790afc109212e3cb9254d575b/src/libs/actions/Search.ts#L1322-L1329
It is not the Search list being frozen. Most proposals here, and my first version, blame FreezeWrapper for pinning the arrow list at 50. I reproduced the issue and the list is not pinned: once page 2 lands, the counter goes from "50 of 50" to "50 of 55" and report 51 opens. On Android and iOS, FreezeWrapper does nothing at all:
https://github.com/Expensify/App/blob/a26a5631a50f1f9790afc109212e3cb9254d575b/src/libs/Navigation/AppNavigator/FreezeWrapper/index.native.tsx#L3-L9
Reproduction data
Current main. Every file on this path (MoneyRequestReportNavigation.tsx, useSaveSortedReportIDs.ts, FreezeWrapper/, ReportNavigation.ts, useSearchSections.ts) is unchanged since 9.4.81-0, the version in the report. 55 expense reports, Spend > Reports, first report opened, Next pressed repeatedly.
Normal pace. Page 2 is back before report 50:
| report | counter | Next | hasMoreResults in the navigation key |
|---|---|---|---|
| 1 | 1 of 50 | on | true |
| 38 | 38 of 50 | on | true (page 2 requested) |
| 39 | 39 of 55 | on | false (page 2 landed, list grew to 55) |
| 51 | 51 of 55 | on | false |
Page 2 held in flight (paused in DevTools until report 50 was reached):
| moment | counter | Next | hasMoreResults |
|---|---|---|---|
| report 50, page 2 pending | 50 of 50 | disabled | undefined |
| page 2 processed | 50 of 55 | on | false |
Same held run with the changes below applied:
| moment | counter | Next | hasMoreResults |
|---|---|---|---|
| report 50, page 2 pending | 50 of 50 | on | true |
| Next pressed while pending | stays on 50 | on | true |
| page 2 processed, Next pressed | 51 of 55 | on | false |
What changes do you think we should make in order to solve the problem?
1. Don't write the navigation key when the request is sent. Remove the early saveLastSearchParams in search() (L1247-L1253). The key is then only written from a complete response in .then(), which already carries hasMoreResults, offset and previousLengthOfResults. This also covers a failed request: hasMoreResults keeps its previous value, so the next press past the threshold retries instead of the arrow staying off for good.
The early write isn't needed for anything else. While a page is loading, search() returns before reaching it for any further call:
https://github.com/Expensify/App/blob/a26a5631a50f1f9790afc109212e3cb9254d575b/src/libs/actions/Search.ts#L1196-L1198
so the offset it writes early is never read before the response replaces it. allowPostSearchRecount is already false by then as well, because the effect that runs right after the report opens clears it:
https://github.com/Expensify/App/blob/a26a5631a50f1f9790afc109212e3cb9254d575b/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L158-L165
2. Don't wrap to the first report while more results are coming. With (1), Next stays on at report 50 during the fetch, and pressing it would reach this modulo and open report 1:
https://github.com/Expensify/App/blob/a26a5631a50f1f9790afc109212e3cb9254d575b/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx#L225-L226
In goToNextReport, return early when on the last loaded report and hasMoreResults is true. The prefetch above it still runs, and once the page lands the next press opens report 51.
Both changes are in shared code, so they apply to all three platforms in the report. Neither touches which list the arrows walk, so the fast path from #86238 stays as it is.
Tests. A search() test asserting that with shouldUpdateLastSearchParams the navigation key still holds hasMoreResults: true while the request is pending, and holds the response's value once it resolves. A navigation test asserting that Next on the last loaded report does not open the first one while hasMoreResults is true.
What alternative solutions did you explore? (Optional)
Switching the arrows to the snapshot list, or mounting useSearchSections all the time. This was my first version, and it is what most proposals here suggest. The reproduction shows the list already grows once page 2 lands. The failure happens before that, so changing where the list comes from doesn't touch it, and mounting the subscriptions permanently gives up the #86238 fast path for nothing.
Making saveLastSearchParams merge instead of set. That keeps hasMoreResults through the early write, but every caller would then keep stale fields such as previousLengthOfResults when a report is opened from a different search. On its own it still wraps to report 1 at the tail.