@tanstack/react-query 5.51.1 → 5.51.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/__tests__/prefetch.test.tsx +7 -5
- package/src/__tests__/ssr-hydration.test.tsx +2 -8
- package/src/__tests__/suspense.test.tsx +1 -1
- package/src/__tests__/useInfiniteQuery.test.tsx +6 -8
- package/src/__tests__/useMutation.test.tsx +1 -1
- package/src/__tests__/useQuery.test.tsx +19 -12
- package/src/__tests__/utils.tsx +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query",
|
|
3
|
-
"version": "5.51.
|
|
3
|
+
"version": "5.51.3",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"!build/codemods/**/__tests__"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@tanstack/query-core": "5.51.
|
|
44
|
+
"@tanstack/query-core": "5.51.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/react": "npm:types-react@rc",
|
|
48
48
|
"@types/react-dom": "npm:types-react-dom@rc",
|
|
49
|
-
"@vitejs/plugin-react": "^4.
|
|
49
|
+
"@vitejs/plugin-react": "^4.3.1",
|
|
50
50
|
"eslint-plugin-react-compiler": "^0.0.0-experimental-c8b3f72-20240517",
|
|
51
51
|
"react": "19.0.0-rc-4c2e457c7c-20240522",
|
|
52
52
|
"react-dom": "19.0.0-rc-4c2e457c7c-20240522",
|
|
@@ -16,11 +16,13 @@ import type { InfiniteData, UseInfiniteQueryOptions, UseQueryOptions } from '..'
|
|
|
16
16
|
import type { Mock } from 'vitest'
|
|
17
17
|
|
|
18
18
|
const generateQueryFn = (data: string) =>
|
|
19
|
-
vi
|
|
20
|
-
|
|
19
|
+
vi
|
|
20
|
+
.fn<(...args: Array<any>) => Promise<string>>()
|
|
21
|
+
.mockImplementation(async () => {
|
|
22
|
+
await sleep(10)
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
return data
|
|
25
|
+
})
|
|
24
26
|
|
|
25
27
|
const generateInfiniteQueryOptions = (
|
|
26
28
|
data: Array<{ data: string; currentPage: number; totalPages: number }>,
|
|
@@ -29,7 +31,7 @@ const generateInfiniteQueryOptions = (
|
|
|
29
31
|
|
|
30
32
|
return {
|
|
31
33
|
queryFn: vi
|
|
32
|
-
.fn<any
|
|
34
|
+
.fn<(...args: Array<any>) => Promise<(typeof data)[number]>>()
|
|
33
35
|
.mockImplementation(async () => {
|
|
34
36
|
const currentPageData = data[currentPage]
|
|
35
37
|
if (!currentPageData) {
|
|
@@ -46,10 +46,7 @@ describe('Server side rendering with de/rehydration', () => {
|
|
|
46
46
|
const consoleMock = vi.spyOn(console, 'error')
|
|
47
47
|
consoleMock.mockImplementation(() => undefined)
|
|
48
48
|
|
|
49
|
-
const fetchDataSuccess = vi.fn<
|
|
50
|
-
Parameters<typeof fetchData>,
|
|
51
|
-
ReturnType<typeof fetchData>
|
|
52
|
-
>(fetchData)
|
|
49
|
+
const fetchDataSuccess = vi.fn<typeof fetchData>(fetchData)
|
|
53
50
|
|
|
54
51
|
// -- Shared part --
|
|
55
52
|
function SuccessComponent() {
|
|
@@ -203,10 +200,7 @@ describe('Server side rendering with de/rehydration', () => {
|
|
|
203
200
|
const consoleMock = vi.spyOn(console, 'error')
|
|
204
201
|
consoleMock.mockImplementation(() => undefined)
|
|
205
202
|
|
|
206
|
-
const fetchDataSuccess = vi.fn<
|
|
207
|
-
Parameters<typeof fetchData>,
|
|
208
|
-
ReturnType<typeof fetchData>
|
|
209
|
-
>(fetchData)
|
|
203
|
+
const fetchDataSuccess = vi.fn<typeof fetchData>(fetchData)
|
|
210
204
|
|
|
211
205
|
// -- Shared part --
|
|
212
206
|
function SuccessComponent() {
|
|
@@ -123,7 +123,7 @@ describe('useSuspenseQuery', () => {
|
|
|
123
123
|
it('should not call the queryFn twice when used in Suspense mode', async () => {
|
|
124
124
|
const key = queryKey()
|
|
125
125
|
|
|
126
|
-
const queryFn = vi.fn<Array<unknown
|
|
126
|
+
const queryFn = vi.fn<(...args: Array<unknown>) => string>()
|
|
127
127
|
queryFn.mockImplementation(() => {
|
|
128
128
|
sleep(10)
|
|
129
129
|
return 'data'
|
|
@@ -920,11 +920,10 @@ describe('useInfiniteQuery', () => {
|
|
|
920
920
|
it('should silently cancel an ongoing fetchNextPage request when another fetchNextPage is invoked', async () => {
|
|
921
921
|
const key = queryKey()
|
|
922
922
|
const start = 10
|
|
923
|
-
const onAborts: Array<Mock<any
|
|
924
|
-
const abortListeners: Array<Mock<any
|
|
923
|
+
const onAborts: Array<Mock<(...args: Array<any>) => any>> = []
|
|
924
|
+
const abortListeners: Array<Mock<(...args: Array<any>) => any>> = []
|
|
925
925
|
const fetchPage = vi.fn<
|
|
926
|
-
|
|
927
|
-
Promise<number>
|
|
926
|
+
(context: QueryFunctionContext<typeof key, number>) => Promise<number>
|
|
928
927
|
>(async ({ pageParam, signal }) => {
|
|
929
928
|
const onAbort = vi.fn()
|
|
930
929
|
const abortListener = vi.fn()
|
|
@@ -996,11 +995,10 @@ describe('useInfiniteQuery', () => {
|
|
|
996
995
|
it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used ', async () => {
|
|
997
996
|
const key = queryKey()
|
|
998
997
|
const start = 10
|
|
999
|
-
const onAborts: Array<Mock<any
|
|
1000
|
-
const abortListeners: Array<Mock<any
|
|
998
|
+
const onAborts: Array<Mock<(...args: Array<any>) => any>> = []
|
|
999
|
+
const abortListeners: Array<Mock<(...args: Array<any>) => any>> = []
|
|
1001
1000
|
const fetchPage = vi.fn<
|
|
1002
|
-
|
|
1003
|
-
Promise<number>
|
|
1001
|
+
(context: QueryFunctionContext<typeof key, number>) => Promise<number>
|
|
1004
1002
|
>(async ({ pageParam, signal }) => {
|
|
1005
1003
|
const onAbort = vi.fn()
|
|
1006
1004
|
const abortListener = vi.fn()
|
|
@@ -150,7 +150,7 @@ describe('useMutation', () => {
|
|
|
150
150
|
let count = 0
|
|
151
151
|
type Value = { count: number }
|
|
152
152
|
|
|
153
|
-
const mutateFn = vi.fn<
|
|
153
|
+
const mutateFn = vi.fn<(value: Value) => Promise<Value>>()
|
|
154
154
|
|
|
155
155
|
mutateFn.mockImplementationOnce(() => {
|
|
156
156
|
return Promise.reject(new Error('Error test Jonas'))
|
|
@@ -2565,7 +2565,9 @@ describe('useQuery', () => {
|
|
|
2565
2565
|
|
|
2566
2566
|
it('should not refetch query on focus when `enabled` is set to `false`', async () => {
|
|
2567
2567
|
const key = queryKey()
|
|
2568
|
-
const queryFn = vi
|
|
2568
|
+
const queryFn = vi
|
|
2569
|
+
.fn<(...args: Array<unknown>) => string>()
|
|
2570
|
+
.mockReturnValue('data')
|
|
2569
2571
|
|
|
2570
2572
|
function Page() {
|
|
2571
2573
|
const { data = 'default' } = useQuery({
|
|
@@ -3340,7 +3342,7 @@ describe('useQuery', () => {
|
|
|
3340
3342
|
it('should retry specified number of times', async () => {
|
|
3341
3343
|
const key = queryKey()
|
|
3342
3344
|
|
|
3343
|
-
const queryFn = vi.fn<Array<unknown
|
|
3345
|
+
const queryFn = vi.fn<(...args: Array<unknown>) => unknown>()
|
|
3344
3346
|
queryFn.mockImplementation(() => {
|
|
3345
3347
|
return Promise.reject(new Error('Error test Barrett'))
|
|
3346
3348
|
})
|
|
@@ -3377,7 +3379,7 @@ describe('useQuery', () => {
|
|
|
3377
3379
|
it('should not retry if retry function `false`', async () => {
|
|
3378
3380
|
const key = queryKey()
|
|
3379
3381
|
|
|
3380
|
-
const queryFn = vi.fn<Array<unknown
|
|
3382
|
+
const queryFn = vi.fn<(...args: Array<unknown>) => unknown>()
|
|
3381
3383
|
|
|
3382
3384
|
queryFn.mockImplementationOnce(() => {
|
|
3383
3385
|
return Promise.reject(new Error('Error test Tanner'))
|
|
@@ -3423,7 +3425,7 @@ describe('useQuery', () => {
|
|
|
3423
3425
|
|
|
3424
3426
|
type DelayError = { delay: number }
|
|
3425
3427
|
|
|
3426
|
-
const queryFn = vi.fn<Array<unknown
|
|
3428
|
+
const queryFn = vi.fn<(...args: Array<unknown>) => unknown>()
|
|
3427
3429
|
queryFn.mockImplementation(() => {
|
|
3428
3430
|
return Promise.reject({ delay: 50 })
|
|
3429
3431
|
})
|
|
@@ -3616,10 +3618,10 @@ describe('useQuery', () => {
|
|
|
3616
3618
|
const key = queryKey()
|
|
3617
3619
|
const states: Array<UseQueryResult<string>> = []
|
|
3618
3620
|
|
|
3619
|
-
const queryFn = vi.fn<Array<unknown
|
|
3621
|
+
const queryFn = vi.fn<(...args: Array<unknown>) => string>()
|
|
3620
3622
|
queryFn.mockImplementation(() => 'data')
|
|
3621
3623
|
|
|
3622
|
-
const prefetchQueryFn = vi.fn<Array<unknown
|
|
3624
|
+
const prefetchQueryFn = vi.fn<(...args: Array<unknown>) => string>()
|
|
3623
3625
|
prefetchQueryFn.mockImplementation(() => 'not yet...')
|
|
3624
3626
|
|
|
3625
3627
|
await queryClient.prefetchQuery({
|
|
@@ -3647,10 +3649,11 @@ describe('useQuery', () => {
|
|
|
3647
3649
|
it('should not refetch if not stale after a prefetch', async () => {
|
|
3648
3650
|
const key = queryKey()
|
|
3649
3651
|
|
|
3650
|
-
const queryFn = vi.fn<Array<unknown
|
|
3652
|
+
const queryFn = vi.fn<(...args: Array<unknown>) => string>()
|
|
3651
3653
|
queryFn.mockImplementation(() => 'data')
|
|
3652
3654
|
|
|
3653
|
-
const prefetchQueryFn =
|
|
3655
|
+
const prefetchQueryFn =
|
|
3656
|
+
vi.fn<(...args: Array<unknown>) => Promise<string>>()
|
|
3654
3657
|
prefetchQueryFn.mockImplementation(async () => {
|
|
3655
3658
|
await sleep(10)
|
|
3656
3659
|
return 'not yet...'
|
|
@@ -3958,7 +3961,7 @@ describe('useQuery', () => {
|
|
|
3958
3961
|
|
|
3959
3962
|
it('it should support enabled:false in query object syntax', async () => {
|
|
3960
3963
|
const key = queryKey()
|
|
3961
|
-
const queryFn = vi.fn<Array<unknown
|
|
3964
|
+
const queryFn = vi.fn<(...args: Array<unknown>) => string>()
|
|
3962
3965
|
queryFn.mockImplementation(() => 'data')
|
|
3963
3966
|
|
|
3964
3967
|
function Page() {
|
|
@@ -4052,7 +4055,9 @@ describe('useQuery', () => {
|
|
|
4052
4055
|
|
|
4053
4056
|
it('should not cause memo churn when data does not change', async () => {
|
|
4054
4057
|
const key = queryKey()
|
|
4055
|
-
const queryFn = vi
|
|
4058
|
+
const queryFn = vi
|
|
4059
|
+
.fn<(...args: Array<unknown>) => string>()
|
|
4060
|
+
.mockReturnValue('data')
|
|
4056
4061
|
const memoFn = vi.fn()
|
|
4057
4062
|
|
|
4058
4063
|
function Page() {
|
|
@@ -4260,7 +4265,9 @@ describe('useQuery', () => {
|
|
|
4260
4265
|
it('should refetch if any query instance becomes enabled', async () => {
|
|
4261
4266
|
const key = queryKey()
|
|
4262
4267
|
|
|
4263
|
-
const queryFn = vi
|
|
4268
|
+
const queryFn = vi
|
|
4269
|
+
.fn<(...args: Array<unknown>) => string>()
|
|
4270
|
+
.mockReturnValue('data')
|
|
4264
4271
|
|
|
4265
4272
|
function Disabled() {
|
|
4266
4273
|
useQuery({ queryKey: key, queryFn, enabled: false })
|
|
@@ -4941,7 +4948,7 @@ describe('useQuery', () => {
|
|
|
4941
4948
|
})
|
|
4942
4949
|
|
|
4943
4950
|
it('should refetch when changed enabled to true in error state', async () => {
|
|
4944
|
-
const queryFn = vi.fn<Array<unknown
|
|
4951
|
+
const queryFn = vi.fn<(...args: Array<unknown>) => unknown>()
|
|
4945
4952
|
queryFn.mockImplementation(async () => {
|
|
4946
4953
|
await sleep(10)
|
|
4947
4954
|
return Promise.reject(new Error('Suspense Error Bingo'))
|
package/src/__tests__/utils.tsx
CHANGED
|
@@ -48,13 +48,13 @@ export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
|
48
48
|
|
|
49
49
|
export function mockVisibilityState(
|
|
50
50
|
value: DocumentVisibilityState,
|
|
51
|
-
): MockInstance<
|
|
51
|
+
): MockInstance<() => DocumentVisibilityState> {
|
|
52
52
|
return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export function mockOnlineManagerIsOnline(
|
|
56
56
|
value: boolean,
|
|
57
|
-
): MockInstance<
|
|
57
|
+
): MockInstance<() => boolean> {
|
|
58
58
|
return vi.spyOn(onlineManager, 'isOnline').mockReturnValue(value)
|
|
59
59
|
}
|
|
60
60
|
|