@tanstack/react-query 5.0.0-alpha.2 → 5.0.0-alpha.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/lib/HydrationBoundary.esm.js +1 -0
- package/build/lib/HydrationBoundary.esm.js.map +1 -1
- package/build/lib/HydrationBoundary.js +1 -0
- package/build/lib/HydrationBoundary.js.map +1 -1
- package/build/lib/HydrationBoundary.mjs +1 -0
- package/build/lib/HydrationBoundary.mjs.map +1 -1
- package/build/lib/QueryClientProvider.esm.js +1 -0
- package/build/lib/QueryClientProvider.esm.js.map +1 -1
- package/build/lib/QueryClientProvider.js +1 -0
- package/build/lib/QueryClientProvider.js.map +1 -1
- package/build/lib/QueryClientProvider.mjs +1 -0
- package/build/lib/QueryClientProvider.mjs.map +1 -1
- package/build/lib/QueryErrorResetBoundary.esm.js +1 -0
- package/build/lib/QueryErrorResetBoundary.esm.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.js +1 -0
- package/build/lib/QueryErrorResetBoundary.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.mjs +1 -0
- package/build/lib/QueryErrorResetBoundary.mjs.map +1 -1
- package/build/lib/__tests__/ssr.test.d.ts +0 -3
- package/build/lib/__tests__/utils.d.ts +2 -3
- package/build/lib/errorBoundaryUtils.esm.js +1 -0
- package/build/lib/errorBoundaryUtils.esm.js.map +1 -1
- package/build/lib/errorBoundaryUtils.js +1 -0
- package/build/lib/errorBoundaryUtils.js.map +1 -1
- package/build/lib/errorBoundaryUtils.mjs +1 -0
- package/build/lib/errorBoundaryUtils.mjs.map +1 -1
- package/build/lib/isRestoring.esm.js +1 -0
- package/build/lib/isRestoring.esm.js.map +1 -1
- package/build/lib/isRestoring.js +1 -0
- package/build/lib/isRestoring.js.map +1 -1
- package/build/lib/isRestoring.mjs +1 -0
- package/build/lib/isRestoring.mjs.map +1 -1
- package/build/lib/suspense.d.ts +1 -1
- package/build/lib/suspense.esm.js +2 -9
- package/build/lib/suspense.esm.js.map +1 -1
- package/build/lib/suspense.js +2 -9
- package/build/lib/suspense.js.map +1 -1
- package/build/lib/suspense.mjs +1 -8
- package/build/lib/suspense.mjs.map +1 -1
- package/build/lib/useBaseQuery.esm.js +1 -11
- package/build/lib/useBaseQuery.esm.js.map +1 -1
- package/build/lib/useBaseQuery.js +1 -11
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.mjs +1 -11
- package/build/lib/useBaseQuery.mjs.map +1 -1
- package/build/lib/useInfiniteQuery.esm.js +1 -0
- package/build/lib/useInfiniteQuery.esm.js.map +1 -1
- package/build/lib/useInfiniteQuery.js +1 -0
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.mjs +1 -0
- package/build/lib/useInfiniteQuery.mjs.map +1 -1
- package/build/lib/useIsFetching.esm.js +1 -0
- package/build/lib/useIsFetching.esm.js.map +1 -1
- package/build/lib/useIsFetching.js +1 -0
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useIsFetching.mjs +1 -0
- package/build/lib/useIsFetching.mjs.map +1 -1
- package/build/lib/useMutation.esm.js +1 -0
- package/build/lib/useMutation.esm.js.map +1 -1
- package/build/lib/useMutation.js +1 -0
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.mjs +1 -0
- package/build/lib/useMutation.mjs.map +1 -1
- package/build/lib/useMutationState.d.ts +3 -3
- package/build/lib/useMutationState.esm.js +1 -0
- package/build/lib/useMutationState.esm.js.map +1 -1
- package/build/lib/useMutationState.js +1 -0
- package/build/lib/useMutationState.js.map +1 -1
- package/build/lib/useMutationState.mjs +1 -0
- package/build/lib/useMutationState.mjs.map +1 -1
- package/build/lib/useQueries.d.ts +2 -3
- package/build/lib/useQueries.esm.js +20 -16
- package/build/lib/useQueries.esm.js.map +1 -1
- package/build/lib/useQueries.js +20 -16
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.mjs +11 -10
- package/build/lib/useQueries.mjs.map +1 -1
- package/build/lib/useQuery.esm.js +1 -0
- package/build/lib/useQuery.esm.js.map +1 -1
- package/build/lib/useQuery.js +1 -0
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/useQuery.mjs +1 -0
- package/build/lib/useQuery.mjs.map +1 -1
- package/build/umd/index.development.js +108 -138
- 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 +3 -3
- package/src/__tests__/HydrationBoundary.test.tsx +4 -3
- package/src/__tests__/QueryClientProvider.test.tsx +2 -1
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +753 -620
- package/src/__tests__/ssr-hydration.test.tsx +11 -10
- package/src/__tests__/ssr.test.tsx +4 -7
- package/src/__tests__/suspense.test.tsx +11 -92
- package/src/__tests__/useInfiniteQuery.test.tsx +18 -16
- package/src/__tests__/useInfiniteQuery.type.test.tsx +94 -13
- package/src/__tests__/useMutation.test.tsx +21 -20
- package/src/__tests__/useMutationState.test.tsx +24 -58
- package/src/__tests__/useQueries.test.tsx +25 -154
- package/src/__tests__/useQuery.test.tsx +174 -359
- package/src/__tests__/utils.tsx +3 -2
- package/src/errorBoundaryUtils.ts +1 -0
- package/src/suspense.ts +3 -11
- package/src/useBaseQuery.ts +1 -19
- package/src/useInfiniteQuery.ts +1 -0
- package/src/useIsFetching.ts +1 -0
- package/src/useMutation.ts +1 -0
- package/src/useMutationState.ts +4 -3
- package/src/useQueries.ts +19 -18
- package/src/useQuery.ts +1 -0
package/src/__tests__/utils.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { act, render } from '@testing-library/react'
|
|
|
3
3
|
import type { QueryClientConfig } from '..'
|
|
4
4
|
import { QueryClient, QueryClientProvider } from '..'
|
|
5
5
|
import * as utils from '@tanstack/query-core'
|
|
6
|
+
import { vi } from 'vitest'
|
|
6
7
|
|
|
7
8
|
export function renderWithClient(
|
|
8
9
|
client: QueryClient,
|
|
@@ -45,11 +46,11 @@ export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export function mockVisibilityState(value: DocumentVisibilityState) {
|
|
48
|
-
return
|
|
49
|
+
return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
export function mockNavigatorOnLine(value: boolean) {
|
|
52
|
-
return
|
|
53
|
+
return vi.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
let queryKeyCount = 0
|
package/src/suspense.ts
CHANGED
|
@@ -46,14 +46,6 @@ export const fetchOptimistic = <
|
|
|
46
46
|
observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
|
|
47
47
|
errorResetBoundary: QueryErrorResetBoundaryValue,
|
|
48
48
|
) =>
|
|
49
|
-
observer
|
|
50
|
-
.
|
|
51
|
-
|
|
52
|
-
defaultedOptions.onSuccess?.(data as TData)
|
|
53
|
-
defaultedOptions.onSettled?.(data, null)
|
|
54
|
-
})
|
|
55
|
-
.catch((error) => {
|
|
56
|
-
errorResetBoundary.clearReset()
|
|
57
|
-
defaultedOptions.onError?.(error)
|
|
58
|
-
defaultedOptions.onSettled?.(undefined, error)
|
|
59
|
-
})
|
|
49
|
+
observer.fetchOptimistic(defaultedOptions).catch(() => {
|
|
50
|
+
errorResetBoundary.clearReset()
|
|
51
|
+
})
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client'
|
|
1
2
|
import * as React from 'react'
|
|
2
3
|
|
|
3
4
|
import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core'
|
|
@@ -40,25 +41,6 @@ export function useBaseQuery<
|
|
|
40
41
|
? 'isRestoring'
|
|
41
42
|
: 'optimistic'
|
|
42
43
|
|
|
43
|
-
// Include callbacks in batch renders
|
|
44
|
-
if (defaultedOptions.onError) {
|
|
45
|
-
defaultedOptions.onError = notifyManager.batchCalls(
|
|
46
|
-
defaultedOptions.onError,
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (defaultedOptions.onSuccess) {
|
|
51
|
-
defaultedOptions.onSuccess = notifyManager.batchCalls(
|
|
52
|
-
defaultedOptions.onSuccess,
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (defaultedOptions.onSettled) {
|
|
57
|
-
defaultedOptions.onSettled = notifyManager.batchCalls(
|
|
58
|
-
defaultedOptions.onSettled,
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
44
|
ensureStaleTime(defaultedOptions)
|
|
63
45
|
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary)
|
|
64
46
|
|
package/src/useInfiniteQuery.ts
CHANGED
package/src/useIsFetching.ts
CHANGED
package/src/useMutation.ts
CHANGED
package/src/useMutationState.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client'
|
|
1
2
|
import * as React from 'react'
|
|
2
3
|
|
|
3
4
|
import type {
|
|
@@ -6,10 +7,10 @@ import type {
|
|
|
6
7
|
Mutation,
|
|
7
8
|
MutationCache,
|
|
8
9
|
DefaultError,
|
|
10
|
+
MutationState,
|
|
9
11
|
} from '@tanstack/query-core'
|
|
10
12
|
import { notifyManager, replaceEqualDeep } from '@tanstack/query-core'
|
|
11
13
|
import { useQueryClient } from './QueryClientProvider'
|
|
12
|
-
import type { MutationState } from '@tanstack/query-core/build/lib/mutation'
|
|
13
14
|
|
|
14
15
|
export function useIsMutating(
|
|
15
16
|
filters?: MutationFilters,
|
|
@@ -22,7 +23,7 @@ export function useIsMutating(
|
|
|
22
23
|
).length
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
type MutationStateOptions<TResult> = {
|
|
26
|
+
type MutationStateOptions<TResult = MutationState> = {
|
|
26
27
|
filters?: MutationFilters
|
|
27
28
|
select?: (
|
|
28
29
|
mutation: Mutation<unknown, DefaultError, unknown, unknown>,
|
|
@@ -45,7 +46,7 @@ function getResult<TResult = MutationState>(
|
|
|
45
46
|
)
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
export function useMutationState<TResult =
|
|
49
|
+
export function useMutationState<TResult = MutationState>(
|
|
49
50
|
options: MutationStateOptions<TResult> = {},
|
|
50
51
|
queryClient?: QueryClient,
|
|
51
52
|
): Array<TResult> {
|
package/src/useQueries.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client'
|
|
1
2
|
import * as React from 'react'
|
|
2
3
|
|
|
3
4
|
import type {
|
|
@@ -155,15 +156,17 @@ export type QueriesResults<
|
|
|
155
156
|
: // Fallback
|
|
156
157
|
UseQueryResult[]
|
|
157
158
|
|
|
158
|
-
export function useQueries<T extends any[]>(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}: {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
export function useQueries<T extends any[]>(
|
|
160
|
+
{
|
|
161
|
+
queries,
|
|
162
|
+
}: {
|
|
163
|
+
queries: readonly [...QueriesOptions<T>]
|
|
164
|
+
},
|
|
165
|
+
queryClient?: QueryClient,
|
|
166
|
+
): QueriesResults<T> {
|
|
165
167
|
const client = useQueryClient(queryClient)
|
|
166
168
|
const isRestoring = useIsRestoring()
|
|
169
|
+
const errorResetBoundary = useQueryErrorResetBoundary()
|
|
167
170
|
|
|
168
171
|
const defaultedQueries = React.useMemo(
|
|
169
172
|
() =>
|
|
@@ -180,6 +183,13 @@ export function useQueries<T extends any[]>({
|
|
|
180
183
|
[queries, client, isRestoring],
|
|
181
184
|
)
|
|
182
185
|
|
|
186
|
+
defaultedQueries.forEach((query) => {
|
|
187
|
+
ensureStaleTime(query)
|
|
188
|
+
ensurePreventErrorBoundaryRetry(query, errorResetBoundary)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
useClearResetErrorBoundary(errorResetBoundary)
|
|
192
|
+
|
|
183
193
|
const [observer] = React.useState(
|
|
184
194
|
() => new QueriesObserver(client, defaultedQueries),
|
|
185
195
|
)
|
|
@@ -204,15 +214,6 @@ export function useQueries<T extends any[]>({
|
|
|
204
214
|
observer.setQueries(defaultedQueries, { listeners: false })
|
|
205
215
|
}, [defaultedQueries, observer])
|
|
206
216
|
|
|
207
|
-
const errorResetBoundary = useQueryErrorResetBoundary()
|
|
208
|
-
|
|
209
|
-
defaultedQueries.forEach((query) => {
|
|
210
|
-
ensurePreventErrorBoundaryRetry(query, errorResetBoundary)
|
|
211
|
-
ensureStaleTime(query)
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
useClearResetErrorBoundary(errorResetBoundary)
|
|
215
|
-
|
|
216
217
|
const shouldAtLeastOneSuspend = optimisticResult.some((result, index) =>
|
|
217
218
|
shouldSuspend(defaultedQueries[index], result, isRestoring),
|
|
218
219
|
)
|
|
@@ -236,14 +237,14 @@ export function useQueries<T extends any[]>({
|
|
|
236
237
|
if (suspensePromises.length > 0) {
|
|
237
238
|
throw Promise.all(suspensePromises)
|
|
238
239
|
}
|
|
239
|
-
|
|
240
|
+
const observerQueries = observer.getQueries()
|
|
240
241
|
const firstSingleResultWhichShouldThrow = optimisticResult.find(
|
|
241
242
|
(result, index) =>
|
|
242
243
|
getHasError({
|
|
243
244
|
result,
|
|
244
245
|
errorResetBoundary,
|
|
245
246
|
throwErrors: defaultedQueries[index]?.throwErrors ?? false,
|
|
246
|
-
query:
|
|
247
|
+
query: observerQueries[index]!,
|
|
247
248
|
}),
|
|
248
249
|
)
|
|
249
250
|
|
package/src/useQuery.ts
CHANGED