Collections now answer two questions separately: can the data be shown (status), and is it still kept up to date (health). Once a query has shown data, a network or backend failure never takes it off the screen.
statusgainscrashed: local storage broke (a closed IndexedDB connection, a failed SQLite persistence write or restore, a throwing sync function, or an invariant failure). Nothing recovers it in place, andreload()rejects. To recover, callcleanup({ dependents: true }), then start the Collection again (for example withpreload()); it starts with no rows. It reaches every live query and Effect above it.errornow means only "the first load failed".- Every Collection has
collection.health, a health node withstatus,failureReason(the adapter is still trying),error(the adapter stopped, or the first load failed),reloading, andhasErrors. A live query'shealthhas one node per source alias, in query order, and keeps object identity while unchanged.health:changefires when it changes.findProblems(health)lists the nodes that have a problem, in query order. Each problem (HealthProblem) shows its newest failure inmessage,cause, andat, and lists every failure still open inerrors, oldest first: eachreportError()of the sync run untilreportHealthy(), or each failed request for more data on a live query's node. One error value is one failure: reporting it again changes nothing, andreportHealthy(error)removes just that failure, so a query Collection whose failing Query recovers removes only that Query's failures. After a live query is ready, a failed request for more data (a page, a joined row, or a source reload's replay of its data) is anerroron the query's own node; the source stays healthy. collection.reload()starts a new sync run and keeps the rows, status, and error on screen until the reload completes: when the new run's snapshot (begin({ snapshot: true })) ortruncate()applies, or at itsmarkReady(), which keeps the rows when no snapshot came. On a live query it reloads every Collection below it that shows anerror, through nested live queries, then the query itself when its own node has anerror, including a failed request for more data. It rejects on acrashedCollection. When the cleanup of the sync run that a reload retired rejects, the Collection crashes, also if the rejection comes later. A query inerrorstays there until itsreload().cleanup()rejects withCollectionHasSubscribersErrorwhile a live query with subscribers or an Effect reads the Collection.cleanup({ dependents: true })ends them first.collection.subscriberslists every dependent.- A local-only Collection's
reload()keeps its rows, including the user's writes:initialDataloads only when the Collection starts, or starts again after cleanup. - Persisted Collections have one status. With
initialRender: { strategy: 'network-first' }, restored rows make the Collectionreadyonce the deadline passes or the remote fails; an empty restore staysloading. Only a local storage failure crashes a persisted Collection: a failed remote subset request is a failure reason, which the next successful remote request clears.
Breaking changes and migration:
| Before | After |
|---|---|
hook isError | isLoadingError (first load failed) or isCrashed |
| — | isSyncError: ready and the health tree has a problem |
status: 'error' after a crash | status: 'crashed' |
adapter markError(error) | fail(error). After readiness it sets the node's error and keeps the rows. Later calls throw. |
cleanup() then preload() to recover | reload() |
adapter begin({ direct: true }) | begin(): every write applies on the rows the Collection holds, also during a reload |
| a reload's first commit replaced every row | begin({ snapshot: true }) or truncate() in the new run replaces them |
adapter markReady() after fail() threw | it does nothing |
cleanup() while live queries or Effects read the Collection | rejects; unmount first or pass { dependents: true } |
persistedStatus, isPersistedReady, persistedError, preloadForInitialRender(), PERSISTED_READINESS | status and health |
query-db utils.lastError, utils.isError, utils.errorCount, utils.clearError() | collection.health, reload() |
infinite-query hooks' error (React, Preact, Vue, Svelte) | the root node's error in health; fetchNextPage() still resolves |
Custom sync adapters: keep the run's readiness in your sync function. A reload calls sync again while collection.status still shows the previous run's status and the Collection still holds the previous run's rows. The new run's writes apply on those rows; it replaces every row only with a snapshot, a transaction begun with begin({ snapshot: true }), or with its own truncate(). The reload completes when that replacement applies, or at the new run's markReady(), which keeps the rows when no snapshot came. So send the new run's full state as a snapshot, or write against the kept rows: an insert of a key the Collection holds throws DuplicateKeySyncError, during a reload as at any time, so write update for a kept row, also from a replayed load after the reload completed. A reload keeps every row its new run does not rewrite: core never deletes kept rows on its own, so removing a row the backend deleted is the adapter's job, through a snapshot, a delete, or row ownership (#2269). An on-demand loadSubset result is partial and is never a snapshot. A live query's own reload keeps its rows and its window until its new run's result is complete. reportError() and reportHealthy() throw before the first markReady() and after fail(). markReady() after the run is ready, or after its fail(), does nothing, so an adapter needs no flag of its own to guard it. A second fail() in the same sync run does nothing. A first-ready callback that throws while sync runs is reported uncaught, and the Collection stays ready. reload() called from inside sync or a loadSubset call rejects, unless a reload is already in flight, whose promise it returns. Calls after a crash do nothing. For an on-demand Collection, a reload aborts the retired run's loadSubset calls and asks the new run's loadSubset for the current demand as soon as sync returns. Honor the signal: when core aborts a load, that load is over for core, and its later resolve or reject decides nothing, holds no readiness, and no replay waits for it. A loadSubset that throws synchronously is a rejection: a failed load, which requestSnapshot() and setWindow() report without throwing. A truncate's or reload's replay decides every request error of the query's demand: its success clears them all, and its failure replaces them with the replay's failures. useLiveSuspenseQuery now throws an Error for a failed first load or a crash: the cause itself when it is an Error, otherwise an Error with the problem's message whose cause holds the reported value.