Skip to content
Source
Sign inSign up
TanStack/db

feat(db): allow externally-provided previousValue in sync update chan… #1445

ClosedSamJB123(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/1445/headopened

Showing 2 changed files with 49 additions and 1 deletion.

x
0 of 2 viewed, 2 left
7 additions and 0 deletions.changeset/sync-previous-value.mdAdded
View file
@@ -0,0 +1,7 @@
+---
+'@tanstack/db': patch
+---
+​
+feat: allow externally-provided `previousValue` in sync update change detection
+​
+When sync update messages include `previousValue`, `commitPendingTransactions` now uses it for the before/after comparison instead of the captured `currentVisibleState`. This allows live-reading proxy objects (e.g. Yjs Y.Type proxies) to work as collection values — the proxy always returns current state, but the sync source can provide the pre-mutation state from its own diff system. No behavior change when `previousValue` is omitted.
42 additions and 1 deletionpackages/db/src/collection/state.tsModified
View file
@@ -123,6 +123,20 @@
public recentlySyncedKeys = new Set<TKey>()
public hasReceivedFirstCommit = false
public isCommittingSyncTransactions = false
+​
+ /**
+ * Collects previousValue from sync update operations within a single
+ * commitPendingTransactions call. When a sync source (e.g. a Yjs-backed
+ * collection using live-reading proxy objects) provides previousValue
+ * on an update message, it takes precedence over the captured
+ * currentVisibleState for the deepEquals comparison.
+ *
+ * This allows live-reading proxy objects to work correctly as collection
+ * values — the proxy always returns the current state, but the sync
+ * source knows the previous state from its own diff system (e.g. Yjs