Skip to content
Source
Sign inSign up
TanStack/db

fix: reconcile duplicate live query child inserts #1600

MergedKyleAMathews(GitHub profile, opens in a new tab)merged 6 commits intomain fromrefs/pull/1600/headmerged by kevin-dp(GitHub profile, opens in a new tab)

Showing 6 changed files with 19 additions and 8 deletions (loading 3).

x
0 of 6 viewed, 6 left
5 additions and 0 deletions.changeset/fix-sync-duplicate-key-utils.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/db': patch
+---
+​
+Fix live query includes reconciliation so updates that re-emit existing child rows update internal child collections instead of attempting duplicate inserts, and ensure duplicate-key sync errors handle collection configs without live query internals.
4 additions and 3 deletionspackages/db/src/collection/sync.tsModified
View file
@@ -151,9 +151,10 @@
// throwing a duplicate-key error during reconciliation.
messageType = `update`
} else {
- const utils = this.config
- .utils as Partial<LiveQueryCollectionUtils>
- const internal = utils[LIVE_QUERY_INTERNAL]
+ const utils = this.config.utils as
+ | Partial<LiveQueryCollectionUtils>
+ | undefined
+ const internal = utils?.[LIVE_QUERY_INTERNAL]
throw new DuplicateKeySyncError(key, this.id, {
hasCustomGetKey: internal?.hasCustomGetKey ?? false,
hasJoins: internal?.hasJoins ?? false,
10 additions and 5 deletionspackages/db/src/query/live/collection-config-builder.tsModified
View file