Skip to content
Source
Sign inSign up
TanStack/db

feat(query-db): add cached opaque cursor pagination #1824

MergedKyleAMathews(GitHub profile, opens in a new tab)merged 8 commits intomain fromrefs/pull/1824/headmerged by tannerlinsley

Showing 23 changed files with 151 additions and 4 deletions (loading 20).

x
0 of 23 viewed, 23 left
7 additions and 0 deletions.changeset/add-cached-cursor-pagination.mdAdded
View file
@@ -0,0 +1,7 @@
+---
+'@tanstack/query-db-collection': patch
+---
+​
+Add `createCursorPager` to fulfill offset/limit requests from endpoints with opaque continuation tokens. Reuse fresh backend pages through the existing QueryClient, with Query-managed expiry, invalidation and garbage collection, while retaining the existing UI peek-ahead behavior.
+​
+Keep manual raw-row writes from overwriting other cache formats or marking them fresh. Preserve wrapped-response writes and seeding of empty row caches.
143 additions and 4 deletionsdocs/collections/query-collection.mdModified
View file
@@ -831,16 +831,155 @@
```
​
Reject failed requests instead of returning partial rows as success. An
-unlimited request must drain until the endpoint reports exhaustion. If the
-endpoint uses opaque cursors instead of page numbers, keep that cursor handling
-inside `queryFn` or its adapter; honoring a new offset may require starting at
-the beginning again. The hook does not maintain remote cursor history.
+unlimited request must drain until the endpoint reports exhaustion. For an
+endpoint with opaque cursors, use `createCursorPager` as shown below. The hook
+does not maintain remote cursor history on its own.
​
Manually appending rows with `writeUpsert` is a separate, lower-level loading
strategy. It does not make an eager `queryFn` incremental: a later successful
refetch still replaces its complete state and can remove appended rows.