feat(db): shared live-query window controller (RFC #1623 phase 5)#1675
feat(db): shared live-query window controller (RFC #1623 phase 5)#1675kevin-dp wants to merge 5 commits into
Conversation
Extracts the forward-pagination state machine out of react-db's useLiveInfiniteQuery into a framework-agnostic createLiveQueryWindowController in @tanstack/db, composing the shared live-query observer. The controller owns loadedPageCount, the peek-ahead window (via collection.utils.setWindow), page slicing, and hasNextPage/isFetchingNextPage, and exposes a reactivity-free getSnapshot/subscribe/fetchNextPage/reset/dispose surface mirroring the observer. react-db's useLiveInfiniteQuery is now a thin binding over it with no public API change; its existing suite stays green. Vue/Svelte/Solid/Angular can build infinite queries on the same controller instead of re-porting React's logic. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
UseLiveInfiniteQueryReturn references ReturnType<typeof useLiveQuery>, but the import was dropped in the controller rewrite. vitest's typecheck missed it; the package build (strict tsc) caught it (TS2304). Re-add as a type-only import. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: +1.25 kB (+0.99%) Total Size: 128 kB 📦 View Changed
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.81 kB ℹ️ View Unchanged
|
…match warn Addresses review of the window-controller extraction: - pageSize/initialPageParam are now part of the controller-recreation check, so changing them at runtime re-windows and re-slices (the old hook had them in its effect/memo deps; the first controller draft baked them in at creation). - Restore the one-time console.warn when a pre-created collection's existing window differs from the first page the hook enforces (dropped in the rewrite). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Draft — Phase 5 of the live-query platform RFC (#1623): extract the infinite/windowed-query state machine into a shared controller. Stacked on #1669 (Phase 4) → #1642 (observer); base is
phase4/ordered-layout-contractso the diff is Phase 5 only.What
Adds
createLiveQueryWindowControllerto@tanstack/db— the framework-agnostic forward-pagination state machine, composing the shared live-query observer. It owns:loadedPageCountand the peek-ahead window (limit = loadedPages * pageSize + 1) applied viacollection.utils.setWindowpages/pageParams,hasNextPage(peek row present),isFetchingNextPagegetSnapshot/subscribe/fetchNextPage/reset/disposesurface, mirroring the observerreact-db'suseLiveInfiniteQueryis reimplemented as a thin binding over it (input resolution +useSyncExternalStore) with no public API change — its full existing suite (31 tests) stays green as the faithfulness anchor.Faithful extraction (v1)
Behavior is preserved exactly: forward-append only (offset always 0), peek-ahead
hasNextPage,getNextPageParamstill accepted-but-unused. No new semantics. The point of this PR is the shared controller, not a redesign.Why draft / open questions
Per the RFC, Phase 5's risk is coordination, not code. Flagging for discussion before finalizing:
rfcs/002: forward-only vs bidirectional windows; keep or dropgetNextPageParam; pre-created-collection window ownership.Tests
packages/db/tests/live-query-window-controller.test.ts— core: peek-ahead first page,fetchNextPagethrough exhaustion, partial last page, no-op when no next page,reset, stable snapshot identity, disabled controller.react-dbuseLiveInfiniteQuerysuite (31) unchanged and green — proves the extraction is behavior-preserving.Full
@tanstack/dbsuite (2478) andreact-dbsuite (122) green.🤖 Generated with Claude Code