fix(query-db): stop direct writes from refetching active subsets #2065
Merged
KyleAMathews(GitHub profile, opens in a new tab)merged 32 commits into
main fromrefs/pull/2065/head·merged by KyleAMathews(GitHub profile, opens in a new tab) Showing 16 changed files with 103 additions and 21 deletions (loading 14).
x
@@ -0,0 +1,8 @@
+---
+'@tanstack/query-db-collection': patch
+---
+
+Prevent direct writes from automatically refetching active Query subsets. On-demand writes patch changed keys already present in active raw arrays or directly selected response arrays, except when the Query is shared with another Collection. Eager writes patch representable rows in a shared Query cache, so Collections using the same Query project those edits. In both modes, cache patches preserve Query error, invalidation, and freshness state; an idle eager cache seed moves from pending to success without advancing its freshness timestamp. Direct writes no longer clear a prior fetch error or mark stale data fresh. Older in-flight or queued results cannot undo an accepted write, and derived cache responses are not replayed over it on resubscribe. A later-started successful subset fetch controls a shared row's value over an older request that settles afterward. Callers choose when to request current server rows; a complete matching on-demand result can remove an omitted ownerless direct row. Query Core 5.90.15 or later is required for post-write refetch replacement and error-state recovery.
+
+An eager Collection that later joins a Query patched by another eager Collection projects the cached edit without starting a request, including when disabled. An on-demand Collection still revalidates an unverified cache edit before accepting it for a subset. A fresh persisted Collection refetches on a cached-row collision when it cannot recover the order of its stored direct write and that Query result.
+Inactive Query entries under the Collection key prefix may be removed after a direct write. A physical Query whose stored key is outside that prefix remains in the cache, even when a custom hash aliases it with a Collection key; callers can explicitly evict or refetch that entry.
@@ -341,8 +341,9 @@
-the eager Query cache in place. On-demand direct writes revalidate scoped
-entries as described below.
+the eager Query cache in place when its row array can be updated. Collections
+sharing that Query project the same patched cache. On-demand direct writes patch existing cached
+row keys on a best-effort basis, as described below.
@@ -382,15 +383,22 @@