Skip to content

feat(svelte-db): add infinite query binding - #1723

Merged
KyleAMathews merged 3 commits into
mainfrom
taren/svelte-infinite-query-controller
Aug 12, 2026
Merged

feat(svelte-db): add infinite query binding#1723
KyleAMathews merged 3 commits into
mainfrom
taren/svelte-infinite-query-controller

Conversation

@tannerlinsley

@tannerlinsley tannerlinsley commented Aug 12, 2026

Copy link
Copy Markdown
Member

🎯 Changes

  • Add useLiveInfiniteQuery as a Svelte 5 binding over the shared live-query window controller.
  • Preserve query-function, reactive collection getter, page, pagination-state, and typed pre-created collection APIs from feat(svelte-db): implement useLiveInfiniteQuery for svelte 5 #1447.
  • Cover exact peek-ahead windows, live row movement, dependency resets, pre-created collections, promise completion, and pagination boundaries.
  • Retain Reijhanniel Jearl Campos's contribution through commit co-authorship.

Reworks #1447 without closing it.

✅ Checklist

  • I have tested this code locally with pnpm test.

Validation:

  • pnpm --filter @tanstack/svelte-db test (64 tests)
  • pnpm --filter @tanstack/svelte-db test:types
  • pnpm --filter @tanstack/svelte-db build
  • ESLint and Prettier

🚀 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

  • New Features

    • Added useLiveInfiniteQuery for reactive infinite queries in Svelte.
    • Supports paginated data, live updates, query state, and fetching additional pages.
    • Works with pre-created live-query collections or query functions.
    • Exposed the new hook through the Svelte DB package.
  • Bug Fixes

    • Added validation and warnings for unsupported pagination configurations.
  • Tests

    • Added coverage for pagination boundaries, live updates, dependency changes, and reactive collections.

Co-authored-by: Reijhanniel Jearl Campos <devcsrj@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 29ffe0eb-39f9-49e4-b090-1addc0e24524

📥 Commits

Reviewing files that changed from the base of the PR and between f1c24cd and 6d3395b.

📒 Files selected for processing (1)
  • packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts

📝 Walkthrough

Walkthrough

Changes

Adds the Svelte useLiveInfiniteQuery binding over the shared live-query window controller. It supports query functions and pre-created ordered collections, exposes reactive pagination state, and includes tests and release metadata.

Svelte live infinite query

Layer / File(s) Summary
API contract and input resolution
packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts, packages/svelte-db/src/index.ts
Defines configuration and return types, supports collection and query-function inputs, validates inputs, and exports the binding.
Controller and reactive state
packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts
Creates or validates ordered collections, configures the window controller, subscribes to snapshots, handles cleanup and fetch errors, and exposes reactive query state.
Behavior validation and release metadata
packages/svelte-db/tests/useLiveInfiniteQuery.svelte.test.ts, .changeset/spicy-roses-hide.md
Tests pagination, live updates, dependency changes, reactive collections, warnings, boundary cases, and the package release entry.

Estimated code review effort: 4 (Complex) | ~45 minutes

Mergeability Score: ⚪ Minimal · up to 6d339

This PR adds the Svelte infinite-query binding and associated tests and release metadata; no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant SvelteComponent
  participant useLiveInfiniteQuery
  participant createLiveQueryWindowController
  participant LiveQueryCollection
  SvelteComponent->>useLiveInfiniteQuery: invoke query binding
  useLiveInfiniteQuery->>LiveQueryCollection: resolve or create ordered collection
  useLiveInfiniteQuery->>createLiveQueryWindowController: initialize controller
  createLiveQueryWindowController->>LiveQueryCollection: configure collection window
  createLiveQueryWindowController-->>useLiveInfiniteQuery: publish snapshot
  useLiveInfiniteQuery-->>SvelteComponent: expose reactive query state
  SvelteComponent->>useLiveInfiniteQuery: fetchNextPage()
  useLiveInfiniteQuery->>createLiveQueryWindowController: fetch next page
  createLiveQueryWindowController-->>useLiveInfiniteQuery: publish updated snapshot
Loading

Possibly related PRs

  • TanStack/db#1642: Introduces the shared live-query observer and window-controller infrastructure used by this binding.
  • TanStack/db#1669: Introduces shared reactive snapshot and pagination-window behavior used by the binding.
  • TanStack/db#1675: Introduces the shared createLiveQueryWindowController used by this binding.

Suggested reviewers: kyleamathews

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of the Svelte DB infinite query binding, which is the main change.
Description check ✅ Passed The description covers the required changes, checklist, validation results, and release impact, including the generated changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch taren/svelte-infinite-query-controller

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts`:
- Around line 141-145: Update the pageSize derivation in useLiveInfiniteQuery so
only positive integers from config.pageSize are accepted; fractional, zero,
negative, and otherwise invalid values must use DEFAULT_PAGE_SIZE. Ensure the
validated integer is the value passed to limit() and the window controller.
- Around line 117-126: Update useLiveInfiniteQuery so its configuration and
return types are parameterized by the inferred TResult, TKey, and TUtils instead
of any. Introduce or reuse collection-specific generic types for
UseLiveInfiniteQueryConfig and UseLiveInfiniteQueryReturn, preserving those
inferred types through getNextPageParam, data, pages, and related values.
- Line 103: Update the fetchNextPage binding in useLiveInfiniteQuery to return
the promise from LiveQueryWindowController.fetchNextPage instead of discarding
it, preserving its resolve/reject behavior. Adjust the related tests to await
fetchNextPage before making assertions.

In `@packages/svelte-db/tests/useLiveInfiniteQuery.svelte.test.ts`:
- Around line 45-182: Extend the useLiveInfiniteQuery pagination tests with
empty-collection, single-row, and pageSize: 0 cases, asserting hasNextPage,
pages, and effective window limits. In the existing multi-page tests, await each
fetchNextPage() promise before flushSync and subsequent assertions so
asynchronous completion order is covered.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 492335f2-05fa-4c8b-9453-e15bad8d0f11

📥 Commits

Reviewing files that changed from the base of the PR and between dc53f0e and 35b813d.

📒 Files selected for processing (4)
  • .changeset/spicy-roses-hide.md
  • packages/svelte-db/src/index.ts
  • packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts
  • packages/svelte-db/tests/useLiveInfiniteQuery.svelte.test.ts

Comment thread packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts Outdated
Comment thread packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts Outdated
Comment thread packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts Outdated
Comment thread packages/svelte-db/tests/useLiveInfiniteQuery.svelte.test.ts Outdated
@pkg-pr-new

pkg-pr-new Bot commented Aug 12, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-db

npm i https://pkg.pr.new/@tanstack/angular-db@1723

@tanstack/browser-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/browser-db-sqlite-persistence@1723

@tanstack/capacitor-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/capacitor-db-sqlite-persistence@1723

@tanstack/cloudflare-durable-objects-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/cloudflare-durable-objects-db-sqlite-persistence@1723

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@1723

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@1723

@tanstack/db-sqlite-persistence-core

npm i https://pkg.pr.new/@tanstack/db-sqlite-persistence-core@1723

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@1723

@tanstack/electron-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/electron-db-sqlite-persistence@1723

@tanstack/expo-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/expo-db-sqlite-persistence@1723

@tanstack/node-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/node-db-sqlite-persistence@1723

@tanstack/offline-transactions

npm i https://pkg.pr.new/@tanstack/offline-transactions@1723

@tanstack/powersync-db-collection

npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1723

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@1723

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@1723

@tanstack/react-native-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/react-native-db-sqlite-persistence@1723

@tanstack/rxdb-db-collection

npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1723

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@1723

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@1723

@tanstack/tauri-db-sqlite-persistence

npm i https://pkg.pr.new/@tanstack/tauri-db-sqlite-persistence@1723

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1723

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@1723

commit: 6d3395b

@github-actions

Copy link
Copy Markdown
Contributor

Size Change: 0 B

Total Size: 132 kB

ℹ️ View Unchanged
Filename Size
packages/db/dist/esm/collection/change-events.js 1.44 kB
packages/db/dist/esm/collection/changes.js 1.51 kB
packages/db/dist/esm/collection/cleanup-queue.js 810 B
packages/db/dist/esm/collection/events.js 434 B
packages/db/dist/esm/collection/index.js 3.86 kB
packages/db/dist/esm/collection/indexes.js 1.99 kB
packages/db/dist/esm/collection/lifecycle.js 1.7 kB
packages/db/dist/esm/collection/mutations.js 2.47 kB
packages/db/dist/esm/collection/state.js 5.51 kB
packages/db/dist/esm/collection/subscription.js 3.77 kB
packages/db/dist/esm/collection/sync.js 3.05 kB
packages/db/dist/esm/collection/transaction-metadata.js 144 B
packages/db/dist/esm/deferred.js 207 B
packages/db/dist/esm/errors.js 5.16 kB
packages/db/dist/esm/event-emitter.js 748 B
packages/db/dist/esm/index.js 3.26 kB
packages/db/dist/esm/indexes/auto-index.js 829 B
packages/db/dist/esm/indexes/base-index.js 784 B
packages/db/dist/esm/indexes/basic-index.js 2.17 kB
packages/db/dist/esm/indexes/btree-index.js 2.29 kB
packages/db/dist/esm/indexes/index-registry.js 820 B
packages/db/dist/esm/indexes/reverse-index.js 557 B
packages/db/dist/esm/live-query-adapter.js 318 B
packages/db/dist/esm/live-query-observer.js 2.35 kB
packages/db/dist/esm/live-query-window-controller.js 3.04 kB
packages/db/dist/esm/local-only.js 916 B
packages/db/dist/esm/local-storage.js 2.12 kB
packages/db/dist/esm/optimistic-action.js 359 B
packages/db/dist/esm/paced-mutations.js 496 B
packages/db/dist/esm/proxy.js 3.75 kB
packages/db/dist/esm/query/builder/functions.js 1.47 kB
packages/db/dist/esm/query/builder/index.js 5.84 kB
packages/db/dist/esm/query/builder/ref-proxy.js 1.24 kB
packages/db/dist/esm/query/compiler/evaluators.js 1.89 kB
packages/db/dist/esm/query/compiler/expressions.js 430 B
packages/db/dist/esm/query/compiler/group-by.js 3.56 kB
packages/db/dist/esm/query/compiler/index.js 6.67 kB
packages/db/dist/esm/query/compiler/joins.js 2.5 kB
packages/db/dist/esm/query/compiler/lazy-targets.js 923 B
packages/db/dist/esm/query/compiler/order-by.js 1.74 kB
packages/db/dist/esm/query/compiler/select.js 1.53 kB
packages/db/dist/esm/query/effect.js 4.77 kB
packages/db/dist/esm/query/expression-helpers.js 1.43 kB
packages/db/dist/esm/query/ir.js 1.25 kB
packages/db/dist/esm/query/live-query-collection.js 360 B
packages/db/dist/esm/query/live/collection-config-builder.js 9.32 kB
packages/db/dist/esm/query/live/collection-registry.js 264 B
packages/db/dist/esm/query/live/collection-subscriber.js 1.95 kB
packages/db/dist/esm/query/live/internal.js 145 B
packages/db/dist/esm/query/live/utils.js 1.81 kB
packages/db/dist/esm/query/optimizer.js 2.92 kB
packages/db/dist/esm/query/predicate-utils.js 2.97 kB
packages/db/dist/esm/query/query-once.js 359 B
packages/db/dist/esm/query/subset-dedupe.js 960 B
packages/db/dist/esm/scheduler.js 1.3 kB
packages/db/dist/esm/SortedMap.js 1.3 kB
packages/db/dist/esm/strategies/debounceStrategy.js 247 B
packages/db/dist/esm/strategies/queueStrategy.js 428 B
packages/db/dist/esm/strategies/throttleStrategy.js 246 B
packages/db/dist/esm/transactions.js 3.04 kB
packages/db/dist/esm/utils.js 927 B
packages/db/dist/esm/utils/array-utils.js 273 B
packages/db/dist/esm/utils/browser-polyfills.js 304 B
packages/db/dist/esm/utils/btree.js 5.61 kB
packages/db/dist/esm/utils/comparison.js 1.15 kB
packages/db/dist/esm/utils/cursor.js 457 B
packages/db/dist/esm/utils/index-optimization.js 2.39 kB
packages/db/dist/esm/utils/type-guards.js 157 B
packages/db/dist/esm/utils/uuid.js 449 B
packages/db/dist/esm/virtual-props.js 360 B

compressed-size-action::db-package-size

@github-actions

Copy link
Copy Markdown
Contributor

Size Change: 0 B

Total Size: 3.79 kB

ℹ️ View Unchanged
Filename Size
packages/react-db/dist/esm/index.js 249 B
packages/react-db/dist/esm/useLiveInfiniteQuery.js 1.29 kB
packages/react-db/dist/esm/useLiveQuery.js 920 B
packages/react-db/dist/esm/useLiveQueryEffect.js 355 B
packages/react-db/dist/esm/useLiveSuspenseQuery.js 567 B
packages/react-db/dist/esm/usePacedMutations.js 401 B

compressed-size-action::react-db-package-size

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts (1)

50-52: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace the local any placeholders with shared generic bounds.

Use object, string | number, and UtilsRecord for the internal collection, snapshot, and controller types, or propagate the actual generics. Keep TUtils extends Record<string, any> because the shared Collection and UseLiveQueryReturnWithCollection contracts currently require that bound.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts` around lines 50 - 52,
Update hasSetWindow and its related collection, snapshot, and controller type
annotations to use the shared bounds object, string | number, and UtilsRecord
instead of local any placeholders, or propagate the actual generics where
available. Preserve TUtils extends Record<string, any> to satisfy the existing
Collection and UseLiveQueryReturnWithCollection contracts.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts`:
- Around line 50-52: Update hasSetWindow and its related collection, snapshot,
and controller type annotations to use the shared bounds object, string |
number, and UtilsRecord instead of local any placeholders, or propagate the
actual generics where available. Preserve TUtils extends Record<string, any> to
satisfy the existing Collection and UseLiveQueryReturnWithCollection contracts.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6520ccca-06b9-41d2-a8de-bc4b4e77c655

📥 Commits

Reviewing files that changed from the base of the PR and between 35b813d and f1c24cd.

📒 Files selected for processing (2)
  • packages/svelte-db/src/useLiveInfiniteQuery.svelte.ts
  • packages/svelte-db/tests/useLiveInfiniteQuery.svelte.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/svelte-db/tests/useLiveInfiniteQuery.svelte.test.ts

@KyleAMathews
KyleAMathews merged commit e19a954 into main Aug 12, 2026
14 of 16 checks passed
@KyleAMathews
KyleAMathews deleted the taren/svelte-infinite-query-controller branch August 12, 2026 23:19
@github-actions github-actions Bot mentioned this pull request Aug 12, 2026
Sign up for free to 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