Skip to content

fix(react-db): let setWindow control limit/offset in useLiveInfiniteQuery - #1553

Closed
v-anton wants to merge 1 commit into
TanStack:mainfrom
v-anton:fix/infinite-query-limit-offset
Closed

fix(react-db): let setWindow control limit/offset in useLiveInfiniteQuery#1553
v-anton wants to merge 1 commit into
TanStack:mainfrom
v-anton:fix/infinite-query-limit-offset

Conversation

@v-anton

@v-antonv-anton commented May 25, 2026

Copy link
Copy Markdown

🎯 Changes

useLiveInfiniteQuery baked .limit(pageSize + 1).offset(0) into the initial query builder. This capped results even after setWindow() tried to expand the window for subsequent pages, making pagination beyond page 1 return no additional data.

The fix removes the hardcoded limit/offset from the initial query and lets setWindow() (called in the useEffect below) be the sole authority on the query window.

✅ Checklist

  • I have tested this code locally with pnpm test:pr.
  • I have followed the steps in the Contributing guide.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

Bug Fixes

  • Fixed infinite query pagination to properly manage dynamic pagination windows across multiple pages without hardcoded initial limits, ensuring correct data retrieval for all pages.

Review Change Stack

@coderabbitai

coderabbitaiBot commented May 25, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8ad95452-7b34-4933-ade7-48b0a9168979

📥 Commits

Reviewing files that changed from the base of the PR and between be656be and 4954cc3.

📒 Files selected for processing (3)
  • .changeset/fix-infinite-query-limit-offset.md
  • packages/react-db/src/useLiveInfiniteQuery.ts
  • packages/react-db/tests/useLiveInfiniteQuery.test.tsx

📝 Walkthrough

Walkthrough

This PR removes hardcoded limit/offset constraints from useLiveInfiniteQuery's initial query setup. Instead of baking a pageSize + 1 peek-ahead window into the query, the hook now delegates all pagination window control to utils.setWindow(). The test suite is comprehensively updated to validate observable outcomes (hasNextPage, data length, page counts) rather than internal request shapes, and a new regression test ensures correct multi-page behavior with the query-function pattern.

Changes

useLiveInfiniteQuery Window Control Fix

Layer / File(s)Summary
Core hook implementation and fix documentation
.changeset/fix-infinite-query-limit-offset.md, packages/react-db/src/useLiveInfiniteQuery.ts
The hook removes the initial .limit(pageSize + 1) / .offset(0) window, passing collection or query function directly to useLiveQuery without peek-ahead constraints, and documents the patch release.
Test suite updates and regression validation
packages/react-db/tests/useLiveInfiniteQuery.test.tsx
Imports are consolidated; peek-ahead, multi-page, and async tests are refactored to assert external outcomes (page count, hasNextPage, data length) instead of internal call counts and transition flags; mock loadSubset is rewritten to handle cursor pagination with filtering and sorting; a regression test validates correct item IDs and hasNextPage across pages 2–3 in query-function pattern usage.

Sequence Diagram

sequenceDiagram
participant UserComponent
participant useLiveInfiniteQuery
participant useLiveQuery
participant utils.setWindow
participant loadSubset
rect rgba(100, 150, 200, 0.5)
Note over useLiveInfiniteQuery: OLD: Hardcoded limit/offset
UserComponent->>useLiveInfiniteQuery: invoke hook
useLiveInfiniteQuery->>useLiveQuery: queryFn with .limit(pageSize+1).offset(0)
useLiveQuery->>loadSubset: fetch(limit, offset)
end
rect rgba(100, 200, 150, 0.5)
Note over useLiveInfiniteQuery: NEW: Dynamic window control
UserComponent->>useLiveInfiniteQuery: invoke hook
useLiveInfiniteQuery->>useLiveQuery: queryFn without initial window
useLiveInfiniteQuery->>utils.setWindow: setWindow(limit, offset)
utils.setWindow->>loadSubset: fetch with window constraints
end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 The window now dances with grace,
No hardcoded bounds in this place,
setWindow takes flight,
Each page feels just right,
Infinite queries embrace their own pace.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Title check✅ PassedThe title clearly and specifically describes the main change: removing hardcoded limit/offset constraints and allowing setWindow() to control pagination in useLiveInfiniteQuery.
Description check✅ PassedThe description fully covers the issue, solution, and includes all required checklist items and release impact sections from the template.
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@KyleAMathews

Copy link
Copy Markdown
Collaborator

Closing as superseded by #1675 and #1724, which implement the shared infinite-query window controller from RFC #1623. The cross-adapter conformance suite in #1724 now covers query-function pagination beyond the first page.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@v-anton@KyleAMathews