@tanstack/react-query 4.7.1 → 4.8.0

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.7.1",
3
+ "version": "4.8.0",
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.7.1",
43
+ "@tanstack/query-core": "4.8.0",
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": "pnpm test:codemods && ../../node_modules/.bin/jest --config jest.config.js",
64
+ "test:jest:dev": "pnpm test:jest --watch"
65
65
  }
66
- }
66
+ }
@@ -84,6 +84,7 @@ describe('useInfiniteQuery', () => {
84
84
  isFetchingNextPage: false,
85
85
  isFetchingPreviousPage: false,
86
86
  isLoading: true,
87
+ isInitialLoading: true,
87
88
  isLoadingError: false,
88
89
  isPlaceholderData: false,
89
90
  isPreviousData: false,
@@ -116,6 +117,7 @@ describe('useInfiniteQuery', () => {
116
117
  isFetchingNextPage: false,
117
118
  isFetchingPreviousPage: false,
118
119
  isLoading: false,
120
+ isInitialLoading: false,
119
121
  isLoadingError: false,
120
122
  isPlaceholderData: false,
121
123
  isPreviousData: false,
@@ -880,34 +882,28 @@ describe('useInfiniteQuery', () => {
880
882
  const firstCtx = fetchPage.mock.calls[callIndex]![0]
881
883
  expect(firstCtx.pageParam).toBeUndefined()
882
884
  expect(firstCtx.queryKey).toEqual(key)
883
- if (typeof AbortSignal === 'function') {
884
- expect(firstCtx.signal).toBeInstanceOf(AbortSignal)
885
- expect(firstCtx.signal?.aborted).toBe(false)
886
- expect(onAborts[callIndex]).not.toHaveBeenCalled()
887
- expect(abortListeners[callIndex]).not.toHaveBeenCalled()
888
- }
885
+ expect(firstCtx.signal).toBeInstanceOf(AbortSignal)
886
+ expect(firstCtx.signal?.aborted).toBe(false)
887
+ expect(onAborts[callIndex]).not.toHaveBeenCalled()
888
+ expect(abortListeners[callIndex]).not.toHaveBeenCalled()
889
889
 
890
890
  callIndex = 1
891
891
  const secondCtx = fetchPage.mock.calls[callIndex]![0]
892
892
  expect(secondCtx.pageParam).toBe(11)
893
893
  expect(secondCtx.queryKey).toEqual(key)
894
- if (typeof AbortSignal === 'function') {
895
- expect(secondCtx.signal).toBeInstanceOf(AbortSignal)
896
- expect(secondCtx.signal?.aborted).toBe(true)
897
- expect(onAborts[callIndex]).toHaveBeenCalledTimes(1)
898
- expect(abortListeners[callIndex]).toHaveBeenCalledTimes(1)
899
- }
894
+ expect(secondCtx.signal).toBeInstanceOf(AbortSignal)
895
+ expect(secondCtx.signal?.aborted).toBe(true)
896
+ expect(onAborts[callIndex]).toHaveBeenCalledTimes(1)
897
+ expect(abortListeners[callIndex]).toHaveBeenCalledTimes(1)
900
898
 
901
899
  callIndex = 2
902
900
  const thirdCtx = fetchPage.mock.calls[callIndex]![0]
903
901
  expect(thirdCtx.pageParam).toBe(11)
904
902
  expect(thirdCtx.queryKey).toEqual(key)
905
- if (typeof AbortSignal === 'function') {
906
- expect(thirdCtx.signal).toBeInstanceOf(AbortSignal)
907
- expect(thirdCtx.signal?.aborted).toBe(false)
908
- expect(onAborts[callIndex]).not.toHaveBeenCalled()
909
- expect(abortListeners[callIndex]).not.toHaveBeenCalled()
910
- }
903
+ expect(thirdCtx.signal).toBeInstanceOf(AbortSignal)
904
+ expect(thirdCtx.signal?.aborted).toBe(false)
905
+ expect(onAborts[callIndex]).not.toHaveBeenCalled()
906
+ expect(abortListeners[callIndex]).not.toHaveBeenCalled()
911
907
  })
912
908
 
913
909
  it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used ', async () => {
@@ -961,23 +957,19 @@ describe('useInfiniteQuery', () => {
961
957
  const firstCtx = fetchPage.mock.calls[callIndex]![0]
962
958
  expect(firstCtx.pageParam).toBeUndefined()
963
959
  expect(firstCtx.queryKey).toEqual(key)
964
- if (typeof AbortSignal === 'function') {
965
- expect(firstCtx.signal).toBeInstanceOf(AbortSignal)
966
- expect(firstCtx.signal?.aborted).toBe(false)
967
- expect(onAborts[callIndex]).not.toHaveBeenCalled()
968
- expect(abortListeners[callIndex]).not.toHaveBeenCalled()
969
- }
960
+ expect(firstCtx.signal).toBeInstanceOf(AbortSignal)
961
+ expect(firstCtx.signal?.aborted).toBe(false)
962
+ expect(onAborts[callIndex]).not.toHaveBeenCalled()
963
+ expect(abortListeners[callIndex]).not.toHaveBeenCalled()
970
964
 
971
965
  callIndex = 1
972
966
  const secondCtx = fetchPage.mock.calls[callIndex]![0]
973
967
  expect(secondCtx.pageParam).toBe(11)
974
968
  expect(secondCtx.queryKey).toEqual(key)
975
- if (typeof AbortSignal === 'function') {
976
- expect(secondCtx.signal).toBeInstanceOf(AbortSignal)
977
- expect(secondCtx.signal?.aborted).toBe(false)
978
- expect(onAborts[callIndex]).not.toHaveBeenCalled()
979
- expect(abortListeners[callIndex]).not.toHaveBeenCalled()
980
- }
969
+ expect(secondCtx.signal).toBeInstanceOf(AbortSignal)
970
+ expect(secondCtx.signal?.aborted).toBe(false)
971
+ expect(onAborts[callIndex]).not.toHaveBeenCalled()
972
+ expect(abortListeners[callIndex]).not.toHaveBeenCalled()
981
973
  })
982
974
 
983
975
  it('should keep fetching first page when not loaded yet and triggering fetch more', async () => {
@@ -1073,22 +1065,12 @@ describe('useInfiniteQuery', () => {
1073
1065
 
1074
1066
  await sleep(300)
1075
1067
 
1076
- if (typeof AbortSignal === 'function') {
1077
- expect(fetches).toBe(2)
1078
- expect(queryClient.getQueryState(key)).toMatchObject({
1079
- data: initialData,
1080
- status: 'success',
1081
- error: null,
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
- }
1068
+ expect(fetches).toBe(2)
1069
+ expect(queryClient.getQueryState(key)).toMatchObject({
1070
+ data: initialData,
1071
+ status: 'success',
1072
+ error: null,
1073
+ })
1092
1074
  })
1093
1075
 
1094
1076
  it('should be able to override the cursor in the fetchNextPage callback', async () => {
@@ -1741,7 +1723,7 @@ describe('useInfiniteQuery', () => {
1741
1723
  const promise = new Promise<string>((resolve, reject) => {
1742
1724
  cancelFn = jest.fn(() => reject('Cancelled'))
1743
1725
  signal?.addEventListener('abort', cancelFn)
1744
- sleep(10).then(() => resolve('OK'))
1726
+ sleep(20).then(() => resolve('OK'))
1745
1727
  })
1746
1728
 
1747
1729
  return promise
@@ -1765,8 +1747,6 @@ describe('useInfiniteQuery', () => {
1765
1747
 
1766
1748
  await waitFor(() => rendered.getByText('off'))
1767
1749
 
1768
- if (typeof AbortSignal === 'function') {
1769
- expect(cancelFn).toHaveBeenCalled()
1770
- }
1750
+ expect(cancelFn).toHaveBeenCalled()
1771
1751
  })
1772
1752
  })
@@ -240,6 +240,7 @@ describe('useQuery', () => {
240
240
  isFetching: true,
241
241
  isPaused: false,
242
242
  isLoading: true,
243
+ isInitialLoading: true,
243
244
  isLoadingError: false,
244
245
  isPlaceholderData: false,
245
246
  isPreviousData: false,
@@ -266,6 +267,7 @@ describe('useQuery', () => {
266
267
  isFetching: false,
267
268
  isPaused: false,
268
269
  isLoading: false,
270
+ isInitialLoading: false,
269
271
  isLoadingError: false,
270
272
  isPlaceholderData: false,
271
273
  isPreviousData: false,
@@ -322,6 +324,7 @@ describe('useQuery', () => {
322
324
  isFetching: true,
323
325
  isPaused: false,
324
326
  isLoading: true,
327
+ isInitialLoading: true,
325
328
  isLoadingError: false,
326
329
  isPlaceholderData: false,
327
330
  isPreviousData: false,
@@ -348,6 +351,7 @@ describe('useQuery', () => {
348
351
  isFetching: true,
349
352
  isPaused: false,
350
353
  isLoading: true,
354
+ isInitialLoading: true,
351
355
  isLoadingError: false,
352
356
  isPlaceholderData: false,
353
357
  isPreviousData: false,
@@ -374,6 +378,7 @@ describe('useQuery', () => {
374
378
  isFetching: false,
375
379
  isPaused: false,
376
380
  isLoading: false,
381
+ isInitialLoading: false,
377
382
  isLoadingError: true,
378
383
  isPlaceholderData: false,
379
384
  isPreviousData: false,
@@ -4328,7 +4333,7 @@ describe('useQuery', () => {
4328
4333
  const promise = new Promise<string>((resolve, reject) => {
4329
4334
  cancelFn = jest.fn(() => reject('Cancelled'))
4330
4335
  signal?.addEventListener('abort', cancelFn)
4331
- sleep(10).then(() => resolve('OK'))
4336
+ sleep(20).then(() => resolve('OK'))
4332
4337
  })
4333
4338
 
4334
4339
  return promise
@@ -4352,9 +4357,7 @@ describe('useQuery', () => {
4352
4357
 
4353
4358
  await waitFor(() => rendered.getByText('off'))
4354
4359
 
4355
- if (typeof AbortSignal === 'function') {
4356
- expect(cancelFn).toHaveBeenCalled()
4357
- }
4360
+ expect(cancelFn).toHaveBeenCalled()
4358
4361
  })
4359
4362
 
4360
4363
  it('should cancel the query if the signal was consumed and there are no more subscriptions', async () => {
@@ -4402,19 +4405,11 @@ describe('useQuery', () => {
4402
4405
  dataUpdateCount: 1,
4403
4406
  })
4404
4407
 
4405
- if (typeof AbortSignal === 'function') {
4406
- expect(queryCache.find([key, 1])?.state).toMatchObject({
4407
- data: undefined,
4408
- status: 'loading',
4409
- fetchStatus: 'idle',
4410
- })
4411
- } else {
4412
- expect(queryCache.find([key, 1])?.state).toMatchObject({
4413
- data: 'data 1',
4414
- status: 'success',
4415
- dataUpdateCount: 1,
4416
- })
4417
- }
4408
+ expect(queryCache.find([key, 1])?.state).toMatchObject({
4409
+ data: undefined,
4410
+ status: 'loading',
4411
+ fetchStatus: 'idle',
4412
+ })
4418
4413
 
4419
4414
  expect(queryCache.find([key, 2])?.state).toMatchObject({
4420
4415
  data: 'data 2',
@@ -4422,19 +4417,11 @@ describe('useQuery', () => {
4422
4417
  dataUpdateCount: 1,
4423
4418
  })
4424
4419
 
4425
- if (typeof AbortSignal === 'function') {
4426
- expect(queryCache.find([key, 3])?.state).toMatchObject({
4427
- data: undefined,
4428
- status: 'loading',
4429
- fetchStatus: 'idle',
4430
- })
4431
- } else {
4432
- expect(queryCache.find([key, 3])?.state).toMatchObject({
4433
- data: 'data 3',
4434
- status: 'success',
4435
- dataUpdateCount: 1,
4436
- })
4437
- }
4420
+ expect(queryCache.find([key, 3])?.state).toMatchObject({
4421
+ data: undefined,
4422
+ status: 'loading',
4423
+ fetchStatus: 'idle',
4424
+ })
4438
4425
  })
4439
4426
 
4440
4427
  it('should refetch when quickly switching to a failed query', async () => {
@@ -5486,7 +5473,7 @@ describe('useQuery', () => {
5486
5473
  status: 'success',
5487
5474
  })
5488
5475
 
5489
- expect(count).toBe(typeof AbortSignal === 'function' ? 1 : 2)
5476
+ expect(count).toBe(1)
5490
5477
 
5491
5478
  onlineMock.mockRestore()
5492
5479
  })