Skip to content
Source
Sign inSign up
TanStack/db

fix: lazy load includes child collections in on-demand sync mode #1471

Mergedkevin-dp(GitHub profile, opens in a new tab)merged 6 commits intomain fromrefs/pull/1471/headmerged by kevin-dp(GitHub profile, opens in a new tab)

Summary

  • Includes child collections now use lazy loading (matching the existing join optimization), so only rows matching parent correlation keys are loaded on-demand via requestSnapshot({ where: inArray(field, keys) })
  • Previously, includes child collections loaded ALL data upfront because the correlation WHERE clause was consumed by the inner join and no filter was passed to the sync layer's loadSubset/queryFn
  • Adds 6 new tests verifying the lazy loading behavior for includes

Fixes #1441

Test plan

  • New tests in includes-lazy-loading.test.ts verify:
    • Correlation filter (inArray) is passed to child collection's loadSubset
    • Query results remain correct with lazy-loaded includes
    • Child source is marked lazy (no eager full load without filter)
    • Reactive loading when new parent rows arrive
    • Works with both toArray and Collection materialization
  • All 112 existing includes tests pass
  • Full test suite passes (2071 tests)
  • Build passes

🤖 Generated with Claude Code

    1. More templates

      @tanstack/angular-db

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

      @tanstack/browser-db-sqlite-persistence

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

      @tanstack/capacitor-db-sqlite-persistence

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

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

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

      @tanstack/db

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

      @tanstack/db-ivm

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

      @tanstack/db-sqlite-persistence-core

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

      @tanstack/electric-db-collection

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

      @tanstack/electron-db-sqlite-persistence

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

      @tanstack/expo-db-sqlite-persistence

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

      @tanstack/node-db-sqlite-persistence

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

      @tanstack/offline-transactions

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

      @tanstack/powersync-db-collection

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

      @tanstack/query-db-collection

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

      @tanstack/react-db

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

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

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

      @tanstack/rxdb-db-collection

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

      @tanstack/solid-db

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

      @tanstack/svelte-db

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

      @tanstack/tauri-db-sqlite-persistence

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

      @tanstack/trailbase-db-collection

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

      @tanstack/vue-db

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

      commit: ca9febb

    2. Size Change: +507 B (+0.45%)

      Total Size: 114 kB

      📦 View Changed
      FilenameSizeChange
      packages/db/dist/esm/query/compiler/index.js4.13 kB+507 B (+13.98%)⚠️
      ℹ️ View Unchanged
      FilenameSize
      packages/db/dist/esm/collection/change-events.js1.39 kB
      packages/db/dist/esm/collection/changes.js1.38 kB
      packages/db/dist/esm/collection/cleanup-queue.js810 B
      packages/db/dist/esm/collection/events.js434 B
      packages/db/dist/esm/collection/index.js3.61 kB
      packages/db/dist/esm/collection/indexes.js1.99 kB
      packages/db/dist/esm/collection/lifecycle.js1.69 kB
      packages/db/dist/esm/collection/mutations.js2.47 kB
      packages/db/dist/esm/collection/state.js5.26 kB
      packages/db/dist/esm/collection/subscription.js3.74 kB
      packages/db/dist/esm/collection/sync.js2.88 kB
      packages/db/dist/esm/collection/transaction-metadata.js144 B
      packages/db/dist/esm/deferred.js207 B
      packages/db/dist/esm/errors.js4.92 kB
      packages/db/dist/esm/event-emitter.js748 B
      packages/db/dist/esm/index.js3 kB
      packages/db/dist/esm/indexes/auto-index.js830 B
      packages/db/dist/esm/indexes/base-index.js729 B
      packages/db/dist/esm/indexes/basic-index.js2.05 kB
      packages/db/dist/esm/indexes/btree-index.js2.17 kB
      packages/db/dist/esm/indexes/index-registry.js820 B
      packages/db/dist/esm/indexes/reverse-index.js538 B
      packages/db/dist/esm/local-only.js890 B
      packages/db/dist/esm/local-storage.js2.1 kB
      packages/db/dist/esm/optimistic-action.js359 B
      packages/db/dist/esm/paced-mutations.js496 B
      packages/db/dist/esm/proxy.js3.75 kB
      packages/db/dist/esm/query/builder/functions.js919 B
      packages/db/dist/esm/query/builder/index.js5.25 kB
      packages/db/dist/esm/query/builder/ref-proxy.js1.2 kB
      packages/db/dist/esm/query/compiler/evaluators.js1.62 kB
      packages/db/dist/esm/query/compiler/expressions.js430 B
      packages/db/dist/esm/query/compiler/group-by.js2.69 kB
      packages/db/dist/esm/query/compiler/joins.js2.34 kB
      packages/db/dist/esm/query/compiler/order-by.js1.72 kB
      packages/db/dist/esm/query/compiler/select.js1.11 kB
      packages/db/dist/esm/query/effect.js4.78 kB
      packages/db/dist/esm/query/expression-helpers.js1.43 kB
      packages/db/dist/esm/query/ir.js829 B
      packages/db/dist/esm/query/live-query-collection.js360 B
      packages/db/dist/esm/query/live/collection-config-builder.js7.88 kB
      packages/db/dist/esm/query/live/collection-registry.js264 B
      packages/db/dist/esm/query/live/collection-subscriber.js1.95 kB
      packages/db/dist/esm/query/live/internal.js145 B
      packages/db/dist/esm/query/live/utils.js1.64 kB
      packages/db/dist/esm/query/optimizer.js2.62 kB
      packages/db/dist/esm/query/predicate-utils.js2.97 kB
      packages/db/dist/esm/query/query-once.js359 B
      packages/db/dist/esm/query/subset-dedupe.js960 B
      packages/db/dist/esm/scheduler.js1.3 kB
      packages/db/dist/esm/SortedMap.js1.3 kB
      packages/db/dist/esm/strategies/debounceStrategy.js247 B
      packages/db/dist/esm/strategies/queueStrategy.js428 B
      packages/db/dist/esm/strategies/throttleStrategy.js246 B
      packages/db/dist/esm/transactions.js2.9 kB
      packages/db/dist/esm/utils.js927 B
      packages/db/dist/esm/utils/array-utils.js273 B
      packages/db/dist/esm/utils/browser-polyfills.js304 B
      packages/db/dist/esm/utils/btree.js5.61 kB
      packages/db/dist/esm/utils/comparison.js1.05 kB
      packages/db/dist/esm/utils/cursor.js457 B
      packages/db/dist/esm/utils/index-optimization.js1.54 kB
      packages/db/dist/esm/utils/type-guards.js157 B
      packages/db/dist/esm/virtual-props.js360 B
      compressed-size-action::db-package-size
    3. Size Change: 0 B

      Total Size: 4.24 kB

      ℹ️ View Unchanged
      FilenameSize
      packages/react-db/dist/esm/index.js249 B
      packages/react-db/dist/esm/useLiveInfiniteQuery.js1.32 kB
      packages/react-db/dist/esm/useLiveQuery.js1.34 kB
      packages/react-db/dist/esm/useLiveQueryEffect.js355 B
      packages/react-db/dist/esm/useLiveSuspenseQuery.js567 B
      packages/react-db/dist/esm/usePacedMutations.js401 B
      compressed-size-action::react-db-package-size

Sign in to join this conversation.