tanstack_query 2.0.0
tanstack_query: ^2.0.0 copied to clipboard
Widgets that help state management of asynchronous operations such as sending HTTP requests, getting the response, and caching the result.
2.0.0 #
New hooks #
usePrefetchQuery— warms a key while a widget builds, without subscribing to it.usePrefetchInfiniteQuery— the same, for an infinite query's first page.
New QueryClient methods #
fetchQuery— fetch a key from outside the widget tree, deduplicated and cached (retry: falseunless something else configures it).prefetchQuery—fetchQuerythat returns nothing and throws nothing.ensureQueryData— the cached data, fetching only when there is none;revalidateIfStalerefetches behind it.fetchInfiniteQuery/prefetchInfiniteQuery/ensureInfiniteQueryData— the same three, for infinite queries.getQueryData/getQueryState— read the cache without building a query or starting a fetch.getQueriesData— every cached entry matching a key, as(queryKey, data)pairs.setQueryDataValue— store a value directly, the JavaScriptsetQueryData(key, value)form.setQueryDefaults/getQueryDefaults— default options per key, matched element by element.removeQueries/resetQueries— drop matching queries;resetQueriesrefetches the active ones.
React Query parity fixes #
- Fix: key filters (
invalidateQueries,removeQueries,resetQueries,getQueriesData) match element by element throughpartialMatchKey, not byString.startsWithon the serialized key —['todos', 1]no longer matches['todos', 11]. - Fix:
removeQueries/resetQueriesalso reach cache entries written bysetQueryDatabefore any observer mounted, like React'squeryCache.findAll. - Fix: a mounted
useQueryfalls back topendingafter its entry is removed, instead of showing the removed data for good. - Fix: a
structuralSharingmerge function written inline is used. Being declared asObject?(so it can also holdfalse), the option left an inline closure typeddynamic Function(dynamic, dynamic), which the typed check missed and silently ignored. - Fix:
fetchQuery/prefetchQuery/ensureQueryDataand their infinite variants applyretry: falseonly when nothing else configured it, sodefaultOptions.queries.retryandsetQueryDefaults(retry:)reach them.QueryDefaultOptions.retrynow defaults tonull("not configured"); the retryer still falls back to 3, ascreateRetryerdoes in JavaScript. - Fix:
QueryResult.isStalecomes fromQuery.isStaleByTime, the single implementation — an errored query (no data) now reportsisStale: trueand refetches on focus/reconnect. - Fix: an invalidated query is stale even with
staleTime: double.infinity, sofetchQueryrefetches it. - Fix:
InfiniteQueryResultequality covers its own fields, so a change confined to e.g.hasNextPageis no longer swallowed by the "result unchanged" guard; the cached page list keeps its identity across recomputations. - Fix:
ensureInfiniteQueryDatafetches only when there are no cached pages (an empty list is data) and acceptsrevalidateIfStale, like the JS version delegating toensureQueryData. - Fix:
invalidateQueries,removeQueriesandresetQueriesrun insidenotifyManager.batch, so one call over N queries rebuilds once.
1.2.8 (05/10/26) #
- Fix:
invalidateQueriesnow keeps cached data while refetching in the background, like React Query. Previously the UI briefly showedpendingwithdata: null. - Fix:
invalidateQueriesonly refetches active queries. Disabled or unmounted ones are marked stale and refetch on next mount. - Fix: Invalidated infinite queries keep and refetch all loaded pages.
- Fix: A disabled
useQuerywith cached data no longer stayspendingon mount. - Feat:
Query.isInvalidated. An invalidated query is stale regardless ofstaleTimeuntil new data lands. - Chore: Fix unused catch variable lint.
1.2.7 (15/04/26) #
- Fix:
gcTime: 0now evicts the cache immediately on unmount (next event loop tick), matching React Query'ssetTimeout(..., 0)behaviour. PreviouslygcTime: 0was silently treated as "GC disabled". - Fix:
gcTimesemantics clarified — negative values disable GC,0means immediate eviction, positive values delay eviction by N ms. - Fix:
MutationDefaultOptions.gcTimedefault changed to5 minutes(300 000 ms), matching React Query's default for both queries and mutations. - Fix: Cached
InfiniteQuerypages are now shown immediately on remount (matching React behaviour) instead of being hidden behindstatus: pendingand re-fetched all at once.
1.2.6 (15/04/26) #
- Fix: Garbage collection bug where active
Querycould be evicted afterinvalidateQueries()orclear()— mirrors React's GC lifecycle exactly. - Arch:
QueryObservermirrors React's GC lifecycle exactly by rebuilding the underlyingQueryreference after cache invalidation. - Arch: Rework
useInfiniteQueryinternals to mirror React's architecture exactly — extractInfiniteQueryBehavior(port ofinfiniteQueryBehavior.ts), rewriteInfiniteQueryObserver(port ofInfiniteQueryObserver.ts), and hook behavior intoQuery.fetch()for React-parity dedup, direction tracking, and page management. - Fix:
isFetchingNextPageincorrectlytrueon remount afterfetchNextPage. - Fix: Rapid
fetchNextPagecalls no longer cause stuckisFetchingNextPagestate. - Fix: Mismatched generic cache entries (e.g.
InfiniteQueryResult<Object>for auseInfiniteQuery<int>) are now safely detected and discarded, triggering a fresh fetch.
1.2.5 (23/01/26) #
- Fix: Prevent infinite widget rebuilds when passing inline (non-const)
mutationKeytouseMutation.
1.2.4 (18/01/26) #
- Correct default GC Time to 5 minutes
1.2.3 (18/01/26) #
- refactor queryObservers
- add useInfiniteQuery properties result (isFetchingPreviousPage, isFetchNextPageError, hasNextPage, ...)
1.2.2 (17/01/26) #
- add context to mutation callbacks
- bug fixes and performance improvements
1.2.1 (14/01/26) #
- upgrade sdk requirement
- fix analysis
1.2.0 (14/01/26) #
- add refetchOnMount, initialData & placeholderData features
- rework refetchOnWindowFocus refetchOnReconnect
1.1.1 (04/01/26) #
- Clean dart format
1.1.0 (04/01/26) #
- Rework internals: move hook logic into core
QueryObserver/QueryandMutationObserver/Mutation. - Move
QueryCacheintoQueryClientand remove legacyQueryClient.Instance. - Implement
gcTimeand garbage collection scheduling for inactive queries. - Add
retry/retryDelaysupport (exponential backoff) andRetryer; add fixes/tests for retry behavior (includinguseInfiniteQuery). - Expose
mutateAsyncandresetMutationAPIs. - Fix observer subscriber management and refactor with
Removable. - Update docs, changelogs, dartdoc and add tests.
1.0.2 (30/12/25) #
- Add dartdoc comments.
1.0.1 (28/12/25) #
- Add
useQueryClienthook to retrieve the activeQueryClientfrom widget context.
1.0.0 (18/12/25) #
- First version with primary hooks (useQuery, useMutation, useInfiniteQuery)