Skip to content
Source
Sign inSign up
TanStack/db

fix(sqlite-persistence): preserve query owner metadata on insert (closes #1618) #1626

Mergedkevin-dp(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/1626/headmerged by kevin-dp(GitHub profile, opens in a new tab)

Showing 4 changed files with 92 additions and 3 deletions (loading 1).

x
0 of 4 viewed, 4 left
5 additions and 0 deletions.changeset/small-tables-listen.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/db-sqlite-persistence-core': patch
+---
+​
+Fixed bug where internal metadata would get reset on insert causing stale items to remain
15 additions and 3 deletionspackages/db-sqlite-persistence-core/src/persisted.tsModified
View file
@@ -2290,9 +2290,21 @@
message.type === `insert` &&
normalization.operation.metadata === undefined
- openTransaction.rowMetadataWrites.set(normalization.operation.key, {
- type: `delete`,
- })
+ // Reset stale metadata for a fresh insert, but don't clobber an
+ // explicit metadata write already queued for this key in the same
+ // transaction (e.g. query reconcile stamps owners, then inserts).
+ if (
+ !openTransaction.rowMetadataWrites.has(
+ normalization.operation.key,
+ )
+ ) {
+ openTransaction.rowMetadataWrites.set(
+ normalization.operation.key,