@tanstack/db@0.5.18
Patch Changes
-
fix(db): prevent live query from being marked ready before subset data is loaded (#1081)
In on-demand sync mode, the live query collection was being marked as
readybefore
the subset data finished loading. This causeduseLiveQueryto returnisReady=true
with empty data, anduseLiveSuspenseQueryto release suspense prematurely.The root cause was a race condition: the
status:changelistener inCollectionSubscriber
was registered after the snapshot was triggered. IfloadSubsetresolved quickly
(or synchronously), theloadingSubsetstatus transition would be missed entirely,
sotrackLoadPromisewas never called on the live query collection.Changes:
- Core fix -
onStatusChangeoption: AddedonStatusChangecallback option to
subscribeChanges(). The listener is registered BEFORE any snapshot is requested,
guaranteeing no status transitions are missed. This replaces the error-prone pattern
of manually deferring snapshots and registering listeners in the correct order. - Ready state gating:
updateLiveQueryStatus()now checksisLoadingSubseton the
live query collection before marking it ready, and listens forloadingSubset:change
to trigger the ready check when subset loading completes.
- Core fix -