* fix(streamedQuery): fall back to initialValue when stream yields no values
Add failing test for empty streams and update implementation to avoid returning undefined.
Includes changeset for patch release.
* chore: address review nitpicks (JSDoc + test cleanup)
* docs: note that initialValue is returned when the stream yields no values
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* add community resources page
* update link for blog posts
* update community resource links
* rm vue community section
* update old links
* fix community resource link
* add timeoutManager class
* add additional types & export functions
* convert all setTimeout/setInterval to managed versions
* tweaks
* add claude-generated tests
* tests
* revert changes in query-async-storage-persister: no path to import query-core
* re-export more types
* console.warn -> non-production console.error
* query-async-storage-persister: use query-core managedSetTimeout
* pdate pnpm-lock for new dependency edge
* sleep: always managedSetTimeout
* remove managed* functions, call method directly
* remove runtime coercion and accept unsafe any within TimeoutManager class
* cleanup; fix test after changes
* name is __TEST_ONLY__
* notifyManager: default scheduler === systemSetTimeoutZero
* Improve TimeoutCallback comment since ai was confused
* remove unnecessary timeoutManager-related exports
* prettier-ify index.ts (seems my editor messed with it already this pr?)
* continue to export defaultTimeoutProvider for tests
* oops missing import
* fix: export systemSetTimeoutZero from core
* ref: use notifyManager.schedule in createPersister
because it needs to work with whatever scheduleFn we have set there
* ref: move provider check behind env check
* docs
* doc tweaks
* doc tweaks
* docs: reference timeoutManager in discussion of 24 day setTimout limit
* Apply suggestion from @TkDodo
* Apply suggestion from @TkDodo
* chore: fix broken links
* docs: syntax fix
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* feat(query-core): add custom reducer support to streamedQuery
Replace maxChunks parameter with flexible reducer function that delegates
data aggregation to consumer code. This provides full control over how
streamed chunks are combined into the final data structure.
Add support for custom placeholderData that works seamlessly with the
reducer function, allowing initialization of complex data types beyond
simple arrays.
https://github.com/TanStack/query/discussions/9065
BREAKING CHANGE: The maxChunks parameter has been removed from streamedQuery.
Use a custom reducer function to control data aggregation behavior instead.
* ci: apply automated fixes
* feat(query-core): require initialValue when using custom reducer in streamedQuery
Add type safety by making initialValue mandatory when providing a custom
reducer function. This prevents runtime errors and ensures proper data
initialization for custom data structures beyond simple arrays.
Use conditional types to enforce the relationship between reducer and
initialValue parameters, maintaining backward compatibility for simple
array-based streaming while requiring explicit initialization for
custom reducers.
BREAKING CHANGE: When using a custom reducer function with streamedQuery,
the initialValue parameter is now required and must be provided.
* feat(query-core): require initialValue when using custom reducer in streamedQuery
Add type safety by making initialValue mandatory when providing a custom
reducer function. This prevents runtime errors and ensures proper data
initialization for custom data structures beyond simple arrays.
Use conditional types to enforce the relationship between reducer and
initialValue parameters, maintaining backward compatibility for simple
array-based streaming while requiring explicit initialization for
custom reducers.
BREAKING CHANGE: When using a custom reducer function with streamedQuery,
the initialValue parameter is now required and must be provided.
* feat(query-core): require initialValue when using custom reducer in streamedQuery
Add type safety by making initialValue mandatory when providing a custom
reducer function. This prevents runtime errors and ensures proper data
initialization for custom data structures beyond simple arrays.
Use conditional types to enforce the relationship between reducer and
initialValue parameters, maintaining backward compatibility for simple
array-based streaming while requiring explicit initialization for
custom reducers.
BREAKING CHANGE: When using a custom reducer function with streamedQuery,
the initialValue parameter is now required and must be provided.
* removed personal vscode workspace file
* updated documentation
* fix(docs): clarify reducer function description in streamedQuery documentation
* ci: apply automated fixes
* fix(tests): Code Review :: update streamedQuery tests to use correct initialValue type
---------
Co-authored-by: gobbimar <marco.gobbi@adidas.com>
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* refactor: narrow onSuccess/onError/onMutate/onSettled callback types to Promise<void> | void
Previously, the `onSuccess`, `onError`, `onMutate`, and `onSettled` callbacks were typed as `() => Promise<unknown> | unknown`. While `unknown` is technically valid, it implies that the return value might be used, assigned, or further processed. However, throughout the codebase, these callbacks are invoked solely for their side effects, and their return values are always ignored. Narrowing the type to `Promise<void> | void` makes this intent explicit, clarifies that any return value will be discarded, and prevents misleading type signatures that suggest otherwise.
This commit narrows their types to `() => Promise<void> | void`, which more accurately reflects their intended use.
* docs: update callback return types to Promise<void> | void in mutation-related documentation
This commit refines the documentation for mutation-related callbacks (`onSuccess`, `onError`, `onSettled`, and `onMutate`), changing their return types from `Promise<unknown> | unknown` to `Promise<void> | void`.
* feat(core): StaleTime.Static
* fix: consider StaleTime.Static for invalidation
previously, it didn't matter if we included `stale: true` or not in the filters for refetch, because marking things with query.invalidate() would set them all to stale anyway.
Now, queries with StaleTime.Static will be marked as `invalidated`, but still shouldn't be refetched. The `isStale` filter logic accounts for that, so we have to include it in the filters
* fix: isStale order check
check for observers first because they contain the source of truth calculated with `isStaleByTime`, and it also takes enabled into account
* fix: isStaleByTime logic
we have to check for undefined data first, because queries without data are really always stale; then, the next check must be against StaleTime.Static, because queries that are marked as invalidated are still not stale, even if they are static.
* tests
* fix: type issue in react
* fix: make sure invalidation _always_ only refetches stale queries
this ensures we never refetch Static queries
* fix: never refetch static queries
* fix: make sure we don't refetchOn... for StaleTime.Static even when 'always' is set
* docs: StaleTime.Static
* ref: switch to 'static' string
* docs
* Fix broken link to TkDodo's Blog page from QueryCache page
It looks like the `docs` part of the url was being removed, so there's now one less `../` in the relative url.
* Fix other broken links on page & add `.md` extension to relative links
as suggested by @TkDodo
* feat(core): ensureInfiniteQueryData
* docs: ensureInfiniteQueryData
* feat(types): make sure we can't pass infiniteQueryOptions to non-infinite query functions like fetchQuery
* feat: allow to dehydrate and restore promises
* fix: retries with initialPromise, but without queryFn
* fix: retries for infinite queries
this could use some reconciliation
* refactor: streamline the way we get the queryFn between Query and InfiniteQuery
* fix: only dehydrate query.promise for pending queries
* feat: allow setting hydration and dehydration defaultOptions on the QueryClient
* test: global defaultOptions for hydrate / dehydrate
* tests: hydration of promises
* feat: next15 integration test
* docs: app directory prefetching example
* docs: global hydrate and dehydrate options
* feat: use streaming
* docs: prefetching
* test: useQuery with initialPromise
* fix: do not leak server errors to the client
* docs: typo
* fix: ignore next in sherif
because we test against multiple versions of next
* test: await promise before clearing client to avoid error
* feat: always respect the `promise` passed to hydrate, even if we already have a cached entry.
* Update docs/framework/react/guides/advanced-ssr.md
Co-authored-by: Fredrik Höglund <fredrik.hoglund@gmail.com>
* Update docs/framework/react/guides/advanced-ssr.md
Co-authored-by: Fredrik Höglund <fredrik.hoglund@gmail.com>
* chore: remove leftover 'use client'
* oops
* docs: better text
* chore: better error messages
* update note
* chore: fix lock file
---------
Co-authored-by: Fredrik Höglund <fredrik.hoglund@gmail.com>
* wip - 1
* Fix more links
* Fix one more link
* Another one
* Update a link
* Fix the broken links in the Angular docs
* Fix the broken links in the Vue docs
* Fix the Svelte links in the docs
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* refactor(types): make queryKey required on ObserverOptions
we cannot create an observer without a key, because an observer, per definition, watches a certain query by its key
* test: observers need a key
* chore: remove a branch that can't exist
we can't have an observer without a queryKey
* fix: when comparing with shallowEqualObjects, the currentResult must come first
because it doesn't detect length changes
* test: we get another event
* types: you can't set queryKey as default
* a test for undefined queryKey makes no sense
* fix: more type issues
* types: queryKey is also not required for defaultOptions in solid
* fix(core): shallowEqualObjects should return false for objects with different lengths
as we use it for options, and the length of options can change
* feat: deprecate isDataEqual
* feat: deprecate contextSharing
* feat: deprecate custom loggers
* test: fix ssr-hydration tests
we need to compare against actual console.log here (and not our own logger), because react hydration mismatches are also logged to the console if they exist. This has surfaced another issue because of how we import react for react17/18 differential testing.
* fix: remove useEffect
that would wind up empty in production, and since this is just during development mode, we can just log during render
* test: adapt tests
we can remove most of these in v5
* chore: fix console.mock declaration
* feat: deprecate placeholder data function
* chore: scope test execution to src directories
if we do `pnpm test` locally, it first does typechecking, which produces output in `build` (including test files). Those will then be tested as well and the svelte tests fail with that.
* test: fix vue query test
* un-deprecate placeholderData function
we might still need it after all - to be discussed
* un-deprecate placeholderData function
* fix auto import
* docs: useQuery to object syntax
* docs: invalidateQueries to object syntax
* docs: useMutation to object syntax
* docs: infinite query and other references to object syntax
* feat(query-core): Expose retry error as `failureReason`
* feat: Add `failureReason` to mutation as well
* fix: mutation `failureCount` not being reset to `0` on success
* chore: Add tests for mutation loading state reset
* fix: linting + tests