@tanstack/solid-query 5.0.0-beta.18 → 5.0.0-beta.21
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/dev.cjs +176 -80
- package/build/dev.js +178 -82
- package/build/index.cjs +176 -80
- package/build/index.d.cts +9 -5
- package/build/index.d.ts +9 -5
- package/build/index.js +178 -82
- package/package.json +2 -2
- package/src/QueryClientProvider.tsx +14 -7
- package/src/__tests__/createInfiniteQuery.test.tsx +36 -29
- package/src/__tests__/createMutation.test.tsx +4 -4
- package/src/__tests__/createQueries.test.tsx +31 -29
- package/src/__tests__/createQuery.test.tsx +81 -86
- package/src/__tests__/suspense.test.tsx +4 -4
- package/src/__tests__/transition.test.tsx +1 -2
- package/src/__tests__/useIsFetching.test.tsx +2 -2
- package/src/__tests__/useIsMutating.test.tsx +3 -3
- package/src/__tests__/utils.tsx +1 -1
- package/src/createBaseQuery.ts +95 -61
- package/src/createMutation.ts +3 -3
- package/src/createQueries.ts +156 -52
- package/src/index.ts +1 -0
- package/src/isRestoring.ts +6 -0
- package/src/utils.ts +1 -1
|
@@ -227,7 +227,7 @@ describe('createQuery', () => {
|
|
|
227
227
|
|
|
228
228
|
it('should return the correct states for a successful query', async () => {
|
|
229
229
|
const key = queryKey()
|
|
230
|
-
const states: CreateQueryResult<string
|
|
230
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
231
231
|
|
|
232
232
|
function Page(): JSX.Element {
|
|
233
233
|
const state = createQuery<string, Error>(() => ({
|
|
@@ -333,7 +333,7 @@ describe('createQuery', () => {
|
|
|
333
333
|
it('should return the correct states for an unsuccessful query', async () => {
|
|
334
334
|
const key = queryKey()
|
|
335
335
|
|
|
336
|
-
const states: CreateQueryResult<unknown, Error
|
|
336
|
+
const states: Array<CreateQueryResult<unknown, Error>> = []
|
|
337
337
|
|
|
338
338
|
function Page() {
|
|
339
339
|
const state = createQuery(() => ({
|
|
@@ -448,7 +448,7 @@ describe('createQuery', () => {
|
|
|
448
448
|
|
|
449
449
|
it('should set isFetchedAfterMount to true after a query has been fetched', async () => {
|
|
450
450
|
const key = queryKey()
|
|
451
|
-
const states: CreateQueryResult<string
|
|
451
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
452
452
|
|
|
453
453
|
await queryClient.prefetchQuery({
|
|
454
454
|
queryKey: key,
|
|
@@ -605,7 +605,7 @@ describe('createQuery', () => {
|
|
|
605
605
|
|
|
606
606
|
it('should be able to watch a query without providing a query function', async () => {
|
|
607
607
|
const key = queryKey()
|
|
608
|
-
const states: CreateQueryResult<string
|
|
608
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
609
609
|
|
|
610
610
|
queryClient.setQueryDefaults(key, { queryFn: () => 'data' })
|
|
611
611
|
|
|
@@ -632,7 +632,7 @@ describe('createQuery', () => {
|
|
|
632
632
|
|
|
633
633
|
it('should pick up a query when re-mounting with gcTime 0', async () => {
|
|
634
634
|
const key = queryKey()
|
|
635
|
-
const states: CreateQueryResult<string
|
|
635
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
636
636
|
|
|
637
637
|
function Page() {
|
|
638
638
|
const [toggle, setToggle] = createSignal(false)
|
|
@@ -712,7 +712,7 @@ describe('createQuery', () => {
|
|
|
712
712
|
|
|
713
713
|
it('should fetch when refetchOnMount is false and nothing has been fetched yet', async () => {
|
|
714
714
|
const key = queryKey()
|
|
715
|
-
const states: CreateQueryResult<string
|
|
715
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
716
716
|
|
|
717
717
|
function Page() {
|
|
718
718
|
const state = createQuery(() => ({
|
|
@@ -741,7 +741,7 @@ describe('createQuery', () => {
|
|
|
741
741
|
|
|
742
742
|
it('should not fetch when refetchOnMount is false and data has been fetched already', async () => {
|
|
743
743
|
const key = queryKey()
|
|
744
|
-
const states: CreateQueryResult<string
|
|
744
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
745
745
|
|
|
746
746
|
queryClient.setQueryData(key, 'prefetched')
|
|
747
747
|
|
|
@@ -771,7 +771,7 @@ describe('createQuery', () => {
|
|
|
771
771
|
|
|
772
772
|
it('should be able to select a part of the data with select', async () => {
|
|
773
773
|
const key = queryKey()
|
|
774
|
-
const states: CreateQueryResult<string
|
|
774
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
775
775
|
|
|
776
776
|
function Page() {
|
|
777
777
|
const state = createQuery(() => ({
|
|
@@ -800,7 +800,7 @@ describe('createQuery', () => {
|
|
|
800
800
|
|
|
801
801
|
it('should be able to select a part of the data with select in object syntax', async () => {
|
|
802
802
|
const key = queryKey()
|
|
803
|
-
const states: CreateQueryResult<string
|
|
803
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
804
804
|
|
|
805
805
|
function Page() {
|
|
806
806
|
const state = createQuery(() => ({
|
|
@@ -829,7 +829,7 @@ describe('createQuery', () => {
|
|
|
829
829
|
|
|
830
830
|
it('should be able to select a part of the data with select in object syntax', async () => {
|
|
831
831
|
const key = queryKey()
|
|
832
|
-
const states: CreateQueryResult<string
|
|
832
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
833
833
|
|
|
834
834
|
function Page() {
|
|
835
835
|
const state = createQuery(() => ({
|
|
@@ -858,7 +858,7 @@ describe('createQuery', () => {
|
|
|
858
858
|
|
|
859
859
|
it('should not re-render when it should only re-render only data change and the selected data did not change', async () => {
|
|
860
860
|
const key = queryKey()
|
|
861
|
-
const states: CreateQueryResult<string
|
|
861
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
862
862
|
|
|
863
863
|
function Page() {
|
|
864
864
|
const state = createQuery(() => ({
|
|
@@ -898,7 +898,7 @@ describe('createQuery', () => {
|
|
|
898
898
|
|
|
899
899
|
it('should throw an error when a selector throws', async () => {
|
|
900
900
|
const key = queryKey()
|
|
901
|
-
const states:
|
|
901
|
+
const states: Array<{ status: string; data?: unknown; error?: Error }> = []
|
|
902
902
|
const error = new Error('Select Error')
|
|
903
903
|
|
|
904
904
|
function Page() {
|
|
@@ -910,7 +910,10 @@ describe('createQuery', () => {
|
|
|
910
910
|
},
|
|
911
911
|
}))
|
|
912
912
|
createRenderEffect(() => {
|
|
913
|
-
|
|
913
|
+
if (state.status === 'pending')
|
|
914
|
+
states.push({ status: 'pending', data: undefined })
|
|
915
|
+
else if (state.status === 'error')
|
|
916
|
+
states.push({ status: 'error', error: state.error })
|
|
914
917
|
})
|
|
915
918
|
return null
|
|
916
919
|
}
|
|
@@ -931,7 +934,7 @@ describe('createQuery', () => {
|
|
|
931
934
|
|
|
932
935
|
it('should track properties and only re-render when a tracked property changes', async () => {
|
|
933
936
|
const key = queryKey()
|
|
934
|
-
const states: CreateQueryResult<string
|
|
937
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
935
938
|
|
|
936
939
|
function Page() {
|
|
937
940
|
const state = createQuery(() => ({
|
|
@@ -979,7 +982,7 @@ describe('createQuery', () => {
|
|
|
979
982
|
it('should always re-render if we are tracking props but not using any', async () => {
|
|
980
983
|
const key = queryKey()
|
|
981
984
|
let renderCount = 0
|
|
982
|
-
const states: CreateQueryResult<string
|
|
985
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
983
986
|
|
|
984
987
|
function Page() {
|
|
985
988
|
const state = createQuery(() => ({
|
|
@@ -1032,7 +1035,7 @@ describe('createQuery', () => {
|
|
|
1032
1035
|
{ id: '2', done: true },
|
|
1033
1036
|
]
|
|
1034
1037
|
|
|
1035
|
-
const states: CreateQueryResult<typeof result1
|
|
1038
|
+
const states: Array<CreateQueryResult<typeof result1>> = []
|
|
1036
1039
|
|
|
1037
1040
|
let count = 0
|
|
1038
1041
|
|
|
@@ -1091,7 +1094,7 @@ describe('createQuery', () => {
|
|
|
1091
1094
|
|
|
1092
1095
|
it('should use query function from hook when the existing query does not have a query function', async () => {
|
|
1093
1096
|
const key = queryKey()
|
|
1094
|
-
const results: CreateQueryResult<string
|
|
1097
|
+
const results: Array<CreateQueryResult<string>> = []
|
|
1095
1098
|
|
|
1096
1099
|
queryClient.setQueryData(key, 'set')
|
|
1097
1100
|
|
|
@@ -1140,7 +1143,7 @@ describe('createQuery', () => {
|
|
|
1140
1143
|
|
|
1141
1144
|
it('should update query stale state and refetch when invalidated with invalidateQueries', async () => {
|
|
1142
1145
|
const key = queryKey()
|
|
1143
|
-
const states: CreateQueryResult<number
|
|
1146
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1144
1147
|
let count = 0
|
|
1145
1148
|
|
|
1146
1149
|
function Page() {
|
|
@@ -1214,7 +1217,7 @@ describe('createQuery', () => {
|
|
|
1214
1217
|
|
|
1215
1218
|
it('should not update disabled query when refetched with refetchQueries', async () => {
|
|
1216
1219
|
const key = queryKey()
|
|
1217
|
-
const states: CreateQueryResult<number
|
|
1220
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1218
1221
|
let count = 0
|
|
1219
1222
|
|
|
1220
1223
|
function Page() {
|
|
@@ -1260,7 +1263,7 @@ describe('createQuery', () => {
|
|
|
1260
1263
|
|
|
1261
1264
|
it('should not refetch disabled query when invalidated with invalidateQueries', async () => {
|
|
1262
1265
|
const key = queryKey()
|
|
1263
|
-
const states: CreateQueryResult<number
|
|
1266
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1264
1267
|
let count = 0
|
|
1265
1268
|
|
|
1266
1269
|
function Page() {
|
|
@@ -1306,7 +1309,7 @@ describe('createQuery', () => {
|
|
|
1306
1309
|
|
|
1307
1310
|
it('should not fetch when switching to a disabled query', async () => {
|
|
1308
1311
|
const key = queryKey()
|
|
1309
|
-
const states: CreateQueryResult<number
|
|
1312
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1310
1313
|
|
|
1311
1314
|
function Page() {
|
|
1312
1315
|
const [count, setCount] = createSignal(0)
|
|
@@ -1363,7 +1366,7 @@ describe('createQuery', () => {
|
|
|
1363
1366
|
|
|
1364
1367
|
it('should keep the previous data when placeholderData is set', async () => {
|
|
1365
1368
|
const key = queryKey()
|
|
1366
|
-
const states: CreateQueryResult<number
|
|
1369
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1367
1370
|
|
|
1368
1371
|
function Page() {
|
|
1369
1372
|
const [count, setCount] = createSignal(0)
|
|
@@ -1430,7 +1433,7 @@ describe('createQuery', () => {
|
|
|
1430
1433
|
|
|
1431
1434
|
it('should not show initial data from next query if placeholderData is set', async () => {
|
|
1432
1435
|
const key = queryKey()
|
|
1433
|
-
const states: DefinedCreateQueryResult<number
|
|
1436
|
+
const states: Array<DefinedCreateQueryResult<number>> = []
|
|
1434
1437
|
|
|
1435
1438
|
function Page() {
|
|
1436
1439
|
const [count, setCount] = createSignal(0)
|
|
@@ -1510,7 +1513,7 @@ describe('createQuery', () => {
|
|
|
1510
1513
|
|
|
1511
1514
|
it('should keep the previous data on disabled query when placeholderData is set to identity function', async () => {
|
|
1512
1515
|
const key = queryKey()
|
|
1513
|
-
const states: CreateQueryResult<number
|
|
1516
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1514
1517
|
|
|
1515
1518
|
function Page() {
|
|
1516
1519
|
const [count, setCount] = createSignal(0)
|
|
@@ -1602,7 +1605,7 @@ describe('createQuery', () => {
|
|
|
1602
1605
|
|
|
1603
1606
|
it('should keep the previous data on disabled query when placeholderData is set and switching query key multiple times', async () => {
|
|
1604
1607
|
const key = queryKey()
|
|
1605
|
-
const states: CreateQueryResult<number
|
|
1608
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1606
1609
|
|
|
1607
1610
|
queryClient.setQueryData([key, 10], 10)
|
|
1608
1611
|
|
|
@@ -1684,7 +1687,7 @@ describe('createQuery', () => {
|
|
|
1684
1687
|
|
|
1685
1688
|
it('should use the correct query function when components use different configurations', async () => {
|
|
1686
1689
|
const key = queryKey()
|
|
1687
|
-
const states: CreateQueryResult<number
|
|
1690
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1688
1691
|
|
|
1689
1692
|
function FirstComponent() {
|
|
1690
1693
|
const state = createQuery(() => ({
|
|
@@ -1752,8 +1755,8 @@ describe('createQuery', () => {
|
|
|
1752
1755
|
|
|
1753
1756
|
it('should be able to set different stale times for a query', async () => {
|
|
1754
1757
|
const key = queryKey()
|
|
1755
|
-
const states1: CreateQueryResult<string
|
|
1756
|
-
const states2: CreateQueryResult<string
|
|
1758
|
+
const states1: Array<CreateQueryResult<string>> = []
|
|
1759
|
+
const states2: Array<CreateQueryResult<string>> = []
|
|
1757
1760
|
|
|
1758
1761
|
await queryClient.prefetchQuery({
|
|
1759
1762
|
queryKey: key,
|
|
@@ -1859,7 +1862,7 @@ describe('createQuery', () => {
|
|
|
1859
1862
|
|
|
1860
1863
|
it('should re-render when a query becomes stale', async () => {
|
|
1861
1864
|
const key = queryKey()
|
|
1862
|
-
const states: CreateQueryResult<string
|
|
1865
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
1863
1866
|
|
|
1864
1867
|
function Page() {
|
|
1865
1868
|
const state = createQuery(() => ({
|
|
@@ -1889,7 +1892,7 @@ describe('createQuery', () => {
|
|
|
1889
1892
|
|
|
1890
1893
|
it('should not re-render when it should only re-render on data changes and the data did not change', async () => {
|
|
1891
1894
|
const key = queryKey()
|
|
1892
|
-
const states: CreateQueryResult<string
|
|
1895
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
1893
1896
|
|
|
1894
1897
|
function Page() {
|
|
1895
1898
|
const state = createQuery(() => ({
|
|
@@ -2131,7 +2134,7 @@ describe('createQuery', () => {
|
|
|
2131
2134
|
|
|
2132
2135
|
it('should not refetch query on focus when `enabled` is set to `false`', async () => {
|
|
2133
2136
|
const key = queryKey()
|
|
2134
|
-
const queryFn = vi.fn<unknown
|
|
2137
|
+
const queryFn = vi.fn<Array<unknown>, string>().mockReturnValue('data')
|
|
2135
2138
|
|
|
2136
2139
|
function Page() {
|
|
2137
2140
|
const { data = 'default' } = createQuery(() => ({
|
|
@@ -2162,7 +2165,7 @@ describe('createQuery', () => {
|
|
|
2162
2165
|
|
|
2163
2166
|
it('should not refetch stale query on focus when `refetchOnWindowFocus` is set to `false`', async () => {
|
|
2164
2167
|
const key = queryKey()
|
|
2165
|
-
const states: CreateQueryResult<number
|
|
2168
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2166
2169
|
let count = 0
|
|
2167
2170
|
|
|
2168
2171
|
function Page() {
|
|
@@ -2197,7 +2200,7 @@ describe('createQuery', () => {
|
|
|
2197
2200
|
|
|
2198
2201
|
it('should not refetch stale query on focus when `refetchOnWindowFocus` is set to a function that returns `false`', async () => {
|
|
2199
2202
|
const key = queryKey()
|
|
2200
|
-
const states: CreateQueryResult<number
|
|
2203
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2201
2204
|
let count = 0
|
|
2202
2205
|
|
|
2203
2206
|
function Page() {
|
|
@@ -2232,7 +2235,7 @@ describe('createQuery', () => {
|
|
|
2232
2235
|
|
|
2233
2236
|
it('should not refetch fresh query on focus when `refetchOnWindowFocus` is set to `true`', async () => {
|
|
2234
2237
|
const key = queryKey()
|
|
2235
|
-
const states: CreateQueryResult<number
|
|
2238
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2236
2239
|
let count = 0
|
|
2237
2240
|
|
|
2238
2241
|
function Page() {
|
|
@@ -2267,7 +2270,7 @@ describe('createQuery', () => {
|
|
|
2267
2270
|
|
|
2268
2271
|
it('should refetch fresh query on focus when `refetchOnWindowFocus` is set to `always`', async () => {
|
|
2269
2272
|
const key = queryKey()
|
|
2270
|
-
const states: CreateQueryResult<number
|
|
2273
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2271
2274
|
let count = 0
|
|
2272
2275
|
|
|
2273
2276
|
function Page() {
|
|
@@ -2307,7 +2310,7 @@ describe('createQuery', () => {
|
|
|
2307
2310
|
|
|
2308
2311
|
it('should calculate focus behaviour for refetchOnWindowFocus depending on function', async () => {
|
|
2309
2312
|
const key = queryKey()
|
|
2310
|
-
const states: CreateQueryResult<number
|
|
2313
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2311
2314
|
let count = 0
|
|
2312
2315
|
|
|
2313
2316
|
function Page() {
|
|
@@ -2357,7 +2360,7 @@ describe('createQuery', () => {
|
|
|
2357
2360
|
|
|
2358
2361
|
it('should refetch fresh query when refetchOnMount is set to always', async () => {
|
|
2359
2362
|
const key = queryKey()
|
|
2360
|
-
const states: CreateQueryResult<string
|
|
2363
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
2361
2364
|
|
|
2362
2365
|
await queryClient.prefetchQuery({
|
|
2363
2366
|
queryKey: key,
|
|
@@ -2400,7 +2403,7 @@ describe('createQuery', () => {
|
|
|
2400
2403
|
|
|
2401
2404
|
it('should refetch stale query when refetchOnMount is set to true', async () => {
|
|
2402
2405
|
const key = queryKey()
|
|
2403
|
-
const states: CreateQueryResult<string
|
|
2406
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
2404
2407
|
|
|
2405
2408
|
await queryClient.prefetchQuery({
|
|
2406
2409
|
queryKey: key,
|
|
@@ -2731,7 +2734,7 @@ describe('createQuery', () => {
|
|
|
2731
2734
|
|
|
2732
2735
|
it('should always fetch if refetchOnMount is set to always', async () => {
|
|
2733
2736
|
const key = queryKey()
|
|
2734
|
-
const states: CreateQueryResult<string
|
|
2737
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
2735
2738
|
|
|
2736
2739
|
await queryClient.prefetchQuery({
|
|
2737
2740
|
queryKey: key,
|
|
@@ -2785,7 +2788,7 @@ describe('createQuery', () => {
|
|
|
2785
2788
|
|
|
2786
2789
|
it('should fetch if initial data is set', async () => {
|
|
2787
2790
|
const key = queryKey()
|
|
2788
|
-
const states: DefinedCreateQueryResult<string
|
|
2791
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2789
2792
|
|
|
2790
2793
|
function Page() {
|
|
2791
2794
|
const state = createQuery(() => ({
|
|
@@ -2823,7 +2826,7 @@ describe('createQuery', () => {
|
|
|
2823
2826
|
|
|
2824
2827
|
it('should not fetch if initial data is set with a stale time', async () => {
|
|
2825
2828
|
const key = queryKey()
|
|
2826
|
-
const states: DefinedCreateQueryResult<string
|
|
2829
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2827
2830
|
|
|
2828
2831
|
function Page() {
|
|
2829
2832
|
const state = createQuery(() => ({
|
|
@@ -2861,7 +2864,7 @@ describe('createQuery', () => {
|
|
|
2861
2864
|
|
|
2862
2865
|
it('should fetch if initial data updated at is older than stale time', async () => {
|
|
2863
2866
|
const key = queryKey()
|
|
2864
|
-
const states: DefinedCreateQueryResult<string
|
|
2867
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2865
2868
|
|
|
2866
2869
|
const oneSecondAgo = Date.now() - 1000
|
|
2867
2870
|
|
|
@@ -2907,7 +2910,7 @@ describe('createQuery', () => {
|
|
|
2907
2910
|
|
|
2908
2911
|
it('should fetch if "initial data updated at" is exactly 0', async () => {
|
|
2909
2912
|
const key = queryKey()
|
|
2910
|
-
const states: DefinedCreateQueryResult<string
|
|
2913
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2911
2914
|
|
|
2912
2915
|
function Page() {
|
|
2913
2916
|
const state = createQuery(() => ({
|
|
@@ -2946,7 +2949,8 @@ describe('createQuery', () => {
|
|
|
2946
2949
|
|
|
2947
2950
|
it('should keep initial data when the query key changes', async () => {
|
|
2948
2951
|
const key = queryKey()
|
|
2949
|
-
const states: Partial<DefinedCreateQueryResult<{ count: number }
|
|
2952
|
+
const states: Array<Partial<DefinedCreateQueryResult<{ count: number }>>> =
|
|
2953
|
+
[]
|
|
2950
2954
|
|
|
2951
2955
|
function Page() {
|
|
2952
2956
|
const [count, setCount] = createSignal(0)
|
|
@@ -2988,7 +2992,7 @@ describe('createQuery', () => {
|
|
|
2988
2992
|
it('should retry specified number of times', async () => {
|
|
2989
2993
|
const key = queryKey()
|
|
2990
2994
|
|
|
2991
|
-
const queryFn = vi.fn<unknown
|
|
2995
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
2992
2996
|
queryFn.mockImplementation(() => {
|
|
2993
2997
|
return Promise.reject(new Error('Error test Barrett'))
|
|
2994
2998
|
})
|
|
@@ -3029,7 +3033,7 @@ describe('createQuery', () => {
|
|
|
3029
3033
|
it('should not retry if retry function `false`', async () => {
|
|
3030
3034
|
const key = queryKey()
|
|
3031
3035
|
|
|
3032
|
-
const queryFn = vi.fn<unknown
|
|
3036
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
3033
3037
|
|
|
3034
3038
|
queryFn.mockImplementationOnce(() => {
|
|
3035
3039
|
return Promise.reject(new Error('Error test Tanner'))
|
|
@@ -3077,7 +3081,7 @@ describe('createQuery', () => {
|
|
|
3077
3081
|
|
|
3078
3082
|
type DelayError = { delay: number }
|
|
3079
3083
|
|
|
3080
|
-
const queryFn = vi.fn<unknown
|
|
3084
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
3081
3085
|
queryFn.mockImplementation(() => {
|
|
3082
3086
|
return Promise.reject({ delay: 50 })
|
|
3083
3087
|
})
|
|
@@ -3179,7 +3183,7 @@ describe('createQuery', () => {
|
|
|
3179
3183
|
|
|
3180
3184
|
it('should fetch on mount when a query was already created with setQueryData', async () => {
|
|
3181
3185
|
const key = queryKey()
|
|
3182
|
-
const states: CreateQueryResult<string
|
|
3186
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3183
3187
|
|
|
3184
3188
|
queryClient.setQueryData(key, 'prefetched')
|
|
3185
3189
|
|
|
@@ -3219,7 +3223,7 @@ describe('createQuery', () => {
|
|
|
3219
3223
|
|
|
3220
3224
|
it('should refetch after focus regain', async () => {
|
|
3221
3225
|
const key = queryKey()
|
|
3222
|
-
const states: CreateQueryResult<string
|
|
3226
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3223
3227
|
|
|
3224
3228
|
// make page unfocused
|
|
3225
3229
|
const visibilityMock = mockVisibilityState('hidden')
|
|
@@ -3286,12 +3290,12 @@ describe('createQuery', () => {
|
|
|
3286
3290
|
// See https://github.com/tannerlinsley/react-query/issues/195
|
|
3287
3291
|
it('should refetch if stale after a prefetch', async () => {
|
|
3288
3292
|
const key = queryKey()
|
|
3289
|
-
const states: CreateQueryResult<string
|
|
3293
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3290
3294
|
|
|
3291
|
-
const queryFn = vi.fn<unknown
|
|
3295
|
+
const queryFn = vi.fn<Array<unknown>, string>()
|
|
3292
3296
|
queryFn.mockImplementation(() => 'data')
|
|
3293
3297
|
|
|
3294
|
-
const prefetchQueryFn = vi.fn<unknown
|
|
3298
|
+
const prefetchQueryFn = vi.fn<Array<unknown>, string>()
|
|
3295
3299
|
prefetchQueryFn.mockImplementation(() => 'not yet...')
|
|
3296
3300
|
|
|
3297
3301
|
await queryClient.prefetchQuery({
|
|
@@ -3325,10 +3329,10 @@ describe('createQuery', () => {
|
|
|
3325
3329
|
it('should not refetch if not stale after a prefetch', async () => {
|
|
3326
3330
|
const key = queryKey()
|
|
3327
3331
|
|
|
3328
|
-
const queryFn = vi.fn<unknown
|
|
3332
|
+
const queryFn = vi.fn<Array<unknown>, string>()
|
|
3329
3333
|
queryFn.mockImplementation(() => 'data')
|
|
3330
3334
|
|
|
3331
|
-
const prefetchQueryFn = vi.fn<unknown
|
|
3335
|
+
const prefetchQueryFn = vi.fn<Array<unknown>, Promise<string>>()
|
|
3332
3336
|
prefetchQueryFn.mockImplementation(async () => {
|
|
3333
3337
|
await sleep(10)
|
|
3334
3338
|
return 'not yet...'
|
|
@@ -3494,7 +3498,7 @@ describe('createQuery', () => {
|
|
|
3494
3498
|
|
|
3495
3499
|
it('should mark query as fetching, when using initialData', async () => {
|
|
3496
3500
|
const key = queryKey()
|
|
3497
|
-
const results: DefinedCreateQueryResult<string
|
|
3501
|
+
const results: Array<DefinedCreateQueryResult<string>> = []
|
|
3498
3502
|
|
|
3499
3503
|
function Page() {
|
|
3500
3504
|
const result = createQuery(() => ({
|
|
@@ -3529,7 +3533,7 @@ describe('createQuery', () => {
|
|
|
3529
3533
|
|
|
3530
3534
|
it('should initialize state properly, when initialData is falsy', async () => {
|
|
3531
3535
|
const key = queryKey()
|
|
3532
|
-
const results: DefinedCreateQueryResult<number
|
|
3536
|
+
const results: Array<DefinedCreateQueryResult<number>> = []
|
|
3533
3537
|
|
|
3534
3538
|
function Page() {
|
|
3535
3539
|
const result = createQuery(() => ({
|
|
@@ -3561,7 +3565,7 @@ describe('createQuery', () => {
|
|
|
3561
3565
|
// // See https://github.com/tannerlinsley/react-query/issues/214
|
|
3562
3566
|
it('data should persist when enabled is changed to false', async () => {
|
|
3563
3567
|
const key = queryKey()
|
|
3564
|
-
const results: DefinedCreateQueryResult<string
|
|
3568
|
+
const results: Array<DefinedCreateQueryResult<string>> = []
|
|
3565
3569
|
|
|
3566
3570
|
function Page() {
|
|
3567
3571
|
const [shouldFetch, setShouldFetch] = createSignal(true)
|
|
@@ -3601,7 +3605,7 @@ describe('createQuery', () => {
|
|
|
3601
3605
|
|
|
3602
3606
|
it('it should support enabled:false in query object syntax', async () => {
|
|
3603
3607
|
const key = queryKey()
|
|
3604
|
-
const queryFn = vi.fn<unknown
|
|
3608
|
+
const queryFn = vi.fn<Array<unknown>, string>()
|
|
3605
3609
|
queryFn.mockImplementation(() => 'data')
|
|
3606
3610
|
|
|
3607
3611
|
function Page() {
|
|
@@ -3711,7 +3715,7 @@ describe('createQuery', () => {
|
|
|
3711
3715
|
|
|
3712
3716
|
it('should not cause memo churn when data does not change', async () => {
|
|
3713
3717
|
const key = queryKey()
|
|
3714
|
-
const queryFn = vi.fn<unknown
|
|
3718
|
+
const queryFn = vi.fn<Array<unknown>, string>().mockReturnValue('data')
|
|
3715
3719
|
const memoFn = vi.fn()
|
|
3716
3720
|
|
|
3717
3721
|
function Page() {
|
|
@@ -3794,7 +3798,7 @@ describe('createQuery', () => {
|
|
|
3794
3798
|
it('should refetch in an interval depending on function result', async () => {
|
|
3795
3799
|
const key = queryKey()
|
|
3796
3800
|
let count = 0
|
|
3797
|
-
const states: CreateQueryResult<number
|
|
3801
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
3798
3802
|
|
|
3799
3803
|
function Page() {
|
|
3800
3804
|
const state = createQuery(() => ({
|
|
@@ -3866,7 +3870,7 @@ describe('createQuery', () => {
|
|
|
3866
3870
|
|
|
3867
3871
|
it('should not interval fetch with a refetchInterval of 0', async () => {
|
|
3868
3872
|
const key = queryKey()
|
|
3869
|
-
const states: CreateQueryResult<number
|
|
3873
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
3870
3874
|
|
|
3871
3875
|
function Page() {
|
|
3872
3876
|
const state = createQuery(() => ({
|
|
@@ -3947,7 +3951,7 @@ describe('createQuery', () => {
|
|
|
3947
3951
|
it('should refetch if any query instance becomes enabled', async () => {
|
|
3948
3952
|
const key = queryKey()
|
|
3949
3953
|
|
|
3950
|
-
const queryFn = vi.fn<unknown
|
|
3954
|
+
const queryFn = vi.fn<Array<unknown>, string>().mockReturnValue('data')
|
|
3951
3955
|
|
|
3952
3956
|
function Disabled() {
|
|
3953
3957
|
createQuery(() => ({ queryKey: key, queryFn, enabled: false }))
|
|
@@ -3984,7 +3988,7 @@ describe('createQuery', () => {
|
|
|
3984
3988
|
it('should use placeholder data while the query loads', async () => {
|
|
3985
3989
|
const key1 = queryKey()
|
|
3986
3990
|
|
|
3987
|
-
const states: CreateQueryResult<string
|
|
3991
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3988
3992
|
|
|
3989
3993
|
function Page() {
|
|
3990
3994
|
const state = createQuery(() => ({
|
|
@@ -4029,7 +4033,8 @@ describe('createQuery', () => {
|
|
|
4029
4033
|
it('should use placeholder data even for disabled queries', async () => {
|
|
4030
4034
|
const key1 = queryKey()
|
|
4031
4035
|
|
|
4032
|
-
const states: { state: CreateQueryResult<string>; count: number }
|
|
4036
|
+
const states: Array<{ state: CreateQueryResult<string>; count: number }> =
|
|
4037
|
+
[]
|
|
4033
4038
|
|
|
4034
4039
|
function Page() {
|
|
4035
4040
|
const [count, setCount] = createSignal(0)
|
|
@@ -4095,7 +4100,7 @@ describe('createQuery', () => {
|
|
|
4095
4100
|
it('placeholder data should run through select', async () => {
|
|
4096
4101
|
const key1 = queryKey()
|
|
4097
4102
|
|
|
4098
|
-
const states: CreateQueryResult<string
|
|
4103
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4099
4104
|
|
|
4100
4105
|
function Page() {
|
|
4101
4106
|
const state = createQuery(() => ({
|
|
@@ -4141,7 +4146,7 @@ describe('createQuery', () => {
|
|
|
4141
4146
|
it('placeholder data function result should run through select', async () => {
|
|
4142
4147
|
const key1 = queryKey()
|
|
4143
4148
|
|
|
4144
|
-
const states: CreateQueryResult<string
|
|
4149
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4145
4150
|
let placeholderFunctionRunCount = 0
|
|
4146
4151
|
|
|
4147
4152
|
function Page() {
|
|
@@ -4393,7 +4398,7 @@ describe('createQuery', () => {
|
|
|
4393
4398
|
|
|
4394
4399
|
it('should cancel the query if the signal was consumed and there are no more subscriptions', async () => {
|
|
4395
4400
|
const key = queryKey()
|
|
4396
|
-
const states: CreateQueryResult<string
|
|
4401
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4397
4402
|
|
|
4398
4403
|
const queryFn: QueryFunction<
|
|
4399
4404
|
string,
|
|
@@ -4463,7 +4468,7 @@ describe('createQuery', () => {
|
|
|
4463
4468
|
|
|
4464
4469
|
it('should refetch when quickly switching to a failed query', async () => {
|
|
4465
4470
|
const key = queryKey()
|
|
4466
|
-
const states: CreateQueryResult<string
|
|
4471
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4467
4472
|
|
|
4468
4473
|
const queryFn = async () => {
|
|
4469
4474
|
await sleep(50)
|
|
@@ -4513,7 +4518,7 @@ describe('createQuery', () => {
|
|
|
4513
4518
|
|
|
4514
4519
|
it('should update query state and refetch when reset with resetQueries', async () => {
|
|
4515
4520
|
const key = queryKey()
|
|
4516
|
-
const states: CreateQueryResult<number
|
|
4521
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
4517
4522
|
let count = 0
|
|
4518
4523
|
|
|
4519
4524
|
function Page() {
|
|
@@ -4587,7 +4592,7 @@ describe('createQuery', () => {
|
|
|
4587
4592
|
|
|
4588
4593
|
it('should update query state and not refetch when resetting a disabled query with resetQueries', async () => {
|
|
4589
4594
|
const key = queryKey()
|
|
4590
|
-
const states: CreateQueryResult<number
|
|
4595
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
4591
4596
|
let count = 0
|
|
4592
4597
|
|
|
4593
4598
|
function Page() {
|
|
@@ -4664,11 +4669,10 @@ describe('createQuery', () => {
|
|
|
4664
4669
|
})
|
|
4665
4670
|
})
|
|
4666
4671
|
|
|
4667
|
-
it('should only call the query hash function once
|
|
4672
|
+
it('should only call the query hash function once', async () => {
|
|
4668
4673
|
const key = queryKey()
|
|
4669
4674
|
|
|
4670
4675
|
let hashes = 0
|
|
4671
|
-
let renders = 0
|
|
4672
4676
|
|
|
4673
4677
|
function queryKeyHashFn(x: any) {
|
|
4674
4678
|
hashes++
|
|
@@ -4676,20 +4680,12 @@ describe('createQuery', () => {
|
|
|
4676
4680
|
}
|
|
4677
4681
|
|
|
4678
4682
|
function Page() {
|
|
4679
|
-
|
|
4683
|
+
createQuery(() => ({
|
|
4680
4684
|
queryKey: key,
|
|
4681
4685
|
queryFn: () => 'test',
|
|
4682
4686
|
queryKeyHashFn,
|
|
4683
4687
|
}))
|
|
4684
4688
|
|
|
4685
|
-
createEffect(
|
|
4686
|
-
on(
|
|
4687
|
-
() => state.status,
|
|
4688
|
-
() => {
|
|
4689
|
-
renders++
|
|
4690
|
-
},
|
|
4691
|
-
),
|
|
4692
|
-
)
|
|
4693
4689
|
return null
|
|
4694
4690
|
}
|
|
4695
4691
|
|
|
@@ -4700,12 +4696,11 @@ describe('createQuery', () => {
|
|
|
4700
4696
|
))
|
|
4701
4697
|
|
|
4702
4698
|
await sleep(10)
|
|
4703
|
-
|
|
4704
|
-
expect(renders).toBe(hashes)
|
|
4699
|
+
expect(hashes).toBe(1)
|
|
4705
4700
|
})
|
|
4706
4701
|
|
|
4707
4702
|
it('should refetch when changed enabled to true in error state', async () => {
|
|
4708
|
-
const queryFn = vi.fn<unknown
|
|
4703
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
4709
4704
|
queryFn.mockImplementation(async () => {
|
|
4710
4705
|
await sleep(10)
|
|
4711
4706
|
return Promise.reject(new Error('Suspense Error Bingo'))
|
|
@@ -4900,7 +4895,7 @@ describe('createQuery', () => {
|
|
|
4900
4895
|
|
|
4901
4896
|
it('should have no error in pending state when refetching after error occurred', async () => {
|
|
4902
4897
|
const key = queryKey()
|
|
4903
|
-
const states: CreateQueryResult<number
|
|
4898
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
4904
4899
|
const error = new Error('oops')
|
|
4905
4900
|
|
|
4906
4901
|
let count = 0
|
|
@@ -5759,7 +5754,7 @@ describe('createQuery', () => {
|
|
|
5759
5754
|
|
|
5760
5755
|
it('it should have status=error on mount when a query has failed', async () => {
|
|
5761
5756
|
const key = queryKey()
|
|
5762
|
-
const states: CreateQueryResult<unknown
|
|
5757
|
+
const states: Array<CreateQueryResult<unknown>> = []
|
|
5763
5758
|
const error = new Error('oops')
|
|
5764
5759
|
|
|
5765
5760
|
const queryFn = async (): Promise<unknown> => {
|