@tanstack/react-query 4.6.1 → 4.7.2
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.2",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,13 +24,6 @@
|
|
|
24
24
|
"sideEffects": [
|
|
25
25
|
"./src/setBatchUpdatesFn.ts"
|
|
26
26
|
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"clean": "rm -rf ./build",
|
|
29
|
-
"test:codemods": "../../node_modules/.bin/jest --config codemods/jest.config.js",
|
|
30
|
-
"test:eslint": "../../node_modules/.bin/eslint --ext .ts,.tsx ./src",
|
|
31
|
-
"test:jest": "yarn test:codemods && ../../node_modules/.bin/jest --config jest.config.js",
|
|
32
|
-
"test:jest:dev": "yarn test:jest --watch"
|
|
33
|
-
},
|
|
34
27
|
"files": [
|
|
35
28
|
"build/lib/*",
|
|
36
29
|
"build/umd/*",
|
|
@@ -47,7 +40,7 @@
|
|
|
47
40
|
"react-error-boundary": "^3.1.4"
|
|
48
41
|
},
|
|
49
42
|
"dependencies": {
|
|
50
|
-
"@tanstack/query-core": "4.
|
|
43
|
+
"@tanstack/query-core": "4.7.2",
|
|
51
44
|
"use-sync-external-store": "^1.2.0"
|
|
52
45
|
},
|
|
53
46
|
"peerDependencies": {
|
|
@@ -62,5 +55,12 @@
|
|
|
62
55
|
"react-native": {
|
|
63
56
|
"optional": true
|
|
64
57
|
}
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"clean": "rm -rf ./build",
|
|
61
|
+
"test:codemods": "../../node_modules/.bin/jest --config codemods/jest.config.js",
|
|
62
|
+
"test:eslint": "../../node_modules/.bin/eslint --ext .ts,.tsx ./src",
|
|
63
|
+
"test:jest": "yarn test:codemods && ../../node_modules/.bin/jest --config jest.config.js",
|
|
64
|
+
"test:jest:dev": "yarn test:jest --watch"
|
|
65
65
|
}
|
|
66
|
-
}
|
|
66
|
+
}
|
|
@@ -880,34 +880,28 @@ describe('useInfiniteQuery', () => {
|
|
|
880
880
|
const firstCtx = fetchPage.mock.calls[callIndex]![0]
|
|
881
881
|
expect(firstCtx.pageParam).toBeUndefined()
|
|
882
882
|
expect(firstCtx.queryKey).toEqual(key)
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
expect(abortListeners[callIndex]).not.toHaveBeenCalled()
|
|
888
|
-
}
|
|
883
|
+
expect(firstCtx.signal).toBeInstanceOf(AbortSignal)
|
|
884
|
+
expect(firstCtx.signal?.aborted).toBe(false)
|
|
885
|
+
expect(onAborts[callIndex]).not.toHaveBeenCalled()
|
|
886
|
+
expect(abortListeners[callIndex]).not.toHaveBeenCalled()
|
|
889
887
|
|
|
890
888
|
callIndex = 1
|
|
891
889
|
const secondCtx = fetchPage.mock.calls[callIndex]![0]
|
|
892
890
|
expect(secondCtx.pageParam).toBe(11)
|
|
893
891
|
expect(secondCtx.queryKey).toEqual(key)
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
expect(abortListeners[callIndex]).toHaveBeenCalledTimes(1)
|
|
899
|
-
}
|
|
892
|
+
expect(secondCtx.signal).toBeInstanceOf(AbortSignal)
|
|
893
|
+
expect(secondCtx.signal?.aborted).toBe(true)
|
|
894
|
+
expect(onAborts[callIndex]).toHaveBeenCalledTimes(1)
|
|
895
|
+
expect(abortListeners[callIndex]).toHaveBeenCalledTimes(1)
|
|
900
896
|
|
|
901
897
|
callIndex = 2
|
|
902
898
|
const thirdCtx = fetchPage.mock.calls[callIndex]![0]
|
|
903
899
|
expect(thirdCtx.pageParam).toBe(11)
|
|
904
900
|
expect(thirdCtx.queryKey).toEqual(key)
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
expect(abortListeners[callIndex]).not.toHaveBeenCalled()
|
|
910
|
-
}
|
|
901
|
+
expect(thirdCtx.signal).toBeInstanceOf(AbortSignal)
|
|
902
|
+
expect(thirdCtx.signal?.aborted).toBe(false)
|
|
903
|
+
expect(onAborts[callIndex]).not.toHaveBeenCalled()
|
|
904
|
+
expect(abortListeners[callIndex]).not.toHaveBeenCalled()
|
|
911
905
|
})
|
|
912
906
|
|
|
913
907
|
it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used ', async () => {
|
|
@@ -961,23 +955,19 @@ describe('useInfiniteQuery', () => {
|
|
|
961
955
|
const firstCtx = fetchPage.mock.calls[callIndex]![0]
|
|
962
956
|
expect(firstCtx.pageParam).toBeUndefined()
|
|
963
957
|
expect(firstCtx.queryKey).toEqual(key)
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
expect(abortListeners[callIndex]).not.toHaveBeenCalled()
|
|
969
|
-
}
|
|
958
|
+
expect(firstCtx.signal).toBeInstanceOf(AbortSignal)
|
|
959
|
+
expect(firstCtx.signal?.aborted).toBe(false)
|
|
960
|
+
expect(onAborts[callIndex]).not.toHaveBeenCalled()
|
|
961
|
+
expect(abortListeners[callIndex]).not.toHaveBeenCalled()
|
|
970
962
|
|
|
971
963
|
callIndex = 1
|
|
972
964
|
const secondCtx = fetchPage.mock.calls[callIndex]![0]
|
|
973
965
|
expect(secondCtx.pageParam).toBe(11)
|
|
974
966
|
expect(secondCtx.queryKey).toEqual(key)
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
expect(abortListeners[callIndex]).not.toHaveBeenCalled()
|
|
980
|
-
}
|
|
967
|
+
expect(secondCtx.signal).toBeInstanceOf(AbortSignal)
|
|
968
|
+
expect(secondCtx.signal?.aborted).toBe(false)
|
|
969
|
+
expect(onAborts[callIndex]).not.toHaveBeenCalled()
|
|
970
|
+
expect(abortListeners[callIndex]).not.toHaveBeenCalled()
|
|
981
971
|
})
|
|
982
972
|
|
|
983
973
|
it('should keep fetching first page when not loaded yet and triggering fetch more', async () => {
|
|
@@ -1073,22 +1063,12 @@ describe('useInfiniteQuery', () => {
|
|
|
1073
1063
|
|
|
1074
1064
|
await sleep(300)
|
|
1075
1065
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
})
|
|
1083
|
-
} else {
|
|
1084
|
-
// if AbortSignal is not consumed, fetches should not abort
|
|
1085
|
-
expect(fetches).toBe(4)
|
|
1086
|
-
expect(queryClient.getQueryState(key)).toMatchObject({
|
|
1087
|
-
data: { pages: [0, 10, 20, 30], pageParams: [0, 1, 2, 3] },
|
|
1088
|
-
status: 'success',
|
|
1089
|
-
error: null,
|
|
1090
|
-
})
|
|
1091
|
-
}
|
|
1066
|
+
expect(fetches).toBe(2)
|
|
1067
|
+
expect(queryClient.getQueryState(key)).toMatchObject({
|
|
1068
|
+
data: initialData,
|
|
1069
|
+
status: 'success',
|
|
1070
|
+
error: null,
|
|
1071
|
+
})
|
|
1092
1072
|
})
|
|
1093
1073
|
|
|
1094
1074
|
it('should be able to override the cursor in the fetchNextPage callback', async () => {
|
|
@@ -1741,7 +1721,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1741
1721
|
const promise = new Promise<string>((resolve, reject) => {
|
|
1742
1722
|
cancelFn = jest.fn(() => reject('Cancelled'))
|
|
1743
1723
|
signal?.addEventListener('abort', cancelFn)
|
|
1744
|
-
sleep(
|
|
1724
|
+
sleep(20).then(() => resolve('OK'))
|
|
1745
1725
|
})
|
|
1746
1726
|
|
|
1747
1727
|
return promise
|
|
@@ -1765,8 +1745,6 @@ describe('useInfiniteQuery', () => {
|
|
|
1765
1745
|
|
|
1766
1746
|
await waitFor(() => rendered.getByText('off'))
|
|
1767
1747
|
|
|
1768
|
-
|
|
1769
|
-
expect(cancelFn).toHaveBeenCalled()
|
|
1770
|
-
}
|
|
1748
|
+
expect(cancelFn).toHaveBeenCalled()
|
|
1771
1749
|
})
|
|
1772
1750
|
})
|
|
@@ -4328,7 +4328,7 @@ describe('useQuery', () => {
|
|
|
4328
4328
|
const promise = new Promise<string>((resolve, reject) => {
|
|
4329
4329
|
cancelFn = jest.fn(() => reject('Cancelled'))
|
|
4330
4330
|
signal?.addEventListener('abort', cancelFn)
|
|
4331
|
-
sleep(
|
|
4331
|
+
sleep(20).then(() => resolve('OK'))
|
|
4332
4332
|
})
|
|
4333
4333
|
|
|
4334
4334
|
return promise
|
|
@@ -4352,9 +4352,7 @@ describe('useQuery', () => {
|
|
|
4352
4352
|
|
|
4353
4353
|
await waitFor(() => rendered.getByText('off'))
|
|
4354
4354
|
|
|
4355
|
-
|
|
4356
|
-
expect(cancelFn).toHaveBeenCalled()
|
|
4357
|
-
}
|
|
4355
|
+
expect(cancelFn).toHaveBeenCalled()
|
|
4358
4356
|
})
|
|
4359
4357
|
|
|
4360
4358
|
it('should cancel the query if the signal was consumed and there are no more subscriptions', async () => {
|
|
@@ -4402,19 +4400,11 @@ describe('useQuery', () => {
|
|
|
4402
4400
|
dataUpdateCount: 1,
|
|
4403
4401
|
})
|
|
4404
4402
|
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
})
|
|
4411
|
-
} else {
|
|
4412
|
-
expect(queryCache.find([key, 1])?.state).toMatchObject({
|
|
4413
|
-
data: 'data 1',
|
|
4414
|
-
status: 'success',
|
|
4415
|
-
dataUpdateCount: 1,
|
|
4416
|
-
})
|
|
4417
|
-
}
|
|
4403
|
+
expect(queryCache.find([key, 1])?.state).toMatchObject({
|
|
4404
|
+
data: undefined,
|
|
4405
|
+
status: 'loading',
|
|
4406
|
+
fetchStatus: 'idle',
|
|
4407
|
+
})
|
|
4418
4408
|
|
|
4419
4409
|
expect(queryCache.find([key, 2])?.state).toMatchObject({
|
|
4420
4410
|
data: 'data 2',
|
|
@@ -4422,19 +4412,11 @@ describe('useQuery', () => {
|
|
|
4422
4412
|
dataUpdateCount: 1,
|
|
4423
4413
|
})
|
|
4424
4414
|
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
})
|
|
4431
|
-
} else {
|
|
4432
|
-
expect(queryCache.find([key, 3])?.state).toMatchObject({
|
|
4433
|
-
data: 'data 3',
|
|
4434
|
-
status: 'success',
|
|
4435
|
-
dataUpdateCount: 1,
|
|
4436
|
-
})
|
|
4437
|
-
}
|
|
4415
|
+
expect(queryCache.find([key, 3])?.state).toMatchObject({
|
|
4416
|
+
data: undefined,
|
|
4417
|
+
status: 'loading',
|
|
4418
|
+
fetchStatus: 'idle',
|
|
4419
|
+
})
|
|
4438
4420
|
})
|
|
4439
4421
|
|
|
4440
4422
|
it('should refetch when quickly switching to a failed query', async () => {
|
|
@@ -5486,7 +5468,7 @@ describe('useQuery', () => {
|
|
|
5486
5468
|
status: 'success',
|
|
5487
5469
|
})
|
|
5488
5470
|
|
|
5489
|
-
expect(count).toBe(
|
|
5471
|
+
expect(count).toBe(1)
|
|
5490
5472
|
|
|
5491
5473
|
onlineMock.mockRestore()
|
|
5492
5474
|
})
|