* Revert "refactor(types): narrow onSuccess/onError/onMutate/onSettled callback types to Promise<void> | void (#9202)"
This reverts commit 982f6ca607.
* test: add callback return type tests for mutation callbacks
Adds test coverage for mutation callback return types, inspired by the discussions and [TkDodo's comment](https://github.com/TanStack/query/pull/9245#issuecomment-2939664588
) in #9245 and the original Promise.all() edge case identified in #9202.
The original PR #9202 narrowed callback return types from `Promise<unknown> | unknown`
to `Promise<void> | void`, but this broke common patterns like:
```ts
onSuccess: (data) => Promise.all([
invalidateQueries(),
trackAnalytics(),
])
```
As noted in [the original discussion](https://github.com/TanStack/query/pull/9202#issuecomment-2934491122),
this `Promise.all()` pattern was a legitimate use case that many users relied on.
These tests ensure we support all the callback patterns that users expect:
✅ **Sync patterns**: Implicit void, explicit void, non-void returns
✅ **Async patterns**: Async functions, Promise.resolve(), Promise<T> returns
✅ **Promise.all() patterns**: The original breaking case from #9202✅ **Promise.allSettled() patterns**: Additional parallel operation support
✅ **Mixed patterns**: Different callback types in same mutation
✅ **Error handling**: All patterns work in error scenarios
✅ **Return value isolation**: Callback returns don't affect mutation result
* refactor(tests): remove unnecessary parameters in mutation tests
* test(mutations): fix mutation test ordering with error handling and cleanup verification
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* Add persisterRestoreByKey
* Fix imports
* Add missing return statement
* Fix test
* docs
* Add extra test
* Merge into single restoreQueries function
- Replaced sponsor image paths that pointed to `_build/assets/...` (invalid in GitHub markdown context)
- Updated to use public URLs (`https://tanstack.com/assets/...`) to prevent broken images
Multiple framework-specific packages (`solid-query`, `svelte-query`, and `angular-query-experimental`) were maintaining their own implementations of the `noop` function, creating unnecessary code duplication across the codebase.
```typescript
// Before: Each package had its own noop
// packages/svelte-query/src/utils.ts
export function noop(): void {}
// packages/solid-query/src/utils.ts (missing, causing import errors)
// Local noop definitions scattered across files
```
Consolidated all `noop` usage to import from the canonical implementation in `@tanstack/query-core`, which all framework packages already depend on.
```typescript
// After: Single source of truth
import { noop } from '@tanstack/query-core'
```
- **Removed duplicate `noop` definition** from `packages/svelte-query/src/utils.ts`
- **Updated import statements** in Solid Query and Svelte Query to use `noop` from `@tanstack/query-core`
- **Fixed missing utils file** in Solid Query that was causing import errors
- **Resolved TypeScript compatibility** issues with `noop`'s overloaded return types
- **Persisters were intentionally left unchanged** as they don't import `query-core` and maintain their own lightweight utils
- **Framework packages already depend on `query-core`**, making this consolidation natural and dependency-free
Refactored the `getQueryData` method in `QueryClient` to use generics for type inference instead of type assertion with `as`.
The previous implementation of `getQueryData` relied on a type assertion (`as`) to cast the result of `queryCache.get()`:
```typescript
return this.#queryCache.get(options.queryHash)?.state.data as
| TInferredQueryFnData
| undefined
```
While this works, using generics is a more type-safe and idiomatic approach in TypeScript. It allows the type system to infer the correct type for `TInferredQueryFnData` when `queryCache.get` is called, reducing the need for manual type casting and potential runtime errors if the cast is incorrect.
## Changes
The `getQueryData` method has been updated to pass `TInferredQueryFnData` as a generic type argument to `this.#queryCache.get()`:
**Before:**
```typescript
return this.#queryCache.get(options.queryHash)?.state.data as
| TInferredQueryFnData
| undefined
```
**After:**
```typescript
return this.#queryCache.get<TInferredQueryFnData>(options.queryHash)?.state
.data
```
This change leverages the existing generic type parameter `TInferredQueryFnData` already defined in the `getQueryData` signature and `QueryCache#get` method.
This refactor extracts the creation of the query function context and fetch context into dedicated helper functions (e.g., `createQueryFnContext`), improving code readability. This change:
- Moves type assertions and type handling higher up, reducing inline type noise and making type boundaries clearer.
- Replaces ad-hoc object construction with a function that does one thing (build query contexts).
No functional behavior is changed; this is a structural and type-safety improvement.
* 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
* chore: update to eslint-plugin-react-hooks v6
and remove the separate compiler linter plugin, as those rules are now integrated
* chore: disable compiler-linter in tests
* chore: bypass lint violations
* chore: Disable '@eslint-react/no-context-provider'
to be react 18 compatible
Moved the NonUndefinedGuard type definition to the query-core package for better reusability across various query options files in angular, react, solid, svelte, and vue packages. Removed duplicate definitions from individual files.
* test(query-core): add test case for query
* test(query-core): use hashQueryKeyByOptions
* add test case about "should call initialData function when it is a function"
* reflect feedback
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>