@tanstack/react-query 5.0.0-alpha.21 → 5.0.0-alpha.23
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/build/lib/errorBoundaryUtils.d.ts +3 -3
- package/build/lib/errorBoundaryUtils.esm.js +3 -3
- package/build/lib/errorBoundaryUtils.esm.js.map +1 -1
- package/build/lib/errorBoundaryUtils.js +3 -3
- package/build/lib/errorBoundaryUtils.js.map +1 -1
- package/build/lib/errorBoundaryUtils.mjs +3 -3
- package/build/lib/errorBoundaryUtils.mjs.map +1 -1
- package/build/lib/useBaseQuery.esm.js +1 -1
- package/build/lib/useBaseQuery.esm.js.map +1 -1
- package/build/lib/useBaseQuery.js +1 -1
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.mjs +1 -1
- package/build/lib/useBaseQuery.mjs.map +1 -1
- package/build/lib/useMutation.esm.js +1 -1
- package/build/lib/useMutation.esm.js.map +1 -1
- package/build/lib/useMutation.js +1 -1
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.mjs +1 -1
- package/build/lib/useMutation.mjs.map +1 -1
- package/build/lib/useQueries.esm.js +1 -1
- package/build/lib/useQueries.esm.js.map +1 -1
- package/build/lib/useQueries.js +1 -1
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.mjs +1 -1
- package/build/lib/useQueries.mjs.map +1 -1
- package/build/umd/index.development.js +10 -10
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +11 -11
- package/src/__tests__/suspense.test.tsx +6 -6
- package/src/__tests__/useMutation.test.tsx +4 -4
- package/src/__tests__/useQueries.test.tsx +9 -9
- package/src/__tests__/useQuery.test.tsx +6 -6
- package/src/errorBoundaryUtils.ts +5 -5
- package/src/useBaseQuery.ts +1 -1
- package/src/useMutation.ts +1 -1
- package/src/useQueries.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.23",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"react-error-boundary": "^3.1.4"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tanstack/query-core": "5.0.0-alpha.
|
|
38
|
+
"@tanstack/query-core": "5.0.0-alpha.23"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": "^18.0.0",
|
|
@@ -38,7 +38,7 @@ describe('QueryErrorResetBoundary', () => {
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
retry: false,
|
|
41
|
-
|
|
41
|
+
throwOnError: true,
|
|
42
42
|
})
|
|
43
43
|
return <div>{data}</div>
|
|
44
44
|
}
|
|
@@ -97,7 +97,7 @@ describe('QueryErrorResetBoundary', () => {
|
|
|
97
97
|
},
|
|
98
98
|
retry: false,
|
|
99
99
|
enabled: !succeed,
|
|
100
|
-
|
|
100
|
+
throwOnError: true,
|
|
101
101
|
})
|
|
102
102
|
return (
|
|
103
103
|
<div>
|
|
@@ -163,7 +163,7 @@ describe('QueryErrorResetBoundary', () => {
|
|
|
163
163
|
},
|
|
164
164
|
retry: false,
|
|
165
165
|
enabled,
|
|
166
|
-
|
|
166
|
+
throwOnError: true,
|
|
167
167
|
})
|
|
168
168
|
|
|
169
169
|
React.useEffect(() => {
|
|
@@ -221,7 +221,7 @@ describe('QueryErrorResetBoundary', () => {
|
|
|
221
221
|
},
|
|
222
222
|
retry: false,
|
|
223
223
|
enabled: false,
|
|
224
|
-
|
|
224
|
+
throwOnError: true,
|
|
225
225
|
})
|
|
226
226
|
|
|
227
227
|
return (
|
|
@@ -289,7 +289,7 @@ describe('QueryErrorResetBoundary', () => {
|
|
|
289
289
|
}
|
|
290
290
|
},
|
|
291
291
|
retry: false,
|
|
292
|
-
|
|
292
|
+
throwOnError: true,
|
|
293
293
|
})
|
|
294
294
|
return <div>{data}</div>
|
|
295
295
|
}
|
|
@@ -347,7 +347,7 @@ describe('QueryErrorResetBoundary', () => {
|
|
|
347
347
|
}
|
|
348
348
|
},
|
|
349
349
|
retry: false,
|
|
350
|
-
|
|
350
|
+
throwOnError: true,
|
|
351
351
|
initialData: 'initial',
|
|
352
352
|
})
|
|
353
353
|
return <div>{data}</div>
|
|
@@ -408,7 +408,7 @@ describe('QueryErrorResetBoundary', () => {
|
|
|
408
408
|
}
|
|
409
409
|
},
|
|
410
410
|
retry: false,
|
|
411
|
-
|
|
411
|
+
throwOnError: true,
|
|
412
412
|
})
|
|
413
413
|
return <div>{data}</div>
|
|
414
414
|
}
|
|
@@ -471,7 +471,7 @@ describe('QueryErrorResetBoundary', () => {
|
|
|
471
471
|
throw new Error('Error')
|
|
472
472
|
},
|
|
473
473
|
retry: false,
|
|
474
|
-
|
|
474
|
+
throwOnError: true,
|
|
475
475
|
})
|
|
476
476
|
return <div>{data}</div>
|
|
477
477
|
}
|
|
@@ -624,7 +624,7 @@ describe('QueryErrorResetBoundary', () => {
|
|
|
624
624
|
}
|
|
625
625
|
},
|
|
626
626
|
retry: false,
|
|
627
|
-
|
|
627
|
+
throwOnError: true,
|
|
628
628
|
})
|
|
629
629
|
return <div>{data}</div>
|
|
630
630
|
}
|
|
@@ -685,7 +685,7 @@ describe('QueryErrorResetBoundary', () => {
|
|
|
685
685
|
}
|
|
686
686
|
},
|
|
687
687
|
retry: false,
|
|
688
|
-
|
|
688
|
+
throwOnError: true,
|
|
689
689
|
retryOnMount: true,
|
|
690
690
|
},
|
|
691
691
|
],
|
|
@@ -748,7 +748,7 @@ describe('QueryErrorResetBoundary', () => {
|
|
|
748
748
|
}
|
|
749
749
|
},
|
|
750
750
|
retry: false,
|
|
751
|
-
|
|
751
|
+
throwOnError: true,
|
|
752
752
|
retryOnMount: true,
|
|
753
753
|
suspense: true,
|
|
754
754
|
},
|
|
@@ -534,7 +534,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
534
534
|
consoleMock.mockRestore()
|
|
535
535
|
})
|
|
536
536
|
|
|
537
|
-
it('should not throw errors to the error boundary when
|
|
537
|
+
it('should not throw errors to the error boundary when throwOnError: false', async () => {
|
|
538
538
|
const key = queryKey()
|
|
539
539
|
|
|
540
540
|
function Page() {
|
|
@@ -546,7 +546,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
546
546
|
},
|
|
547
547
|
retry: false,
|
|
548
548
|
suspense: true,
|
|
549
|
-
|
|
549
|
+
throwOnError: false,
|
|
550
550
|
})
|
|
551
551
|
return <div>rendered</div>
|
|
552
552
|
}
|
|
@@ -573,7 +573,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
573
573
|
await waitFor(() => rendered.getByText('rendered'))
|
|
574
574
|
})
|
|
575
575
|
|
|
576
|
-
it('should throw errors to the error boundary when a
|
|
576
|
+
it('should throw errors to the error boundary when a throwOnError function returns true', async () => {
|
|
577
577
|
const consoleMock = vi
|
|
578
578
|
.spyOn(console, 'error')
|
|
579
579
|
.mockImplementation(() => undefined)
|
|
@@ -588,7 +588,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
588
588
|
},
|
|
589
589
|
retry: false,
|
|
590
590
|
suspense: true,
|
|
591
|
-
|
|
591
|
+
throwOnError: (err) => err.message !== 'Local Error',
|
|
592
592
|
})
|
|
593
593
|
return <div>rendered</div>
|
|
594
594
|
}
|
|
@@ -616,7 +616,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
616
616
|
consoleMock.mockRestore()
|
|
617
617
|
})
|
|
618
618
|
|
|
619
|
-
it('should not throw errors to the error boundary when a
|
|
619
|
+
it('should not throw errors to the error boundary when a throwOnError function returns false', async () => {
|
|
620
620
|
const key = queryKey()
|
|
621
621
|
|
|
622
622
|
function Page() {
|
|
@@ -628,7 +628,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
628
628
|
},
|
|
629
629
|
retry: false,
|
|
630
630
|
suspense: true,
|
|
631
|
-
|
|
631
|
+
throwOnError: (err) => err.message !== 'Local Error',
|
|
632
632
|
})
|
|
633
633
|
return <div>rendered</div>
|
|
634
634
|
}
|
|
@@ -688,7 +688,7 @@ describe('useMutation', () => {
|
|
|
688
688
|
fireEvent.click(getByText('unmount'))
|
|
689
689
|
})
|
|
690
690
|
|
|
691
|
-
it('should be able to throw an error when
|
|
691
|
+
it('should be able to throw an error when throwOnError is set to true', async () => {
|
|
692
692
|
const consoleMock = vi
|
|
693
693
|
.spyOn(console, 'error')
|
|
694
694
|
.mockImplementation(() => undefined)
|
|
@@ -699,7 +699,7 @@ describe('useMutation', () => {
|
|
|
699
699
|
err.stack = ''
|
|
700
700
|
return Promise.reject(err)
|
|
701
701
|
},
|
|
702
|
-
|
|
702
|
+
throwOnError: true,
|
|
703
703
|
})
|
|
704
704
|
|
|
705
705
|
return (
|
|
@@ -735,7 +735,7 @@ describe('useMutation', () => {
|
|
|
735
735
|
consoleMock.mockRestore()
|
|
736
736
|
})
|
|
737
737
|
|
|
738
|
-
it('should be able to throw an error when
|
|
738
|
+
it('should be able to throw an error when throwOnError is a function that returns true', async () => {
|
|
739
739
|
const consoleMock = vi
|
|
740
740
|
.spyOn(console, 'error')
|
|
741
741
|
.mockImplementation(() => undefined)
|
|
@@ -747,7 +747,7 @@ describe('useMutation', () => {
|
|
|
747
747
|
err.stack = ''
|
|
748
748
|
return Promise.reject(err)
|
|
749
749
|
},
|
|
750
|
-
|
|
750
|
+
throwOnError: () => {
|
|
751
751
|
boundary = !boundary
|
|
752
752
|
return !boundary
|
|
753
753
|
},
|
|
@@ -644,7 +644,7 @@ describe('useQueries', () => {
|
|
|
644
644
|
}
|
|
645
645
|
})
|
|
646
646
|
|
|
647
|
-
it("should throw error if in one of queries' queryFn throws and
|
|
647
|
+
it("should throw error if in one of queries' queryFn throws and throwOnError is in use", async () => {
|
|
648
648
|
const consoleMock = vi
|
|
649
649
|
.spyOn(console, 'error')
|
|
650
650
|
.mockImplementation(() => undefined)
|
|
@@ -661,14 +661,14 @@ describe('useQueries', () => {
|
|
|
661
661
|
queryFn: () =>
|
|
662
662
|
Promise.reject(
|
|
663
663
|
new Error(
|
|
664
|
-
'this should not throw because
|
|
664
|
+
'this should not throw because throwOnError is not set',
|
|
665
665
|
),
|
|
666
666
|
),
|
|
667
667
|
},
|
|
668
668
|
{
|
|
669
669
|
queryKey: key2,
|
|
670
670
|
queryFn: () => Promise.reject(new Error('single query error')),
|
|
671
|
-
|
|
671
|
+
throwOnError: true,
|
|
672
672
|
retry: false,
|
|
673
673
|
},
|
|
674
674
|
{
|
|
@@ -681,7 +681,7 @@ describe('useQueries', () => {
|
|
|
681
681
|
Promise.reject(
|
|
682
682
|
new Error('this should not throw because query#2 already did'),
|
|
683
683
|
),
|
|
684
|
-
|
|
684
|
+
throwOnError: true,
|
|
685
685
|
retry: false,
|
|
686
686
|
},
|
|
687
687
|
],
|
|
@@ -709,7 +709,7 @@ describe('useQueries', () => {
|
|
|
709
709
|
consoleMock.mockRestore()
|
|
710
710
|
})
|
|
711
711
|
|
|
712
|
-
it("should throw error if in one of queries' queryFn throws and
|
|
712
|
+
it("should throw error if in one of queries' queryFn throws and throwOnError function resolves to true", async () => {
|
|
713
713
|
const consoleMock = vi
|
|
714
714
|
.spyOn(console, 'error')
|
|
715
715
|
.mockImplementation(() => undefined)
|
|
@@ -726,10 +726,10 @@ describe('useQueries', () => {
|
|
|
726
726
|
queryFn: () =>
|
|
727
727
|
Promise.reject(
|
|
728
728
|
new Error(
|
|
729
|
-
'this should not throw because
|
|
729
|
+
'this should not throw because throwOnError function resolves to false',
|
|
730
730
|
),
|
|
731
731
|
),
|
|
732
|
-
|
|
732
|
+
throwOnError: () => false,
|
|
733
733
|
retry: false,
|
|
734
734
|
},
|
|
735
735
|
{
|
|
@@ -739,7 +739,7 @@ describe('useQueries', () => {
|
|
|
739
739
|
{
|
|
740
740
|
queryKey: key3,
|
|
741
741
|
queryFn: () => Promise.reject(new Error('single query error')),
|
|
742
|
-
|
|
742
|
+
throwOnError: () => true,
|
|
743
743
|
retry: false,
|
|
744
744
|
},
|
|
745
745
|
{
|
|
@@ -748,7 +748,7 @@ describe('useQueries', () => {
|
|
|
748
748
|
Promise.reject(
|
|
749
749
|
new Error('this should not throw because query#3 already did'),
|
|
750
750
|
),
|
|
751
|
-
|
|
751
|
+
throwOnError: true,
|
|
752
752
|
retry: false,
|
|
753
753
|
},
|
|
754
754
|
],
|
|
@@ -2747,7 +2747,7 @@ describe('useQuery', () => {
|
|
|
2747
2747
|
await waitFor(() => rendered.getByText('Error test jaylen'))
|
|
2748
2748
|
})
|
|
2749
2749
|
|
|
2750
|
-
it('should throw error if queryFn throws and
|
|
2750
|
+
it('should throw error if queryFn throws and throwOnError is in use', async () => {
|
|
2751
2751
|
const consoleMock = vi
|
|
2752
2752
|
.spyOn(console, 'error')
|
|
2753
2753
|
.mockImplementation(() => undefined)
|
|
@@ -2758,7 +2758,7 @@ describe('useQuery', () => {
|
|
|
2758
2758
|
queryKey: key,
|
|
2759
2759
|
queryFn: () => Promise.reject(new Error('Error test jaylen')),
|
|
2760
2760
|
retry: false,
|
|
2761
|
-
|
|
2761
|
+
throwOnError: true,
|
|
2762
2762
|
})
|
|
2763
2763
|
|
|
2764
2764
|
return (
|
|
@@ -2780,7 +2780,7 @@ describe('useQuery', () => {
|
|
|
2780
2780
|
consoleMock.mockRestore()
|
|
2781
2781
|
})
|
|
2782
2782
|
|
|
2783
|
-
it('should update with data if we observe no properties and
|
|
2783
|
+
it('should update with data if we observe no properties and throwOnError', async () => {
|
|
2784
2784
|
const key = queryKey()
|
|
2785
2785
|
|
|
2786
2786
|
let result: UseQueryResult<string> | undefined
|
|
@@ -2789,7 +2789,7 @@ describe('useQuery', () => {
|
|
|
2789
2789
|
const query = useQuery({
|
|
2790
2790
|
queryKey: key,
|
|
2791
2791
|
queryFn: () => Promise.resolve('data'),
|
|
2792
|
-
|
|
2792
|
+
throwOnError: true,
|
|
2793
2793
|
})
|
|
2794
2794
|
|
|
2795
2795
|
React.useEffect(() => {
|
|
@@ -2817,7 +2817,7 @@ describe('useQuery', () => {
|
|
|
2817
2817
|
queryFn: () => Promise.reject(new Error('Local Error')),
|
|
2818
2818
|
|
|
2819
2819
|
retry: false,
|
|
2820
|
-
|
|
2820
|
+
throwOnError: (err) => err.message !== 'Local Error',
|
|
2821
2821
|
})
|
|
2822
2822
|
|
|
2823
2823
|
return (
|
|
@@ -2852,7 +2852,7 @@ describe('useQuery', () => {
|
|
|
2852
2852
|
queryFn: () => Promise.reject(new Error('Remote Error')),
|
|
2853
2853
|
|
|
2854
2854
|
retry: false,
|
|
2855
|
-
|
|
2855
|
+
throwOnError: (err) => err.message !== 'Local Error',
|
|
2856
2856
|
})
|
|
2857
2857
|
|
|
2858
2858
|
return (
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
Query,
|
|
5
5
|
QueryKey,
|
|
6
6
|
QueryObserverResult,
|
|
7
|
-
|
|
7
|
+
ThrowOnError,
|
|
8
8
|
} from '@tanstack/query-core'
|
|
9
9
|
import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
|
|
10
10
|
import * as React from 'react'
|
|
@@ -26,7 +26,7 @@ export const ensurePreventErrorBoundaryRetry = <
|
|
|
26
26
|
>,
|
|
27
27
|
errorResetBoundary: QueryErrorResetBoundaryValue,
|
|
28
28
|
) => {
|
|
29
|
-
if (options.suspense || options.
|
|
29
|
+
if (options.suspense || options.throwOnError) {
|
|
30
30
|
// Prevent retrying failed query if the error boundary has not been reset yet
|
|
31
31
|
if (!errorResetBoundary.isReset()) {
|
|
32
32
|
options.retryOnMount = false
|
|
@@ -51,18 +51,18 @@ export const getHasError = <
|
|
|
51
51
|
>({
|
|
52
52
|
result,
|
|
53
53
|
errorResetBoundary,
|
|
54
|
-
|
|
54
|
+
throwOnError,
|
|
55
55
|
query,
|
|
56
56
|
}: {
|
|
57
57
|
result: QueryObserverResult<TData, TError>
|
|
58
58
|
errorResetBoundary: QueryErrorResetBoundaryValue
|
|
59
|
-
|
|
59
|
+
throwOnError: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
60
60
|
query: Query<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
61
61
|
}) => {
|
|
62
62
|
return (
|
|
63
63
|
result.isError &&
|
|
64
64
|
!errorResetBoundary.isReset() &&
|
|
65
65
|
!result.isFetching &&
|
|
66
|
-
shouldThrowError(
|
|
66
|
+
shouldThrowError(throwOnError, [result.error, query])
|
|
67
67
|
)
|
|
68
68
|
}
|
package/src/useBaseQuery.ts
CHANGED
package/src/useMutation.ts
CHANGED
package/src/useQueries.ts
CHANGED
|
@@ -243,7 +243,7 @@ export function useQueries<T extends any[]>(
|
|
|
243
243
|
getHasError({
|
|
244
244
|
result,
|
|
245
245
|
errorResetBoundary,
|
|
246
|
-
|
|
246
|
+
throwOnError: defaultedQueries[index]?.throwOnError ?? false,
|
|
247
247
|
query: observerQueries[index]!,
|
|
248
248
|
}),
|
|
249
249
|
)
|