-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: backport v5 apis to v4 #9140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4
Are you sure you want to change the base?
Conversation
View your CI Pipeline Execution ↗ for commit b907fd5.
☁️ Nx Cloud last updated this comment at |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit b907fd5:
|
d9085f6
to
98805c8
Compare
| 'getNextPageParam' | ||
| 'getPreviousPageParam' | ||
| 'queryKeyHashFn' | ||
| '_defaulted' | ||
| 'behavior' | ||
| 'structuralSharing' | ||
| 'isDataEqual' | ||
| 'onSuccess' | ||
| 'onError' | ||
| 'onSettled' | ||
| 'enabled' | ||
| 'refetchInterval' | ||
| 'initialData' | ||
| 'networkMode' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don’t have this in v5. Where is this list coming from ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right — only 'getNextPageParam', 'getPreviousPageParam', 'onSuccess', 'onError', 'onSettled', and 'context' needed to be omitted here since these properties are no longer present in v5. When I copied the Suspensive React Query code, I didn't reconsider whether this list was still relevant, and ended up including some obsolete entries. Thanks for catching that! I reflect in 6c9d86f
Also, I should have omitted 'refetchInterval' as well. If we don’t, it can cause a TypeScript error like below. I was a bit sad to leave it out 🥲 — but I figured it’s not a big deal to omit it from queryOptions for now, as we can remove
omitting 'refetchInterval' next time if need.
Without Omit refetchInterval

With Omit refetchInterval

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to explore some more to see if it's possible to support this without omitting refetchInterval. Will share back if I find a better workaround.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I explored a bit further to see if refetchInterval
could be supported without breaking the v5 types, but unfortunately, I couldn’t find a viable workaround.
In v5, the refetchInterval function now receives only the Query object as its argument, whereas in v4 it used to receive both TData and Query. This change in signature makes it incompatible with v4-style callbacks. If we allow refetchInterval to pass through as-is, it could lead to subtle bugs or confusing TypeScript errors for users who are migrating and expect the old behavior.
Since the primary goal of queryOptions
is to offer reusability and type safety across v5, I believe it’s better to leave refetchInterval
out for now. Users who need it can still add it manually when configuring individual queries.
3ea3785
to
6c9d86f
Compare
6c9d86f
to
56487e6
Compare
expectTypeOf(query2).toEqualTypeOf< | ||
DefinedUseQueryResult<{ field: string }> | ||
>() | ||
expectTypeOf(query3).toEqualTypeOf< | ||
DefinedUseQueryResult<{ field: string }> | ||
>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the issue where useQueries
had to return DefinedUseQueryResult
.
This was previously returning UseQueryResult
instead of DefinedUseQueryResult
.
@@ -256,6 +268,8 @@ export interface QueryObserverOptions< | |||
/** | |||
* Set this to `true` to keep the previous `data` when fetching based on a new query key. | |||
* Defaults to `false`. | |||
* | |||
* @deprecated keepPreviousData will be removed in the next major version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tagged @deprecated
/** | ||
* @deprecated This method will accept only queryKey in the next major version. | ||
*/ | ||
getQueryData<TQueryFnData = unknown>( | ||
queryKey: QueryKey, | ||
filters: OmitKeyof<QueryFilters, 'queryKey'>, | ||
): TQueryFnData | undefined | ||
/** | ||
* @deprecated This method will accept only queryKey in the next major version. | ||
*/ | ||
getQueryData<TQueryFnData = unknown>( | ||
queryKey: QueryKey, | ||
filters?: OmitKeyof<QueryFilters, 'queryKey'>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3a518d9
to
ab6151b
Compare
find<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData>( | ||
arg1: QueryKey, | ||
arg2?: QueryFilters, | ||
filters: QueryFilters, | ||
): Query<TQueryFnData, TError, TData> | undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a function overload accepting only a filters
object. This could make migration to v5 easier. In v5, QueryCache.find
only accepts a filters
object
/** | ||
* @deprecated This method should be used with only one object argument. | ||
*/ | ||
find<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData>( | ||
queryKey: QueryKey, | ||
filters?: OmitKeyof<QueryFilters, 'queryKey'>, | ||
): Query<TQueryFnData, TError, TData> | undefined | ||
/** | ||
* @deprecated This method should be used with only one object argument. | ||
*/ | ||
find<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData>( | ||
arg1: QueryKey | QueryFilters, | ||
arg2?: OmitKeyof<QueryFilters, 'queryKey'>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tagged jsdoc @deprecated
on unnecessary type overriding of QueryCache's methods
/** | ||
* @deprecated This method should be used with only one object argument. | ||
*/ | ||
findAll( | ||
queryKey?: QueryKey, | ||
filters?: OmitKeyof<QueryFilters, 'queryKey'>, | ||
): Query[] | ||
/** | ||
* @deprecated This method should be used with only one object argument. | ||
*/ | ||
findAll( | ||
arg1?: QueryKey | QueryFilters, | ||
arg2?: OmitKeyof<QueryFilters, 'queryKey'>, | ||
): Query[] | ||
/** | ||
* @deprecated This method should be used with only one object argument. | ||
*/ | ||
findAll( | ||
arg1?: QueryKey | QueryFilters, | ||
arg2?: OmitKeyof<QueryFilters, 'queryKey'>, | ||
): Query[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tagged jsdoc @deprecated
on unnecessary type overriding of QueryCache's methods
isLoading, | ||
isPending: isLoading, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use isPending like v5
/** | ||
* @deprecated This method should be used with only one object argument. | ||
*/ | ||
isFetching( | ||
queryKey?: QueryKey, | ||
filters?: OmitKeyof<QueryFilters, 'queryKey'>, | ||
): number | ||
/** | ||
* @deprecated This method should be used with only one object argument. | ||
*/ | ||
isFetching(arg1?: QueryKey | QueryFilters, arg2?: QueryFilters): number { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tag jsdoc @deprecated
on unnecessary function overloads
ab9aaf0
to
d1698fa
Compare
Co-authored-by: Daniel Perez <[email protected]>
d1698fa
to
b907fd5
Compare
Initialized by #8754 with @danielpza
I added the v5 backport API to v4 based on the migration guide from migrating to v5 guide in TanStack Query Official Docs.
@tanstack/query-core
@deprecated
@deprecated
on unnecessary function overloads of QueryClient's methods -- isFetching, ensureQueryData, getQueriesData, setQueriesData, removeQueries, resetQueries, cancelQueries, invalidateQueries, refetchQueries, fetchQuery, prefetchQuery, fetchInfiniteQuery, prefetchInfiniteQuery@deprecated
on unnecessary function overloads of QueryCache's methods -- find, findAll@deprecated
on unnecessary function overloads of useQuery, useInfiniteQuery@tanstack/react-query
@tanstack/vue-query
I added test cases to guarantee all use cases with these apis backported