Inlining a `select` on a query object passed to `useQueries` /
`useSuspenseQueries` can't infer its `data` argument from the sibling
`queryFn` and falls back to `unknown` — a known TypeScript limitation
(TanStack/query#6556).
Document the two workarounds (annotate the `select` parameter, or define
the query with the `queryOptions` helper) in the React docs, and add type
tests guarding the behavior. Scoped to React for an easier review; the
other framework adapters can follow the same pattern in separate PRs.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* 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(react-query): add mutationOptions
* test(react-query): add DataTag test case
* fix(react-query): remove unnecessary types from mutation
* fix(react-query): remove unncessary type overload
* chore(react-query): add mutationOptions to barrel file
* fix(react-query): fix test eslint issue
* docs(react-query): add more examples
* test(react-query): add more test cases
* chore(react-query): Change mutaitonKey to required
* fix(react-query): fix test code type error
* test(react-query): add testcase when used with other mutation util
* fix(react-query): fix error test code and avoid use deprecateed method
* fix(react-query): fix error test code and avoid use deprecateed method
* fix(react-query): fix import detect error
* fix(react-query): fix import detect error
* fix(react-query): add function overload
* test(react-query): fix mutation options test code
* Update docs/framework/react/typescript.md
* Update docs/framework/react/reference/mutationOptions.md
* Update docs/framework/react/typescript.md
* fix: update mutationOptions type definition to allow optional mutationKey with restricting filter when mutationKey wasn't passed
* ci: apply automated fixes
* chore: add Nick-Lucas as co-author
Co-authored-by: Nick Lucas <8896153+Nick-Lucas@users.noreply.github.com>
* test(react-query): fix test code and add used with useMutation without mutationKey
* Update packages/react-query/src/__tests__/mutationOptions.test-d.tsx
* docs: add mutationOptions to sidebar config
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
Co-authored-by: Jonghyeon Ko <manudeli.ko@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Nick Lucas <8896153+Nick-Lucas@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
* docs(react-query): fix incorrect paths in documentation
The documentation contained incorrect file paths.
Fixed the incorrect paths to match the actual directory structure.
* docs(react-query): fixed incorrect relative path (./ -> ../)
* add failing repro test
* update assertinos
* add logg
* ehm - maybe fix?
* rm -only
* make example
* upd
* ad debug logs
* more debugging
* push
* maybe???
* rm log
* revert
* fix: ?
* fix: check for pending status again
otherwise, we risk including promises that happen because of background updates (think persistQueryClient)
* fix: clear serverQueryClient between "requests"
otherwise, we are re-using the cache and the query won't be in "pending" state the second time around
* chore: remove logs
* rethrow next build error
* kick off ci again
* add `shouldRedactError` option
* pluralize
* docs
* chore: more memory
* chore: revert more memory
* don't compare statuses if they don't exist
* ci: apply automated fixes
* lint
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* feat(react-query): allow useQuery and useQueries to unsubscribe from the query cache with an option
* test: subscribed
* fix: revert calling getOptimisticResult later
* docs(react): update the react-native.md section (#8506)
* update the doc
* update the doc
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* docs: reference
---------
Co-authored-by: Florian De la comble <f.delacomble@gmail.com>
* let’s do it again
* fix test group
* maybe
* mkay
* cool
* rm console.logs
* mkay
* mkay
* fix(vue-query): invalidate queries immediately after calling `invalidateQueries` (#7930)
* fix(vue-query): invalidate queries immediately after call `invalidateQueries`
* chore: recovery code comments
* release: v5.53.2
* docs(vue-query): update SSR guide for nuxt2 (#8001)
* docs: update SSR guide for nuxt2
* ci: apply automated fixes
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* thenable
* mkay
* Update packages/react-query/src/__tests__/useQuery.test.tsx
* mkay
* mkay
* faster and more consistent
* mkay
* mkay
* mkay
* mkay
* mkay
* fix unhandled rejections
* more
* more
* mkay
* fix more
* fixy
* cool
* Update packages/react-query/package.json
* fix: track data property if `promise` is tracked
if users use the `promise` returned from useQuery, they are actually interested in the `data` it unwraps to. Since the promise doesn't change when data resolves, we would likely miss a re-render
* Revert "fix: track data property if `promise` is tracked"
This reverts commit d1184babd1.
* add test case that @tkdodo was concerned about
* tweak
* mkay
* add `useInfiniteQuery()` test
* consistent testing
* better test
* rm comment
* test resetting errror boundary
* better test
* cool
* cool
* more test
* mv cleanup
* mkay
* some more things
* add fixme
* fix types
* wat
* fixes
* revert
* fix
* colocating doesn’t workkk
* mkay
* mkay
* might work
* more test
* cool
* i don’t know hwat i’m doing
* mocky
* lint
* space
* rm log
* setIsServer
* mkay
* ffs
* remove unnecessary stufffff
* tweak more
* just naming and comments
* tweak
* fix: use fetchOptimistic util instead of observer.fetchOptimistic
* refactor: make sure to only trigger fetching during render if we really have no cache entry yet
* fix: move the `isNewCacheEntry` check before observer creation
* chore: avoid rect key warnings
* fix: add an `updateResult` for all observers to finalize currentThenable
* chore: logs during suspense errors
* fix: empty catch
* feature flag
* add comment
* simplify
* omit from suspense
* feat flag
* more tests
* test: scope experimental_promise to useQuery().promise tests
* refactor: rename to experimental_prefetchInRender
* test: more tests
* test: more cancelation
* fix cancellation
* make it work
* tweak comment
* Update packages/react-query/src/useBaseQuery.ts
* simplify code a bit
* Update packages/query-core/src/queryObserver.ts
* refactor: move experimental_prefetchInRender check until after the early bail-out
* fix: when cancelled, the promise should stay pending
* test: disabled case
* chore: no idea what's going on
* refactor: delete unnecessary check
* revert refactor i did for cancellation when we wanted it to `throw`
* add docs
* align
* tweak
* Update docs/reference/QueryClient.md
* Update docs/framework/react/reference/queryOptions.md
---------
Co-authored-by: Alex Liu <dsa1314@gmail.com>
Co-authored-by: Tanner Linsley <tannerlinsley@users.noreply.github.com>
Co-authored-by: Damian Osipiuk <osipiukd+git@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* fix(query-core): allow function value of `notifyOnChangeProps` query option to return `undefined`
`undefined` is a valid return value for the function value of `notifyOnChangeProps`. See linked issue for more details.
Fixes#7426.
* docs(react-query): update signature of `useQuery`'s `notifyOnChangeProps` option
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* Add possibility to pass a callback to enabled.
* Refactor into using the same pattern as resolving staletime, with the use of a resolveEnabled util function
* Update tests for enabled option as a callback
* update docs
* remove typo
* Update enabled type in docs
* remove duplicated test case
* Fix eslint errors
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
Co-authored-by: John Pettersson <john.pettersson@carnegie.se>
* feat: usePrefetchQuery
* refactor: switch to actual prefetching
* refactor: remove ensureInfiniteQueryData function
will do in a separate PR
* chore: add tests for usePrefetchQuery and usePrefetchInfiniteQuery (#7586)
* chore: add tests for usePrefetchQuery and usePrefetchInfiniteQuery
* chore: update tests to assert the alternative spy is not called
* chore: add some new tests
* chore: remove it.only whoops
* chore: call mockClear after fetching
* chore: improve waterfall test by asserting fallback calls instead of loading node query
* chore: improve code repetition
* chore: add some generics to helper functions
* usePrefetchQuery type tests and docs (#7592)
* chore: add type tests and docs
* chore: update hooks to use FetchQueryOptions and FetchInfiniteQueryOptions
* chore: update tests
* chore: update docs
* chore: remove .md extension from link
* chore: add unknown default value to TQueryFnData
* Apply suggestions from code review
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
* Apply suggestions from code review
Co-authored-by: Fredrik Höglund <fredrik.hoglund@gmail.com>
* chore: fix types in tests
* chore: add new tests (#7614)
* chore: add new tests
* Apply suggestions from code review
---------
Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
---------
Co-authored-by: Bruno Lopes <88719327+brunolopesr@users.noreply.github.com>
Co-authored-by: Fredrik Höglund <fredrik.hoglund@gmail.com>