@tanstack/react-query 4.24.10 → 5.0.0-alpha.1
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.d.ts +9 -0
- package/build/lib/{Hydrate.esm.js → HydrationBoundary.esm.js} +14 -17
- package/build/lib/HydrationBoundary.esm.js.map +1 -0
- package/build/lib/{Hydrate.js → HydrationBoundary.js} +17 -24
- package/build/lib/HydrationBoundary.js.map +1 -0
- package/build/lib/{Hydrate.mjs → HydrationBoundary.mjs} +14 -17
- package/build/lib/HydrationBoundary.mjs.map +1 -0
- package/build/lib/QueryClientProvider.d.ts +4 -19
- package/build/lib/QueryClientProvider.esm.js +11 -46
- package/build/lib/QueryClientProvider.esm.js.map +1 -1
- package/build/lib/QueryClientProvider.js +14 -52
- package/build/lib/QueryClientProvider.js.map +1 -1
- package/build/lib/QueryClientProvider.mjs +11 -46
- package/build/lib/QueryClientProvider.mjs.map +1 -1
- package/build/lib/QueryErrorResetBoundary.esm.js +7 -2
- package/build/lib/QueryErrorResetBoundary.esm.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.js +10 -8
- package/build/lib/QueryErrorResetBoundary.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.mjs +7 -2
- package/build/lib/QueryErrorResetBoundary.mjs.map +1 -1
- package/build/lib/__tests__/useQuery.types.test.d.ts +1 -2
- package/build/lib/__tests__/utils.d.ts +7 -10
- 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 +6 -9
- 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/index.d.ts +4 -5
- package/build/lib/index.esm.js +3 -4
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +6 -9
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +3 -4
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/isRestoring.esm.js.map +1 -1
- package/build/lib/isRestoring.js +3 -6
- package/build/lib/isRestoring.js.map +1 -1
- package/build/lib/isRestoring.mjs.map +1 -1
- package/build/lib/suspense.esm.js +5 -5
- package/build/lib/suspense.esm.js.map +1 -1
- package/build/lib/suspense.js +5 -7
- package/build/lib/suspense.js.map +1 -1
- package/build/lib/suspense.mjs +5 -5
- package/build/lib/suspense.mjs.map +1 -1
- package/build/lib/types.d.ts +14 -22
- package/build/lib/useBaseQuery.d.ts +2 -2
- package/build/lib/useBaseQuery.esm.js +15 -18
- package/build/lib/useBaseQuery.esm.js.map +1 -1
- package/build/lib/useBaseQuery.js +18 -24
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.mjs +15 -18
- package/build/lib/useBaseQuery.mjs.map +1 -1
- package/build/lib/useInfiniteQuery.d.ts +2 -4
- package/build/lib/useInfiniteQuery.esm.js +6 -4
- package/build/lib/useInfiniteQuery.esm.js.map +1 -1
- package/build/lib/useInfiniteQuery.js +5 -5
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.mjs +6 -4
- package/build/lib/useInfiniteQuery.mjs.map +1 -1
- package/build/lib/useIsFetching.d.ts +2 -7
- package/build/lib/useIsFetching.esm.js +5 -9
- package/build/lib/useIsFetching.esm.js.map +1 -1
- package/build/lib/useIsFetching.js +7 -14
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useIsFetching.mjs +5 -9
- package/build/lib/useIsFetching.mjs.map +1 -1
- package/build/lib/useMutation.d.ts +2 -5
- package/build/lib/useMutation.esm.js +12 -14
- package/build/lib/useMutation.esm.js.map +1 -1
- package/build/lib/useMutation.js +14 -19
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.mjs +12 -14
- package/build/lib/useMutation.mjs.map +1 -1
- package/build/lib/useMutationState.d.ts +8 -0
- package/build/lib/useMutationState.esm.js +37 -0
- package/build/lib/useMutationState.esm.js.map +1 -0
- package/build/lib/useMutationState.js +59 -0
- package/build/lib/useMutationState.js.map +1 -0
- package/build/lib/useMutationState.mjs +37 -0
- package/build/lib/useMutationState.mjs.map +1 -0
- package/build/lib/useQueries.d.ts +9 -7
- package/build/lib/useQueries.esm.js +16 -27
- package/build/lib/useQueries.esm.js.map +1 -1
- package/build/lib/useQueries.js +19 -33
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.mjs +16 -27
- package/build/lib/useQueries.mjs.map +1 -1
- package/build/lib/useQuery.d.ts +9 -21
- package/build/lib/useQuery.esm.js +5 -4
- package/build/lib/useQuery.esm.js.map +1 -1
- package/build/lib/useQuery.js +4 -5
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/useQuery.mjs +5 -4
- package/build/lib/useQuery.mjs.map +1 -1
- package/build/lib/utils.d.ts +1 -1
- package/build/lib/utils.esm.js +5 -6
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +5 -8
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +5 -6
- package/build/lib/utils.mjs.map +1 -1
- package/build/umd/index.development.js +1003 -1827
- 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 +6 -18
- package/src/{Hydrate.tsx → HydrationBoundary.tsx} +17 -18
- package/src/QueryClientProvider.tsx +11 -65
- package/src/__tests__/{Hydrate.test.tsx → HydrationBoundary.test.tsx} +89 -77
- package/src/__tests__/QueryClientProvider.test.tsx +33 -147
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +118 -85
- package/src/__tests__/ssr-hydration.test.tsx +27 -33
- package/src/__tests__/ssr.test.tsx +23 -9
- package/src/__tests__/suspense.test.tsx +194 -171
- package/src/__tests__/useInfiniteQuery.test.tsx +249 -494
- package/src/__tests__/useInfiniteQuery.type.test.tsx +131 -0
- package/src/__tests__/useIsFetching.test.tsx +65 -108
- package/src/__tests__/useMutation.test.tsx +200 -268
- package/src/__tests__/useMutationState.test.tsx +284 -0
- package/src/__tests__/useQueries.test.tsx +43 -347
- package/src/__tests__/useQuery.test.tsx +890 -686
- package/src/__tests__/useQuery.types.test.tsx +23 -24
- package/src/__tests__/utils.tsx +14 -23
- package/src/errorBoundaryUtils.ts +5 -10
- package/src/index.ts +4 -7
- package/src/types.ts +33 -38
- package/src/useBaseQuery.ts +7 -7
- package/src/useInfiniteQuery.ts +13 -77
- package/src/useIsFetching.ts +8 -20
- package/src/useMutation.ts +8 -66
- package/src/useMutationState.ts +81 -0
- package/src/useQueries.ts +29 -21
- package/src/useQuery.ts +27 -104
- package/src/utils.ts +5 -5
- package/build/lib/Hydrate.d.ts +0 -10
- package/build/lib/Hydrate.esm.js.map +0 -1
- package/build/lib/Hydrate.js.map +0 -1
- package/build/lib/Hydrate.mjs.map +0 -1
- package/build/lib/reactBatchedUpdates.d.ts +0 -2
- package/build/lib/reactBatchedUpdates.esm.js +0 -6
- package/build/lib/reactBatchedUpdates.esm.js.map +0 -1
- package/build/lib/reactBatchedUpdates.js +0 -30
- package/build/lib/reactBatchedUpdates.js.map +0 -1
- package/build/lib/reactBatchedUpdates.mjs +0 -6
- package/build/lib/reactBatchedUpdates.mjs.map +0 -1
- package/build/lib/reactBatchedUpdates.native.d.ts +0 -2
- package/build/lib/reactBatchedUpdates.native.esm.js +0 -2
- package/build/lib/reactBatchedUpdates.native.esm.js.map +0 -1
- package/build/lib/reactBatchedUpdates.native.js +0 -13
- package/build/lib/reactBatchedUpdates.native.js.map +0 -1
- package/build/lib/reactBatchedUpdates.native.mjs +0 -2
- package/build/lib/reactBatchedUpdates.native.mjs.map +0 -1
- package/build/lib/setBatchUpdatesFn.esm.js +0 -5
- package/build/lib/setBatchUpdatesFn.esm.js.map +0 -1
- package/build/lib/setBatchUpdatesFn.js +0 -7
- package/build/lib/setBatchUpdatesFn.js.map +0 -1
- package/build/lib/setBatchUpdatesFn.mjs +0 -5
- package/build/lib/setBatchUpdatesFn.mjs.map +0 -1
- package/build/lib/useIsMutating.d.ts +0 -7
- package/build/lib/useIsMutating.esm.js +0 -16
- package/build/lib/useIsMutating.esm.js.map +0 -1
- package/build/lib/useIsMutating.js +0 -40
- package/build/lib/useIsMutating.js.map +0 -1
- package/build/lib/useIsMutating.mjs +0 -16
- package/build/lib/useIsMutating.mjs.map +0 -1
- package/build/lib/useSyncExternalStore.d.ts +0 -2
- package/build/lib/useSyncExternalStore.esm.js +0 -7
- package/build/lib/useSyncExternalStore.esm.js.map +0 -1
- package/build/lib/useSyncExternalStore.js +0 -11
- package/build/lib/useSyncExternalStore.js.map +0 -1
- package/build/lib/useSyncExternalStore.mjs +0 -7
- package/build/lib/useSyncExternalStore.mjs.map +0 -1
- package/build/lib/useSyncExternalStore.native.d.ts +0 -2
- package/build/lib/useSyncExternalStore.native.esm.js +0 -2
- package/build/lib/useSyncExternalStore.native.esm.js.map +0 -1
- package/build/lib/useSyncExternalStore.native.js +0 -13
- package/build/lib/useSyncExternalStore.native.js.map +0 -1
- package/build/lib/useSyncExternalStore.native.mjs +0 -2
- package/build/lib/useSyncExternalStore.native.mjs.map +0 -1
- package/codemods/v4/key-transformation.js +0 -138
- package/codemods/v4/replace-import-specifier.js +0 -25
- package/codemods/v4/utils/index.js +0 -166
- package/codemods/v4/utils/replacers/key-replacer.js +0 -160
- package/codemods/v4/utils/transformers/query-cache-transformer.js +0 -115
- package/codemods/v4/utils/transformers/query-client-transformer.js +0 -49
- package/codemods/v4/utils/transformers/use-query-like-transformer.js +0 -32
- package/codemods/v4/utils/unprocessable-key-error.js +0 -8
- package/src/__tests__/useIsMutating.test.tsx +0 -259
- package/src/reactBatchedUpdates.native.ts +0 -4
- package/src/reactBatchedUpdates.ts +0 -2
- package/src/setBatchUpdatesFn.ts +0 -4
- package/src/useIsMutating.ts +0 -39
- package/src/useSyncExternalStore.native.ts +0 -5
- package/src/useSyncExternalStore.ts +0 -4
- /package/build/lib/__tests__/{Hydrate.test.d.ts → HydrationBoundary.test.d.ts} +0 -0
- /package/build/lib/__tests__/{useIsMutating.test.d.ts → useInfiniteQuery.type.test.d.ts} +0 -0
- /package/build/lib/{setBatchUpdatesFn.d.ts → __tests__/useMutationState.test.d.ts} +0 -0
|
@@ -14,23 +14,14 @@ import {
|
|
|
14
14
|
} from '..'
|
|
15
15
|
import { createQueryClient, setIsServer, sleep } from './utils'
|
|
16
16
|
|
|
17
|
-
const isReact18 = () => (process.env.REACTJS_VERSION || '18') === '18'
|
|
18
|
-
|
|
19
17
|
const ReactHydrate = (element: React.ReactElement, container: Element) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
26
|
-
return () => {
|
|
27
|
-
root.unmount()
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
ReactDOM.hydrate(element, container)
|
|
18
|
+
let root: any
|
|
19
|
+
ReactDOMTestUtils.act(() => {
|
|
20
|
+
// @ts-expect-error
|
|
21
|
+
root = ReactDOM.hydrateRoot(container, element)
|
|
22
|
+
})
|
|
32
23
|
return () => {
|
|
33
|
-
|
|
24
|
+
root.unmount()
|
|
34
25
|
}
|
|
35
26
|
}
|
|
36
27
|
|
|
@@ -58,9 +49,6 @@ describe('Server side rendering with de/rehydration', () => {
|
|
|
58
49
|
const consoleMock = jest.spyOn(console, 'error')
|
|
59
50
|
consoleMock.mockImplementation(() => undefined)
|
|
60
51
|
|
|
61
|
-
if (!isReact18()) {
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
52
|
const fetchDataSuccess = jest.fn<
|
|
65
53
|
ReturnType<typeof fetchData>,
|
|
66
54
|
Parameters<typeof fetchData>
|
|
@@ -68,7 +56,10 @@ describe('Server side rendering with de/rehydration', () => {
|
|
|
68
56
|
|
|
69
57
|
// -- Shared part --
|
|
70
58
|
function SuccessComponent() {
|
|
71
|
-
const result = useQuery(
|
|
59
|
+
const result = useQuery({
|
|
60
|
+
queryKey: ['success'],
|
|
61
|
+
queryFn: () => fetchDataSuccess('success!'),
|
|
62
|
+
})
|
|
72
63
|
return (
|
|
73
64
|
<PrintStateComponent componentName="SuccessComponent" result={result} />
|
|
74
65
|
)
|
|
@@ -81,9 +72,10 @@ describe('Server side rendering with de/rehydration', () => {
|
|
|
81
72
|
const prefetchClient = createQueryClient({
|
|
82
73
|
queryCache: prefetchCache,
|
|
83
74
|
})
|
|
84
|
-
await prefetchClient.prefetchQuery(
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
await prefetchClient.prefetchQuery({
|
|
76
|
+
queryKey: ['success'],
|
|
77
|
+
queryFn: () => fetchDataSuccess('success'),
|
|
78
|
+
})
|
|
87
79
|
const dehydratedStateServer = dehydrate(prefetchClient)
|
|
88
80
|
const renderCache = new QueryCache()
|
|
89
81
|
const renderClient = createQueryClient({
|
|
@@ -138,16 +130,15 @@ describe('Server side rendering with de/rehydration', () => {
|
|
|
138
130
|
const consoleMock = jest.spyOn(console, 'error')
|
|
139
131
|
consoleMock.mockImplementation(() => undefined)
|
|
140
132
|
|
|
141
|
-
if (!isReact18()) {
|
|
142
|
-
return
|
|
143
|
-
}
|
|
144
133
|
const fetchDataError = jest.fn(() => {
|
|
145
134
|
throw new Error('fetchDataError')
|
|
146
135
|
})
|
|
147
136
|
|
|
148
137
|
// -- Shared part --
|
|
149
138
|
function ErrorComponent() {
|
|
150
|
-
const result = useQuery(
|
|
139
|
+
const result = useQuery({
|
|
140
|
+
queryKey: ['error'],
|
|
141
|
+
queryFn: () => fetchDataError(),
|
|
151
142
|
retry: false,
|
|
152
143
|
})
|
|
153
144
|
return (
|
|
@@ -161,7 +152,10 @@ describe('Server side rendering with de/rehydration', () => {
|
|
|
161
152
|
const prefetchClient = createQueryClient({
|
|
162
153
|
queryCache: prefetchCache,
|
|
163
154
|
})
|
|
164
|
-
await prefetchClient.prefetchQuery(
|
|
155
|
+
await prefetchClient.prefetchQuery({
|
|
156
|
+
queryKey: ['error'],
|
|
157
|
+
queryFn: () => fetchDataError(),
|
|
158
|
+
})
|
|
165
159
|
const dehydratedStateServer = dehydrate(prefetchClient)
|
|
166
160
|
const renderCache = new QueryCache()
|
|
167
161
|
const renderClient = createQueryClient({
|
|
@@ -178,7 +172,7 @@ describe('Server side rendering with de/rehydration', () => {
|
|
|
178
172
|
setIsServer(false)
|
|
179
173
|
|
|
180
174
|
const expectedMarkup =
|
|
181
|
-
'ErrorComponent - status:
|
|
175
|
+
'ErrorComponent - status:pending fetching:true data:undefined'
|
|
182
176
|
|
|
183
177
|
expect(markup).toBe(expectedMarkup)
|
|
184
178
|
|
|
@@ -216,9 +210,6 @@ describe('Server side rendering with de/rehydration', () => {
|
|
|
216
210
|
const consoleMock = jest.spyOn(console, 'error')
|
|
217
211
|
consoleMock.mockImplementation(() => undefined)
|
|
218
212
|
|
|
219
|
-
if (!isReact18()) {
|
|
220
|
-
return
|
|
221
|
-
}
|
|
222
213
|
const fetchDataSuccess = jest.fn<
|
|
223
214
|
ReturnType<typeof fetchData>,
|
|
224
215
|
Parameters<typeof fetchData>
|
|
@@ -226,7 +217,10 @@ describe('Server side rendering with de/rehydration', () => {
|
|
|
226
217
|
|
|
227
218
|
// -- Shared part --
|
|
228
219
|
function SuccessComponent() {
|
|
229
|
-
const result = useQuery(
|
|
220
|
+
const result = useQuery({
|
|
221
|
+
queryKey: ['success'],
|
|
222
|
+
queryFn: () => fetchDataSuccess('success!'),
|
|
223
|
+
})
|
|
230
224
|
return (
|
|
231
225
|
<PrintStateComponent componentName="SuccessComponent" result={result} />
|
|
232
226
|
)
|
|
@@ -249,7 +243,7 @@ describe('Server side rendering with de/rehydration', () => {
|
|
|
249
243
|
setIsServer(false)
|
|
250
244
|
|
|
251
245
|
const expectedMarkup =
|
|
252
|
-
'SuccessComponent - status:
|
|
246
|
+
'SuccessComponent - status:pending fetching:true data:undefined'
|
|
253
247
|
|
|
254
248
|
expect(markup).toBe(expectedMarkup)
|
|
255
249
|
|
|
@@ -17,7 +17,7 @@ describe('Server Side Rendering', () => {
|
|
|
17
17
|
const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
|
|
18
18
|
|
|
19
19
|
function Page() {
|
|
20
|
-
const query = useQuery(key, queryFn)
|
|
20
|
+
const query = useQuery({ queryKey: key, queryFn })
|
|
21
21
|
|
|
22
22
|
const content = `status ${query.status}`
|
|
23
23
|
|
|
@@ -34,7 +34,7 @@ describe('Server Side Rendering', () => {
|
|
|
34
34
|
</QueryClientProvider>,
|
|
35
35
|
)
|
|
36
36
|
|
|
37
|
-
expect(markup).toContain('status
|
|
37
|
+
expect(markup).toContain('status pending')
|
|
38
38
|
expect(queryFn).toHaveBeenCalledTimes(0)
|
|
39
39
|
queryCache.clear()
|
|
40
40
|
})
|
|
@@ -44,9 +44,12 @@ describe('Server Side Rendering', () => {
|
|
|
44
44
|
const queryClient = createQueryClient({ queryCache })
|
|
45
45
|
const key = queryKey()
|
|
46
46
|
const fetchFn = () => Promise.resolve('data')
|
|
47
|
-
const data = await queryClient.fetchQuery(
|
|
47
|
+
const data = await queryClient.fetchQuery({
|
|
48
|
+
queryKey: key,
|
|
49
|
+
queryFn: fetchFn,
|
|
50
|
+
})
|
|
48
51
|
expect(data).toBe('data')
|
|
49
|
-
expect(queryCache.find(key)?.state.data).toBe('data')
|
|
52
|
+
expect(queryCache.find({ queryKey: key })?.state.data).toBe('data')
|
|
50
53
|
queryCache.clear()
|
|
51
54
|
})
|
|
52
55
|
|
|
@@ -60,7 +63,7 @@ describe('Server Side Rendering', () => {
|
|
|
60
63
|
})
|
|
61
64
|
|
|
62
65
|
function Page() {
|
|
63
|
-
const query = useQuery(key, queryFn)
|
|
66
|
+
const query = useQuery({ queryKey: key, queryFn })
|
|
64
67
|
|
|
65
68
|
const content = `status ${query.status}`
|
|
66
69
|
|
|
@@ -71,7 +74,7 @@ describe('Server Side Rendering', () => {
|
|
|
71
74
|
)
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
await queryClient.prefetchQuery(key, queryFn)
|
|
77
|
+
await queryClient.prefetchQuery({ queryKey: key, queryFn })
|
|
75
78
|
|
|
76
79
|
const markup = renderToString(
|
|
77
80
|
<QueryClientProvider client={queryClient}>
|
|
@@ -92,7 +95,9 @@ describe('Server Side Rendering', () => {
|
|
|
92
95
|
|
|
93
96
|
function Page() {
|
|
94
97
|
const [page, setPage] = React.useState(1)
|
|
95
|
-
const { data } = useQuery(
|
|
98
|
+
const { data } = useQuery({
|
|
99
|
+
queryKey: [key, page],
|
|
100
|
+
queryFn: async () => page,
|
|
96
101
|
initialData: 1,
|
|
97
102
|
})
|
|
98
103
|
|
|
@@ -126,7 +131,12 @@ describe('Server Side Rendering', () => {
|
|
|
126
131
|
})
|
|
127
132
|
|
|
128
133
|
function Page() {
|
|
129
|
-
const query = useInfiniteQuery(
|
|
134
|
+
const query = useInfiniteQuery({
|
|
135
|
+
queryKey: key,
|
|
136
|
+
queryFn,
|
|
137
|
+
getNextPageParam: () => undefined,
|
|
138
|
+
defaultPageParam: 0,
|
|
139
|
+
})
|
|
130
140
|
return (
|
|
131
141
|
<ul>
|
|
132
142
|
{query.data?.pages.map((page) => (
|
|
@@ -136,7 +146,11 @@ describe('Server Side Rendering', () => {
|
|
|
136
146
|
)
|
|
137
147
|
}
|
|
138
148
|
|
|
139
|
-
await queryClient.prefetchInfiniteQuery(
|
|
149
|
+
await queryClient.prefetchInfiniteQuery({
|
|
150
|
+
queryKey: key,
|
|
151
|
+
queryFn,
|
|
152
|
+
defaultPageParam: 0,
|
|
153
|
+
})
|
|
140
154
|
|
|
141
155
|
const markup = renderToString(
|
|
142
156
|
<QueryClientProvider client={queryClient}>
|