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)

Showing 4 changed files with 86 additions and 0 deletions (loading 1).

x
0 of 4 viewed, 4 left
7 additions and 0 deletions.changeset/includes-child-where-clauses.mdAdded
View file
@@ -0,0 +1,7 @@
+---
+'@tanstack/db': patch
+---
+​
+fix: pass child where clauses to loadSubset in includes
+​
+Pure-child WHERE clauses on includes subqueries (e.g., `.where(({ item }) => eq(item.status, 'active'))`) are now passed through to the child collection's `loadSubset`/`queryFn`, enabling server-side filtering. Previously only the correlation filter reached the sync layer; additional child filters were applied client-side only.
7 additions and 0 deletions.changeset/includes-lazy-loading.mdAdded
View file
@@ -0,0 +1,7 @@
+---
+'@tanstack/db': patch
+---
+​
+fix: lazy load includes child collections in on-demand sync mode
+​
+Includes child collections now use the same lazy loading mechanism as regular joins. When a query uses includes with a correlation WHERE clause (e.g., `.where(({ item }) => eq(item.rootId, r.id))`), only matching child rows are loaded on-demand via `requestSnapshot({ where: inArray(field, keys) })` instead of loading all data upfront. This ensures the sync layer's `queryFn` receives the correlation filter in `loadSubsetOptions`, enabling efficient server-side filtering.
72 additions and 0 deletionspackages/db/src/query/compiler/index.tsModified
View file
@@ -4,6 +4,7 @@
join as joinOperator,
map,
reduce,