Skip to content
Source
Sign inSign up
TanStack/db

Fix syncedData not updating on manual writes in mutationFn #1130

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

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

x
0 of 6 viewed, 6 left
6 additions and 0 deletions.changeset/fix-synced-data-writes.mdAdded
View file
@@ -0,0 +1,6 @@
+---
+'@tanstack/db': patch
+'@tanstack/query-db-collection': patch
+---
+​
+Fix syncedData not updating when manual write operations (writeUpsert, writeInsert, etc.) are called after async operations in mutation handlers. Previously, the sync transaction would be blocked by the persisting user transaction, leaving syncedData stale until the next sync cycle.
23 additions and 2 deletionspackages/db/src/collection/state.tsModified
View file
@@ -25,6 +25,12 @@
upserts: Map<TKey, T>
deletes: Set<TKey>
+ /**
+ * When true, this transaction should be processed immediately even if there
+ * are persisting user transactions. Used by manual write operations (writeInsert,
+ * writeUpdate, writeDelete, writeUpsert) which need synchronous updates to syncedData.
+ */
+ immediate?: boolean
​
export class CollectionStateManager<
@@ -437,13 +443,17 @@