Skip to content

Commit f0bf297

Browse files
thomasballingerConvex, Inc.
authored andcommitted
Revert new usePaginatedQuery options that aren't ready (#38031)
We're not ready for new usePaginatedQuery options that enable gapless custom pagination (query streams, etc.) yet; we can do it, but the behavior is either difficult to describe and may change. Stick to convex helpers for this for now. GitOrigin-RevId: fff159089f6af65156906aaac473e37b61822e8f
1 parent 667fd0d commit f0bf297

File tree

2 files changed

+10
-68
lines changed

2 files changed

+10
-68
lines changed

src/react/use_paginated_query.test.tsx

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -275,20 +275,9 @@ describe("usePaginatedQuery pages", () => {
275275
resetPaginationId();
276276
});
277277

278-
test.each([
279-
{
280-
latestPageSize: undefined,
281-
},
282-
{
283-
latestPageSize: "fixed" as const,
284-
},
285-
{
286-
latestPageSize: "grow" as const,
287-
},
288-
])("loadMore with latestPageSize $latestPageSize", ({ latestPageSize }) => {
278+
test("loadMore", () => {
289279
const { result } = renderHook(
290-
() =>
291-
usePaginatedQuery(query, {}, { initialNumItems: 1, latestPageSize }),
280+
() => usePaginatedQuery(query, {}, { initialNumItems: 1 }),
292281
{ wrapper },
293282
);
294283
mockPage(
@@ -302,18 +291,6 @@ describe("usePaginatedQuery pages", () => {
302291
isDone: false,
303292
},
304293
);
305-
mockPage(
306-
{
307-
numItems: 1,
308-
cursor: null,
309-
endCursor: "abc",
310-
},
311-
{
312-
page: ["item1"],
313-
continueCursor: "abc",
314-
isDone: false,
315-
},
316-
);
317294
mockPage(
318295
{
319296
numItems: 2,

src/react/use_paginated_query.ts

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,7 @@ const completeSplitQuery =
153153
* @param args - The arguments object for the query function, excluding
154154
* the `paginationOpts` property. That property is injected by this hook.
155155
* @param options - An object specifying the `initialNumItems` to be loaded in
156-
* the first page, and the `latestPageSize` to use.
157-
* @param options.latestPageSize controls how the latest page (the first page
158-
* until another page is loaded) size grows. With "fixed", the page size will
159-
* stay at the size specified by `initialNumItems` / `loadMore`. With "grow",
160-
* the page size will grow as new items are added within the range of the initial
161-
* page. Once multiple pages are loaded, all but the last page will grow, in
162-
* order to provide seamless pagination. See the docs for more details.
156+
* the first page.
163157
* @returns A {@link UsePaginatedQueryResult} that includes the currently loaded
164158
* items, the status of the pagination, and a `loadMore` function.
165159
*
@@ -168,10 +162,7 @@ const completeSplitQuery =
168162
export function usePaginatedQuery<Query extends PaginatedQueryReference>(
169163
query: Query,
170164
args: PaginatedQueryArgs<Query> | "skip",
171-
options: {
172-
initialNumItems: number;
173-
latestPageSize?: "grow" | "fixed";
174-
},
165+
options: { initialNumItems: number },
175166
): UsePaginatedQueryReturnType<Query> {
176167
if (
177168
typeof options?.initialNumItems !== "number" ||
@@ -247,9 +238,9 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
247238
Value[],
248239
undefined | PaginationResult<Value>,
249240
] = useMemo(() => {
250-
let currResult: PaginationResult<Value> | undefined = undefined;
241+
let currResult = undefined;
251242

252-
const allItems: Value[] = [];
243+
const allItems = [];
253244
for (const pageKey of currState.pageKeys) {
254245
currResult = resultsObject[pageKey];
255246
if (currResult === undefined) {
@@ -362,33 +353,9 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
362353
if (!alreadyLoadingMore) {
363354
alreadyLoadingMore = true;
364355
setState((prevState) => {
365-
let nextPageKey = prevState.nextPageKey;
356+
const pageKeys = [...prevState.pageKeys, prevState.nextPageKey];
366357
const queries = { ...prevState.queries };
367-
let ongoingSplits = prevState.ongoingSplits;
368-
let pageKeys = prevState.pageKeys;
369-
if (options.latestPageSize === "fixed") {
370-
const lastPageKey = prevState.pageKeys.at(-1)!;
371-
const boundLastPageKey = nextPageKey;
372-
queries[boundLastPageKey] = {
373-
query: prevState.query,
374-
args: {
375-
...prevState.args,
376-
paginationOpts: {
377-
...(queries[lastPageKey]!.args
378-
.paginationOpts as unknown as PaginationOptions),
379-
endCursor: continueCursor,
380-
},
381-
},
382-
};
383-
nextPageKey++;
384-
ongoingSplits = {
385-
...ongoingSplits,
386-
[lastPageKey]: [boundLastPageKey, nextPageKey],
387-
};
388-
} else {
389-
pageKeys = [...prevState.pageKeys, nextPageKey];
390-
}
391-
queries[nextPageKey] = {
358+
queries[prevState.nextPageKey] = {
392359
query: prevState.query,
393360
args: {
394361
...prevState.args,
@@ -399,19 +366,17 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
399366
},
400367
},
401368
};
402-
nextPageKey++;
403369
return {
404370
...prevState,
371+
nextPageKey: prevState.nextPageKey + 1,
405372
pageKeys,
406-
nextPageKey,
407373
queries,
408-
ongoingSplits,
409374
};
410375
});
411376
}
412377
},
413378
} as const;
414-
}, [maybeLastResult, currState.nextPageKey, options.latestPageSize]);
379+
}, [maybeLastResult, currState.nextPageKey]);
415380

416381
return {
417382
results,

0 commit comments

Comments
 (0)