Skip to content
Source
Sign inSign up
TanStack/db

fix(db): propagate changes through nested toArray includes at depth 3+ #1457

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

Showing 5 changed files with 25 additions and 2 deletions (loading 2).

x
0 of 5 viewed, 5 left
5 additions and 0 deletions.changeset/fix-nested-includes-propagation.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/db': patch
+---
+​
+Fix nested `toArray()` includes not propagating changes at depth 3+. When a query used nested includes like `toArray(runs) → toArray(texts) → concat(toArray(textDeltas))`, changes to the deepest level (e.g., inserting a textDelta) were silently lost because `flushIncludesState` only drained one level of nested buffers. Also throw a clear error when `toArray()` or `concat(toArray())` is used inside expressions like `coalesce()`, instead of silently producing incorrect results.
2 additions and 0 deletionspackages/db/src/query/builder/functions.tsModified
View file
@@ -437,12 +437,14 @@
export type OperatorName = (typeof operators)[number]
​
export class ToArrayWrapper<_T = unknown> {
+ readonly __brand = `ToArrayWrapper` as const
declare readonly _type: `toArray`
declare readonly _result: _T
constructor(public readonly query: QueryBuilder<any>) {}
​
export class ConcatToArrayWrapper<_T = unknown> {
+ readonly __brand = `ConcatToArrayWrapper` as const
declare readonly _type: `concatToArray`
declare readonly _result: _T
constructor(public readonly query: QueryBuilder<any>) {}