Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .changeset/fix-infinite-query-peek-ahead.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@tanstack/react-db": patch
---

fix(react-db): include peek-ahead item in useLiveInfiniteQuery initial query

The initial query was fetching exactly `pageSize` items, but the peek-ahead logic requires `pageSize + 1` to determine if more pages exist. This caused `hasNextPage` to incorrectly return `false` on initial load when using SQLite predicate push-down with `syncMode: "on-demand"`.
3 changes: 2 additions & 1 deletion packages/react-db/src/useLiveInfiniteQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ export function useLiveInfiniteQuery<TContext extends Context>(

// Create a live query with initial limit and offset
// Either pass collection directly or wrap query function
// Use pageSize + 1 for the initial limit to include the peek-ahead item
const queryResult = isCollection
? useLiveQuery(queryFnOrCollection)
: useLiveQuery(
(q) => queryFnOrCollection(q).limit(pageSize).offset(0),
(q) => queryFnOrCollection(q).limit(pageSize + 1).offset(0),
deps,
)

Expand Down