Skip to content
Source
Sign inSign up
TanStack/db

fix(solid-db): clone rows in syncDataFromCollection so reconcile sees in-place mutations #1604

Closedtsushanth(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/1604/headopened

Showing 3 changed files with 178 additions and 2 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/solid-db-reconcile-clone-rows.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+"@tanstack/solid-db": patch
+---
+​
+Fix `useLiveQuery` not propagating `toArray` include changes. When the upstream collection mutated parent rows in place (as it does when flushing `toArray` include values), Solid's `reconcile` short-circuited on the stable parent reference and the rendered `data` array kept showing the old include content. `syncDataFromCollection` now shallow-clones each row (and any array-valued field on it) before handing it to `reconcile`, so field-level diffing actually runs.
25 additions and 2 deletionspackages/solid-db/src/useLiveQuery.tsModified
View file
@@ -341,12 +341,35 @@
​
- // Helper to sync data array from collection in correct order
+ // Helper to sync data array from collection in correct order.
+ //
+ // `reconcile` short-circuits on `next === target` (both at the array-item
+ // level and at the field level), so when the collection mutates a row in
+ // place — as it does for `toArray` include values flushed by
+ // `flushIncludesState` in `packages/db/src/query/live/collection-config-builder.ts`
+ // — downstream consumers never see the change. Shallow-clone each row (and
+ // any array-valued field on it) so `reconcile` recurses into the field-level
+ // diff instead of bailing on the stable parent / include reference.
+ // Tracking issue: https://github.com/TanStack/db/issues/1571
+ const cloneRowForReconcile = <T,>(v: T): T => {
+ if (v === null || typeof v !== `object` || Array.isArray(v)) {