Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7ad4cba
Paginate live to-do searches
TMisiukiewicz Sep 11, 2026
31b41a4
Merge remote-tracking branch 'origin/main' into paginate-live-search-…
TMisiukiewicz Sep 14, 2026
4c65f8b
Keep the live row cap monotonic
TMisiukiewicz Sep 14, 2026
b9c6e4f
Resume live pagination after the last revealed row
TMisiukiewicz Sep 15, 2026
2ebf402
Cap selection data to the rendered rows
TMisiukiewicz Sep 15, 2026
ad85902
Cap the offline reveal at the live row limit
TMisiukiewicz Sep 15, 2026
0231de5
Restart a to-do page request stranded by a reload
TMisiukiewicz Sep 15, 2026
4495c26
Test the live row cap
TMisiukiewicz Sep 15, 2026
22baeb2
Merge origin/main into paginate-live-search-offline
TMisiukiewicz Sep 15, 2026
2ed0d9d
Remove duplicate shouldUseNarrowLayout declaration
TMisiukiewicz Sep 15, 2026
b212c4b
Own live pagination with local state, force snapshot isLoading off
TMisiukiewicz Sep 21, 2026
f181fc8
Retry live pagination on failure
TMisiukiewicz Sep 21, 2026
e3adfc0
Enable local pagination when live search reaches server limit
TMisiukiewicz Sep 21, 2026
8f6f84b
Test live to-do search pagination with offline handling
TMisiukiewicz Sep 21, 2026
98770b7
Merge remote-tracking branch 'origin/main' into paginate-live-search-…
TMisiukiewicz Sep 23, 2026
5a072e2
Keep selected, highlighted and adopted live rows in view under the cap
TMisiukiewicz Sep 23, 2026
97f37cc
Page live searches from the answered cursor and key the in-flight fla…
TMisiukiewicz Sep 23, 2026
08b0eef
Keep the live cap's reveal rule inside useLiveRowLimit
TMisiukiewicz Sep 23, 2026
7bbf39d
Replace live row cap type assertions with the group row type guard
TMisiukiewicz Sep 23, 2026
a7aa048
Revert no-op changes to useSearchPageSetup
TMisiukiewicz Sep 23, 2026
980b2b9
Wait for a request to go out before paging in cached to-do rows locally
TMisiukiewicz Sep 24, 2026
ae8a48f
Clear the adopted live page flag once that page settles
TMisiukiewicz Sep 24, 2026
143e8cf
Retry a failed live page only on an end the user scrolled to
TMisiukiewicz Sep 24, 2026
d364d3c
Test a live page landing after a remount rewound the snapshot
TMisiukiewicz Sep 24, 2026
cbb11ed
Mark a scrolled-to end from visible rows, not the worklet scroll handler
TMisiukiewicz Sep 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/Search/ChatSearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function ChatSearchView({
onEndReached,
onLayout,
onScroll,
onViewableItemsChanged,
contentContainerStyle,
containerStyle,
ref,
Expand Down Expand Up @@ -123,6 +124,7 @@ function ChatSearchView({
onSelectRow={handleSelectRow}
keyExtractor={keyExtractor}
onScroll={onScroll}
onViewableItemsChanged={onViewableItemsChanged}
showsVerticalScrollIndicator={false}
ref={listRef}
columns={columns}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Search/ExpenseFlatSearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function ExpenseFlatSearchView({
onEndReached,
onLayout,
onScroll,
onViewableItemsChanged,
contentContainerStyle,
containerStyle,
ref,
Expand Down Expand Up @@ -169,6 +170,7 @@ function ExpenseFlatSearchView({
onSelectRow={handleSelectRow}
keyExtractor={keyExtractor}
onScroll={onScroll}
onViewableItemsChanged={onViewableItemsChanged}
showsVerticalScrollIndicator={false}
ref={listRef}
columns={columns}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Search/ExpenseGroupedSearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function ExpenseGroupedSearchView({
onEndReached,
onLayout,
onScroll,
onViewableItemsChanged,
contentContainerStyle,
containerStyle,
ref,
Expand Down Expand Up @@ -375,6 +376,7 @@ function ExpenseGroupedSearchView({
onSelectRow={handleSelectRow}
keyExtractor={keyExtractor}
onScroll={onScroll}
onViewableItemsChanged={onViewableItemsChanged}
showsVerticalScrollIndicator={false}
ref={listRef}
columns={columns}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Search/ExpenseReportSearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function ExpenseReportSearchView({
onEndReached,
onLayout,
onScroll,
onViewableItemsChanged,
contentContainerStyle,
containerStyle,
ref,
Expand Down Expand Up @@ -159,6 +160,7 @@ function ExpenseReportSearchView({
onSelectRow={handleSelectRow}
keyExtractor={keyExtractor}
onScroll={onScroll}
onViewableItemsChanged={onViewableItemsChanged}
showsVerticalScrollIndicator={false}
ref={listRef}
columns={columns}
Expand Down
1 change: 1 addition & 0 deletions src/components/Search/SearchResultsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function SearchResultsProvider({children}: SearchResultsProviderProps) {
const hasResults = Object.keys(liveData.data).length > 0;
// For to-do searches, always return a valid SearchResults object (even with empty data)
// This ensures we show the empty state instead of loading/blocking views
// isLoading forced off: the shared flag survives a reload and would strand the skeletons
currentSearchResults = {
search: {...searchInfo, isLoading: false, hasResults},
data: liveData.data,
Expand Down
2 changes: 2 additions & 0 deletions src/components/Search/TaskSearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function TaskSearchView({
onEndReached,
onLayout,
onScroll,
onViewableItemsChanged,
contentContainerStyle,
containerStyle,
ref,
Expand Down Expand Up @@ -121,6 +122,7 @@ function TaskSearchView({
onSelectRow={handleSelectRow}
keyExtractor={keyExtractor}
onScroll={onScroll}
onViewableItemsChanged={onViewableItemsChanged}
showsVerticalScrollIndicator={false}
ref={listRef}
columns={columns}
Expand Down
38 changes: 38 additions & 0 deletions src/components/Search/hooks/useLiveRowLimit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import CONST from '@src/CONST';

import {useState} from 'react';

type LiveRowLimit = {
liveRowLimit: number;

/** Offset of the last page the server answered. Unlike the snapshot offset, which every search() caller rewrites, it only moves forward. */
answeredOffset: number;

/** Shows one more page of live rows without the server, for when it has no pages left. */
revealNextPage: () => void;
};

/** Row cap for a live (to-do) search. Reset rides on `<Search key={queryJSON.hash}>` remounting, so there is no reset here. */
function useLiveRowLimit(offset = 0, hasUnconfirmedPage = false): LiveRowLimit {
// offset is written when the request fires, so a page still running or failed there only confirms the one before it
const confirmedOffset = Math.max(0, hasUnconfirmedPage ? offset - CONST.SEARCH.RESULTS_PAGE_SIZE : offset);

// a refresh rewinds offset to 0, but the pages past it already answered and their rows are still in Onyx
const [answeredOffset, setAnsweredOffset] = useState(confirmedOffset);
if (answeredOffset < confirmedOffset) {
setAnsweredOffset(confirmedOffset);
}
const currentAnsweredOffset = Math.max(answeredOffset, confirmedOffset);
const answeredRows = currentAnsweredOffset + CONST.SEARCH.RESULTS_PAGE_SIZE;

const [revealedRows, setRevealedRows] = useState(answeredRows);
if (revealedRows < answeredRows) {
setRevealedRows(answeredRows);
}

const revealNextPage = () => setRevealedRows((rows) => rows + CONST.SEARCH.RESULTS_PAGE_SIZE);

return {liveRowLimit: Math.max(revealedRows, answeredRows), answeredOffset: currentAnsweredOffset, revealNextPage};
}

export default useLiveRowLimit;
51 changes: 45 additions & 6 deletions src/components/Search/hooks/useSearchSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useSearchQueryContext, useSearchResultsContext} from '@components/Search/SearchContext';
import type {ReportActionListItemType, SearchListItem, TransactionGroupListItemType, TransactionListItemType} from '@components/Search/SearchList/ListItem/types';
import type {SearchColumnType, SearchData, SearchQueryJSON} from '@components/Search/types';
import type {SearchColumnType, SearchData, SearchQueryJSON, SelectedTransactions} from '@components/Search/types';

import useActionLoadingReportIDs from '@hooks/useActionLoadingReportIDs';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
Expand All @@ -15,7 +15,7 @@ import usePolicyForMovingExpenses from '@hooks/usePolicyForMovingExpenses';
import useReportAttributes from '@hooks/useReportAttributes';

import {isDefaultExpensesQuery, queryHasViolationFilter} from '@libs/SearchQueryUtils';
import {getColumnsToShow, getSections, getSortedSections, getSortedTransactionData, getValidGroupBy, isSearchDataLoaded} from '@libs/SearchUIUtils';
import {getColumnsToShow, getSections, getSortedSections, getSortedTransactionData, getValidGroupBy, isSearchDataLoaded, isTransactionGroupListItemType} from '@libs/SearchUIUtils';
import {shouldShowAttendees} from '@libs/TransactionUtils';

import CONST from '@src/CONST';
Expand Down Expand Up @@ -47,7 +47,7 @@ type SearchSnapshotResult = {
data: SearchListItem[];
/** Sorted row items BEFORE optimistic stabilization. The chart view consumes this, not `data`. */
chartData: SearchListItem[];
/** Group-enriched sections before sort. Consumed for selection counts and bulk-action wiring. */
/** Group-enriched sections before sort, capped to `visibleRowLimit`. Consumed for selection counts and bulk-action wiring. */
filteredData: SearchData;
/** Length of the base (pre-sort) sections (used as `prevReportsLength` when firing the next search). */
filteredDataLength: number;
Expand Down Expand Up @@ -85,13 +85,37 @@ type UseSearchSnapshotParams = {
* full-collection reads. */
transactions: OptimisticTrackingParams['transactions'];
reportActions: OptimisticTrackingParams['reportActions'];
/** Row cap for `data`. Live (to-do) searches page on this instead of a server cursor; their rows are all report groups. */
visibleRowLimit?: number;

/** Rows ticked here stay rendered past `visibleRowLimit`. */
selectedTransactions?: SelectedTransactions;
};

const EMPTY_DATA: SearchListItem[] = [];
const EMPTY_COLUMNS: SearchColumnType[] = [];
const EMPTY_HASHES: string[] = [];
const EMPTY_GROUP_ITEMS: TransactionGroupListItemType[] = [];

/** How many leading rows the cap keeps: `rowLimit` rows on screen, stretched down to the last ticked or highlighted row. */
function getRowLimitEnd(rows: SearchListItem[], rowLimit: number, selectedTransactions: SelectedTransactions | undefined, isOffline: boolean): number {
const isKeySelected = (key: string | undefined) => !!key && !!selectedTransactions?.[key]?.isSelected;
let shownRowCount = 0;
let end = 0;
for (const [index, row] of rows.entries()) {
// online, a row being deleted is hidden, so it doesn't use up the cap
if (!isOffline && row.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
continue;
}
shownRowCount += 1;
const isRowSelected = isKeySelected(row.keyForList) || (isTransactionGroupListItemType(row) && row.transactions.some((transaction) => isKeySelected(transaction.keyForList)));
if (shownRowCount <= rowLimit || !!row.shouldAnimateInHighlight || isRowSelected) {
end = index + 1;
}
}
return end;
}

const hashToString = (queryHash?: number) => (queryHash || queryHash === 0 ? String(queryHash) : undefined);

/**
Expand All @@ -102,7 +126,15 @@ const hashToString = (queryHash?: number) => (queryHash || queryHash === 0 ? Str
* per-group sub-snapshots, and absorbs the optimistic-row resilience. Returns the sorted rows plus the
* list-level meta and the optimistic-tracking carriers that `<Search>` consumes.
*/
function useSearchSnapshot({queryJSON, searchResults, newSearchResultKeys, transactions, reportActions}: UseSearchSnapshotParams): SearchSnapshotResult {
function useSearchSnapshot({
queryJSON,
searchResults,
newSearchResultKeys,
transactions,
reportActions,
visibleRowLimit,
selectedTransactions,
}: UseSearchSnapshotParams): SearchSnapshotResult {
const {type, sortBy, sortOrder, hash, groupBy} = queryJSON;

const {isOffline} = useNetwork();
Expand Down Expand Up @@ -413,10 +445,17 @@ function useSearchSnapshot({queryJSON, searchResults, newSearchResultKeys, trans
return item.transactions.length === 0 || !subSnapshot || !subSnapshot?.search?.hasMoreResults;
});

// slice after the sort so page 2 continues the order on screen
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

const visibleFilteredData = isRowLimitApplied ? visibleData.filter(isTransactionGroupListItemType) : filteredData;

return {
data: stableSortedData,
data: visibleData,
chartData,
filteredData,
filteredData: visibleFilteredData,
filteredDataLength,
allDataLength,
hasDeletedTransaction,
Expand Down
Loading
Loading