Skip to content
Source
Sign inSign up
TanStack/db

fix(db): live query stuck loading when subquery-in-select inner is cold on-demand #1510

Closedmarbemac(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1510/headopened

Showing 3 changed files with 205 additions and 3 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/fix-subquery-in-select-empty-outer-hang.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/db': patch
+---
+​
+Fix `useLiveSuspenseQuery` (and any live query) hanging forever when a subquery-in-`select` source is an `on-demand` collection and the outer query returns zero rows. The lazy mechanism that loads inner-collection rows per outer row never fired its `loadSubset` (no parent rows → no per-row tap), so the on-demand inner stayed not-ready and `allCollectionsReady` never went true. Lazy aliases (subquery-in-select inner aliases and lazy-join inner aliases) are now skipped by the readiness gate; the existing `isLoadingSubset` gate still keeps the live query from marking ready while in-flight per-row loads are pending.
12 additions and 3 deletionspackages/db/src/query/live/collection-config-builder.tsModified
View file
@@ -1038,9 +1038,18 @@
private allCollectionsReady() {
- return Object.values(this.collections).every((collection) =>
- collection.isReady(),
- )
+ // Skip lazy aliases: they load per outer row via per-row taps, so an
+ // empty outer never fires loadSubset on a cold on-demand inner. The
+ // live query's isLoadingSubset gate still waits for in-flight per-row
+ // loads when the outer is non-empty.
+ for (const [alias, collectionId] of Object.entries(
+ this.compiledAliasToCollectionId,
+ )) {
+ if (this.lazySources.has(alias)) continue
+ const collection = this.collections[collectionId]
+ if (collection && !collection.isReady()) return false