Skip to content
Source
Sign inSign up
TanStack/db

Fix/live query record drop on subset unmount #1656

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

Showing 3 changed files with 57 additions and 4 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/evil-maps-shine.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/query-db-collection': minor
+---
+​
+fix: move setPersistedOwners after write to prevent row deletion when sibling live query GCs
9 additions and 4 deletionspackages/query-db-collection/src/query.tsModified
View file
@@ -1318,15 +1318,20 @@
newItemsMap.forEach((newItem, key) => {
+ addRow(key, hashedQueryKey)
+ const existingItem = currentSyncedItems.get(key)
+ if (!existingItem) {
+ write({ type: `insert`, value: newItem })
+ } else if (!previouslyOwnedRows.has(key)) {
+ write({ type: `update`, value: newItem })
+ }
+ // Read owners AFTER write: insert clears pending metadata, so reading here
+ // ensures we see the post-insert baseline and correctly re-apply ownership.
const owners = getPersistedOwners(key)
if (!owners.has(hashedQueryKey)) {
owners.add(hashedQueryKey)
setPersistedOwners(key, owners)