Skip to content
Source
Sign inSign up
TanStack/db

fix(db): start no network work for a live query until it has a subscriber or preload #2060

MergedKyleAMathewsmerged 20 commits intomain fromrefs/pull/2060/headmerged by KyleAMathews

Showing 36 changed files with 74 additions and 0 deletions (loading 33).

x
0 of 36 viewed, 36 left
6 additions and 0 deletions.changeset/network-waits-for-subscriber.mdAdded
View file
@@ -0,0 +1,6 @@
+---
+'@tanstack/db': patch
+'@tanstack/react-db': patch
+---
+​
+A live query no longer starts network work for its source collections before it has a subscriber or a preload. Rendering a component that never commits, or creating a live query with `startSync: true`, reads only the rows its sources already hold; the first subscriber or `preload()` starts the sources' sync and loads on-demand data. This applies to nested live queries and pooled `eq` queries too. `useLiveSuspenseQuery` preloads during render, so a source that already holds the rows still renders without suspending. A source collection's `subscriberCount` and `subscribers:change` now count only subscribers that ask for data, so a live query waiting for its first subscriber no longer makes a Query Collection refetch.
67 additions and 0 deletionsdocs/contributing/oracle-reviews/2026-10-07-deferred-acquisition-review.mdAdded
View file
@@ -0,0 +1,67 @@
+# Deferred acquisition review, 2026-10-07
+​
+Scope: PR #2060 (`issue-2023-network-on-subscriber`) at `19588268c`, reviewed by
+an external high-effort code review. The repair commit that adds this record
+sits on top of that revision. Owner:
+`packages/db/tests/live-query-deferred-acquisition-oracle.test.ts`.
+​
+## Law
+​
+Normative law 15 in `packages/db/src/query/live/ARCHITECTURE.md`. Authority:
+the maintainer's decision that a live query starts no network work until it
+has a subscriber or a preload, with preload counting and eager sources
+included. This review sharpened the formulation: the subscriber must ask for
+data, a subscriber that survives cleanup still counts, and a read that waits
+for readiness counts as a preload.
+​