fix: preserve persisted Query writes across overlapping refetches #2002
Merged
KyleAMathewsmerged 10 commits into
main fromrefs/pull/2002/head·merged by KyleAMathews Showing 9 changed files with 110 additions and 10 deletions (loading 6).
x
@@ -0,0 +1,7 @@
+---
+'@tanstack/db': patch
+'@tanstack/db-sqlite-persistence-core': patch
+'@tanstack/query-db-collection': patch
+---
+
+Keep accepted Query results and parallel mutation-handler writes in order when SQLite persistence overlaps a refetch. Refresh the Query cache when a queued write applies, so an earlier row cannot overwrite the latest durable value.
@@ -313,6 +313,78 @@
+The Query ownership oracle enumerates five controlled persisted-refetch
+overlaps after initial load: a committed metadata-only transaction before
+Collection publication followed by a newer refetch, direct `writeUpsert`, or
+mutation-handler `writeUpsert`; and a row transaction before durability
+followed by a newer refetch or direct `writeUpsert`. It checks the latest
+public receipt, public and stored rows, and the Query Collection error ledger.
+Adjacent controls cover precommit cancellation and cleanup fencing. With the
+Query result controller's post-commit supersession guard, refetch and direct
+write successors pass before publication and durability. Both before-publication
+mutation-handler schedules now settle: an immediate write queued before the
+older normal source reaches core and one queued after it begins waiting both
+release the older publication without overtaking its durable write. They
+require fulfilled awaited handler receipts and durable revisions in
+`one`, `two`, `three` order. The controlled adapter records distinct durable revisions,
+collapsing adjacent duplicate writes of the same value.
+Two additional before-publication refetch histories replace the held result's