Skip to content
Source
Sign inSign up
TanStack/db

Fix unbounded expression growth in DeduplicatedLoadSubset #1348

MergedKyleAMathews(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/1348/headmerged by KyleAMathews(GitHub profile, opens in a new tab)

Showing 3 changed files with 148 additions and 20 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/fix-unbounded-where-growth.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/db': patch
+---
+​
+Fix unbounded WHERE expression growth in `DeduplicatedLoadSubset` when loading all data after accumulating specific predicates. The deduplication layer now correctly tracks the original request predicate (e.g., `where: undefined` for "load all") instead of the optimized difference query sent to the backend, ensuring `hasLoadedAllData` is properly set and subsequent requests are deduplicated.
14 additions and 15 deletionspackages/db/src/query/subset-dedupe.tsModified
View file
@@ -126,28 +126,29 @@
return prom
​
- // Not fully covered by existing data
- // Compute the subset of data that is not covered by the existing data
- // such that we only have to load that subset of missing data
- const clonedOptions = cloneOptions(options)
+ // Not fully covered by existing data — load the missing subset.
+ // We need two clones: trackingOptions preserves the original predicate for
+ // accurate tracking (e.g., where=undefined means "all data"), while loadOptions
+ // may be narrowed with a difference expression for the actual backend request.
+ const trackingOptions = cloneOptions(options)
+ const loadOptions = cloneOptions(options)
if (this.unlimitedWhere !== undefined && options.limit === undefined) {
// Compute difference to get only the missing data
// We can only do this for unlimited queries