Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

CHANGELOG.md

63 lines13.3 KB

@tanstack/preact-db

1.0.0-rc.1

Major Changes

  • Release the first 1.0 candidate. Remove deprecated pre-1.0 APIs and give (#2171) published row metadata precedence over colliding selected fields. Structured source spreads and direct source-row returns keep source attribution; new functional objects and other projections receive output Collection metadata. Keep the two packages accidentally released as stable 1.x on their stable release lines. Both stable minor releases require @tanstack/db@^1.0.0-rc.0 for the RC health and restoration settlement APIs; upgrade DB with them.

    Remove Query Collection’s automatic refetch after mutation handlers. Handlers return Promise<void> and must await collection.utils.refetch() or write confirmed data with the write* utilities; { refetch: false } is removed.

Minor Changes

  • Add @tanstack/preact-db, a Preact adapter with useLiveQuery and useLiveInfiniteQuery. Both compare query identity derived from the query IR on each render, require a queryKey for functional query variants, and pass the shared live-query and infinite-query conformance suites. Queries read concrete source Collections; DbProvider and collection descriptors are not supported yet. (#2235)

  • 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. (#2168)

    • status gains crashed: 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, and reload() rejects. To recover, call cleanup({ dependents: true }), then start the Collection again (for example with preload()); it starts with no rows. It reaches every live query and Effect above it. error now means only "the first load failed".
    • Every Collection has collection.health, a health node with status, failureReason (the adapter is still trying), error (the adapter stopped, or the first load failed), reloading, and hasErrors. A live query's health has one node per source alias, in query order, and keeps object identity while unchanged. health:change fires when it changes. findProblems(health) lists the nodes that have a problem, in query order. Each problem (HealthProblem) shows its newest failure in message, cause, and at, and lists every failure still open in errors, oldest first: each reportError() of the sync run until reportHealthy(), or each failed request for more data on a live query's node. One error value is one failure: reporting it again changes nothing, and reportHealthy(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 an error on 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 })) or truncate() applies, or at its markReady(), which keeps the rows when no snapshot came. On a live query it reloads every Collection below it that shows an error, through nested live queries, then the query itself when its own node has an error, including a failed request for more data. It rejects on a crashed Collection. When the cleanup of the sync run that a reload retired rejects, the Collection crashes, also if the rejection comes later. A query in error stays there until its reload().
    • cleanup() rejects with CollectionHasSubscribersError while a live query with subscribers or an Effect reads the Collection. cleanup({ dependents: true }) ends them first. collection.subscribers lists every dependent.
    • A local-only Collection's reload() keeps its rows, including the user's writes: initialData loads only when the Collection starts, or starts again after cleanup.
    • Persisted Collections have one status. With initialRender: { strategy: 'network-first' }, restored rows make the Collection ready once the deadline passes or the remote fails; an empty restore stays loading. 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:

    BeforeAfter
    hook isErrorisLoadingError (first load failed) or isCrashed
    —isSyncError: ready and the health tree has a problem
    status: 'error' after a crashstatus: '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 recoverreload()
    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 rowbegin({ snapshot: true }) or truncate() in the new run replaces them
    adapter markReady() after fail() threwit does nothing
    cleanup() while live queries or Effects read the Collectionrejects; unmount first or pass { dependents: true }
    persistedStatus, isPersistedReady, persistedError, preloadForInitialRender(), PERSISTED_READINESSstatus 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.

Patch Changes

  • Breaking: grouping, includes, and pooling are now opt-in. An app bundles an operator's code only when it imports the value for that operator. Joins do not change. A typical app is about 8 kB smaller after gzip. This app has a query collection, a filtered live query, and React useLiveQuery. (#2232)

    • An include needs include(), toArray(), or materialize(). Change issues: q.from(...) in select() to issues: include(q.from(...)). A subquery in select() without one of these throws IncludeOperatorRequiredError.
    • Aggregates such as count() need no change. A groupBy with no aggregate takes groupKeys(): .groupBy(groupKeys(({ todo }) => todo.status)). Without it, the query throws GroupingOperatorRequiredError.
    • Hooks do not pool live queries by default. To share one partition among many equality-filtered queries, pass pool: pooledLiveQueries in the hook's query config: useLiveQuery({ query, pool: pooledLiveQueries }). Results do not change. Angular's { params, query } form takes pool the same way. Any other pool value, such as the old boolean, throws InvalidPoolOptionError, also for a disabled query. For adapter authors: the pool option of resolveLiveQueryValue is now pooledLiveQueries or false, not a boolean. An adapter that reads pool from its own options checks it with configPool first.
    • Code that builds query IR by hand must supply the operator code. IR.Aggregate takes groupingCompiler as its third argument. IR.IncludesSubquery takes includesRuntime as its fifth argument, before parentFilters. Import both from @tanstack/db. IR without them throws GroupingOperatorRequiredError or IncludeOperatorRequiredError when it compiles, unless another aggregate or groupKeys() in the query supplies the grouping compiler. Queries that the query builder builds need no change.
    • Operator code is part of query identity. A hook that re-renders a grouped query without groupKeys() now throws GroupingOperatorRequiredError. Before, React and Preact kept the grouped query.
    • Vue: when a changed query fails to compile, useLiveQuery no longer shows the rows of the previous query.
  • Updated dependencies [5649a07, 43d4ef6, 7538afd, a07cd73, 6c1ca8f, 30175be, 4c39add, 1640de8, 367ea7c, 7d9ed02, 45eeef8]:

    • @tanstack/db@1.0.0-rc.1