@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-alpha.1",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,37 +21,25 @@
|
|
|
21
21
|
},
|
|
22
22
|
"./package.json": "./package.json"
|
|
23
23
|
},
|
|
24
|
-
"sideEffects":
|
|
25
|
-
"./src/setBatchUpdatesFn.ts"
|
|
26
|
-
],
|
|
24
|
+
"sideEffects": false,
|
|
27
25
|
"files": [
|
|
28
26
|
"build/lib/*",
|
|
29
27
|
"build/umd/*",
|
|
30
|
-
"src"
|
|
31
|
-
"codemods",
|
|
32
|
-
"!codemods/jest.config.js",
|
|
33
|
-
"!codemods/**/__testfixtures__",
|
|
34
|
-
"!codemods/**/__tests__"
|
|
28
|
+
"src"
|
|
35
29
|
],
|
|
36
30
|
"devDependencies": {
|
|
37
|
-
"@types/jscodeshift": "^0.11.3",
|
|
38
31
|
"@types/react": "^18.0.14",
|
|
39
32
|
"@types/react-dom": "^18.0.5",
|
|
40
|
-
"@types/use-sync-external-store": "^0.0.3",
|
|
41
33
|
"react": "^18.2.0",
|
|
42
|
-
"react-17": "npm:react@^17.0.2",
|
|
43
34
|
"react-dom": "^18.2.0",
|
|
44
|
-
"react-dom-17": "npm:react-dom@^17.0.2",
|
|
45
|
-
"jscodeshift": "^0.13.1",
|
|
46
35
|
"react-error-boundary": "^3.1.4"
|
|
47
36
|
},
|
|
48
37
|
"dependencies": {
|
|
49
|
-
"
|
|
50
|
-
"@tanstack/query-core": "4.24.10"
|
|
38
|
+
"@tanstack/query-core": "5.0.0-alpha.1"
|
|
51
39
|
},
|
|
52
40
|
"peerDependencies": {
|
|
53
|
-
"react": "^
|
|
54
|
-
"react-dom": "^
|
|
41
|
+
"react": "^18.0.0",
|
|
42
|
+
"react-dom": "^18.0.0",
|
|
55
43
|
"react-native": "*"
|
|
56
44
|
},
|
|
57
45
|
"peerDependenciesMeta": {
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
-
import type { HydrateOptions } from '@tanstack/query-core'
|
|
4
|
+
import type { HydrateOptions, QueryClient } from '@tanstack/query-core'
|
|
5
5
|
import { hydrate } from '@tanstack/query-core'
|
|
6
6
|
import { useQueryClient } from './QueryClientProvider'
|
|
7
|
-
import type { ContextOptions } from './types'
|
|
8
7
|
|
|
9
|
-
export
|
|
10
|
-
state
|
|
11
|
-
options
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export interface HydrationBoundaryProps {
|
|
9
|
+
state?: unknown
|
|
10
|
+
options?: HydrateOptions
|
|
11
|
+
children?: React.ReactNode
|
|
12
|
+
queryClient?: QueryClient
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const HydrationBoundary = ({
|
|
16
|
+
children,
|
|
17
|
+
options = {},
|
|
18
|
+
state,
|
|
19
|
+
queryClient,
|
|
20
|
+
}: HydrationBoundaryProps) => {
|
|
21
|
+
const client = useQueryClient(queryClient)
|
|
14
22
|
|
|
15
23
|
const optionsRef = React.useRef(options)
|
|
16
24
|
optionsRef.current = options
|
|
@@ -21,18 +29,9 @@ export function useHydrate(
|
|
|
21
29
|
// hydrate can and should be run *during* render here for SSR to work properly
|
|
22
30
|
React.useMemo(() => {
|
|
23
31
|
if (state) {
|
|
24
|
-
hydrate(
|
|
32
|
+
hydrate(client, state, optionsRef.current)
|
|
25
33
|
}
|
|
26
|
-
}, [
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface HydrateProps {
|
|
30
|
-
state?: unknown
|
|
31
|
-
options?: HydrateOptions
|
|
32
|
-
children?: React.ReactNode
|
|
33
|
-
}
|
|
34
|
+
}, [client, state])
|
|
34
35
|
|
|
35
|
-
export const Hydrate = ({ children, options, state }: HydrateProps) => {
|
|
36
|
-
useHydrate(state, options)
|
|
37
36
|
return children as React.ReactElement
|
|
38
37
|
}
|
|
@@ -2,77 +2,33 @@
|
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
4
|
import type { QueryClient } from '@tanstack/query-core'
|
|
5
|
-
import type { ContextOptions } from './types'
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
interface Window {
|
|
9
|
-
ReactQueryClientContext?: React.Context<QueryClient | undefined>
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const defaultContext = React.createContext<QueryClient | undefined>(
|
|
6
|
+
export const QueryClientContext = React.createContext<QueryClient | undefined>(
|
|
14
7
|
undefined,
|
|
15
8
|
)
|
|
16
|
-
const QueryClientSharingContext = React.createContext<boolean>(false)
|
|
17
9
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// instance of the context across the window
|
|
21
|
-
// to ensure that if React Query is used across
|
|
22
|
-
// different bundles or microfrontends they will
|
|
23
|
-
// all use the same **instance** of context, regardless
|
|
24
|
-
// of module scoping.
|
|
25
|
-
function getQueryClientContext(
|
|
26
|
-
context: React.Context<QueryClient | undefined> | undefined,
|
|
27
|
-
contextSharing: boolean,
|
|
28
|
-
) {
|
|
29
|
-
if (context) {
|
|
30
|
-
return context
|
|
31
|
-
}
|
|
32
|
-
if (contextSharing && typeof window !== 'undefined') {
|
|
33
|
-
if (!window.ReactQueryClientContext) {
|
|
34
|
-
window.ReactQueryClientContext = defaultContext
|
|
35
|
-
}
|
|
10
|
+
export const useQueryClient = (queryClient?: QueryClient) => {
|
|
11
|
+
const client = React.useContext(QueryClientContext)
|
|
36
12
|
|
|
37
|
-
|
|
13
|
+
if (queryClient) {
|
|
14
|
+
return queryClient
|
|
38
15
|
}
|
|
39
16
|
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const useQueryClient = ({ context }: ContextOptions = {}) => {
|
|
44
|
-
const queryClient = React.useContext(
|
|
45
|
-
getQueryClientContext(context, React.useContext(QueryClientSharingContext)),
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
if (!queryClient) {
|
|
17
|
+
if (!client) {
|
|
49
18
|
throw new Error('No QueryClient set, use QueryClientProvider to set one')
|
|
50
19
|
}
|
|
51
20
|
|
|
52
|
-
return
|
|
21
|
+
return client
|
|
53
22
|
}
|
|
54
23
|
|
|
55
|
-
type
|
|
24
|
+
export type QueryClientProviderProps = {
|
|
56
25
|
client: QueryClient
|
|
57
26
|
children?: React.ReactNode
|
|
58
27
|
}
|
|
59
|
-
type QueryClientProviderPropsWithContext = ContextOptions & {
|
|
60
|
-
contextSharing?: never
|
|
61
|
-
} & QueryClientProviderPropsBase
|
|
62
|
-
type QueryClientProviderPropsWithContextSharing = {
|
|
63
|
-
context?: never
|
|
64
|
-
contextSharing?: boolean
|
|
65
|
-
} & QueryClientProviderPropsBase
|
|
66
|
-
|
|
67
|
-
export type QueryClientProviderProps =
|
|
68
|
-
| QueryClientProviderPropsWithContext
|
|
69
|
-
| QueryClientProviderPropsWithContextSharing
|
|
70
28
|
|
|
71
29
|
export const QueryClientProvider = ({
|
|
72
30
|
client,
|
|
73
31
|
children,
|
|
74
|
-
context,
|
|
75
|
-
contextSharing = false,
|
|
76
32
|
}: QueryClientProviderProps): JSX.Element => {
|
|
77
33
|
React.useEffect(() => {
|
|
78
34
|
client.mount()
|
|
@@ -81,19 +37,9 @@ export const QueryClientProvider = ({
|
|
|
81
37
|
}
|
|
82
38
|
}, [client])
|
|
83
39
|
|
|
84
|
-
if (process.env.NODE_ENV !== 'production' && contextSharing) {
|
|
85
|
-
client
|
|
86
|
-
.getLogger()
|
|
87
|
-
.error(
|
|
88
|
-
`The contextSharing option has been deprecated and will be removed in the next major version`,
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const Context = getQueryClientContext(context, contextSharing)
|
|
93
|
-
|
|
94
40
|
return (
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
</
|
|
41
|
+
<QueryClientContext.Provider value={client}>
|
|
42
|
+
{children}
|
|
43
|
+
</QueryClientContext.Provider>
|
|
98
44
|
)
|
|
99
45
|
}
|
|
@@ -7,8 +7,7 @@ import {
|
|
|
7
7
|
QueryCache,
|
|
8
8
|
useQuery,
|
|
9
9
|
dehydrate,
|
|
10
|
-
|
|
11
|
-
Hydrate,
|
|
10
|
+
HydrationBoundary,
|
|
12
11
|
} from '@tanstack/react-query'
|
|
13
12
|
import { createQueryClient, sleep } from './utils'
|
|
14
13
|
import * as coreModule from '@tanstack/query-core'
|
|
@@ -23,78 +22,81 @@ describe('React hydration', () => {
|
|
|
23
22
|
beforeAll(async () => {
|
|
24
23
|
const queryCache = new QueryCache()
|
|
25
24
|
const queryClient = createQueryClient({ queryCache })
|
|
26
|
-
await queryClient.prefetchQuery(
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
await queryClient.prefetchQuery({
|
|
26
|
+
queryKey: ['string'],
|
|
27
|
+
queryFn: () => dataQuery(['stringCached']),
|
|
28
|
+
})
|
|
29
29
|
const dehydrated = dehydrate(queryClient)
|
|
30
30
|
stringifiedState = JSON.stringify(dehydrated)
|
|
31
31
|
queryClient.clear()
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const queryClient = createQueryClient({ queryCache })
|
|
39
|
-
|
|
40
|
-
function Page() {
|
|
41
|
-
useHydrate(dehydratedState)
|
|
42
|
-
const { data } = useQuery(['string'], () => dataQuery(['string']))
|
|
43
|
-
return (
|
|
44
|
-
<div>
|
|
45
|
-
<h1>{data}</h1>
|
|
46
|
-
</div>
|
|
47
|
-
)
|
|
48
|
-
}
|
|
34
|
+
test('should hydrate queries to the cache on context', async () => {
|
|
35
|
+
const dehydratedState = JSON.parse(stringifiedState)
|
|
36
|
+
const queryCache = new QueryCache()
|
|
37
|
+
const queryClient = createQueryClient({ queryCache })
|
|
49
38
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
function Page() {
|
|
40
|
+
const { data } = useQuery({
|
|
41
|
+
queryKey: ['string'],
|
|
42
|
+
queryFn: () => dataQuery(['string']),
|
|
43
|
+
})
|
|
44
|
+
return (
|
|
45
|
+
<div>
|
|
46
|
+
<h1>{data}</h1>
|
|
47
|
+
</div>
|
|
54
48
|
)
|
|
49
|
+
}
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
const rendered = render(
|
|
52
|
+
<QueryClientProvider client={queryClient}>
|
|
53
|
+
<HydrationBoundary state={dehydratedState}>
|
|
54
|
+
<Page />
|
|
55
|
+
</HydrationBoundary>
|
|
56
|
+
</QueryClientProvider>,
|
|
57
|
+
)
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
await rendered.findByText('stringCached')
|
|
60
|
+
await rendered.findByText('string')
|
|
61
|
+
queryClient.clear()
|
|
62
|
+
})
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
test('should hydrate queries to the cache on custom context', async () => {
|
|
65
|
+
const queryCacheOuter = new QueryCache()
|
|
66
|
+
const queryCacheInner = new QueryCache()
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
const queryClientInner = new QueryClient({ queryCache: queryCacheInner })
|
|
69
|
+
const queryClientOuter = new QueryClient({ queryCache: queryCacheOuter })
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
const dehydratedState = JSON.parse(stringifiedState)
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
function Page() {
|
|
74
|
+
const { data } = useQuery({
|
|
75
|
+
queryKey: ['string'],
|
|
76
|
+
queryFn: () => dataQuery(['string']),
|
|
77
|
+
})
|
|
78
|
+
return (
|
|
79
|
+
<div>
|
|
80
|
+
<h1>{data}</h1>
|
|
81
|
+
</div>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
const rendered = render(
|
|
86
|
+
<QueryClientProvider client={queryClientOuter}>
|
|
87
|
+
<QueryClientProvider client={queryClientInner}>
|
|
88
|
+
<HydrationBoundary state={dehydratedState}>
|
|
87
89
|
<Page />
|
|
88
|
-
</
|
|
89
|
-
</QueryClientProvider
|
|
90
|
-
|
|
90
|
+
</HydrationBoundary>
|
|
91
|
+
</QueryClientProvider>
|
|
92
|
+
</QueryClientProvider>,
|
|
93
|
+
)
|
|
91
94
|
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
await rendered.findByText('stringCached')
|
|
96
|
+
await rendered.findByText('string')
|
|
94
97
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
})
|
|
98
|
+
queryClientInner.clear()
|
|
99
|
+
queryClientOuter.clear()
|
|
98
100
|
})
|
|
99
101
|
|
|
100
102
|
describe('ReactQueryCacheProvider with hydration support', () => {
|
|
@@ -104,7 +106,10 @@ describe('React hydration', () => {
|
|
|
104
106
|
const queryClient = createQueryClient({ queryCache })
|
|
105
107
|
|
|
106
108
|
function Page({ queryKey }: { queryKey: [string] }) {
|
|
107
|
-
const { data } = useQuery(
|
|
109
|
+
const { data } = useQuery({
|
|
110
|
+
queryKey,
|
|
111
|
+
queryFn: () => dataQuery(queryKey),
|
|
112
|
+
})
|
|
108
113
|
return (
|
|
109
114
|
<div>
|
|
110
115
|
<h1>{data}</h1>
|
|
@@ -114,9 +119,9 @@ describe('React hydration', () => {
|
|
|
114
119
|
|
|
115
120
|
const rendered = render(
|
|
116
121
|
<QueryClientProvider client={queryClient}>
|
|
117
|
-
<
|
|
122
|
+
<HydrationBoundary state={dehydratedState}>
|
|
118
123
|
<Page queryKey={['string']} />
|
|
119
|
-
</
|
|
124
|
+
</HydrationBoundary>
|
|
120
125
|
</QueryClientProvider>,
|
|
121
126
|
)
|
|
122
127
|
|
|
@@ -126,21 +131,23 @@ describe('React hydration', () => {
|
|
|
126
131
|
const intermediateClient = createQueryClient({
|
|
127
132
|
queryCache: intermediateCache,
|
|
128
133
|
})
|
|
129
|
-
await intermediateClient.prefetchQuery(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
await intermediateClient.prefetchQuery({
|
|
135
|
+
queryKey: ['string'],
|
|
136
|
+
queryFn: () => dataQuery(['should change']),
|
|
137
|
+
})
|
|
138
|
+
await intermediateClient.prefetchQuery({
|
|
139
|
+
queryKey: ['added string'],
|
|
140
|
+
queryFn: () => dataQuery(['added string']),
|
|
141
|
+
})
|
|
135
142
|
const dehydrated = dehydrate(intermediateClient)
|
|
136
143
|
intermediateClient.clear()
|
|
137
144
|
|
|
138
145
|
rendered.rerender(
|
|
139
146
|
<QueryClientProvider client={queryClient}>
|
|
140
|
-
<
|
|
147
|
+
<HydrationBoundary state={dehydrated}>
|
|
141
148
|
<Page queryKey={['string']} />
|
|
142
149
|
<Page queryKey={['added string']} />
|
|
143
|
-
</
|
|
150
|
+
</HydrationBoundary>
|
|
144
151
|
</QueryClientProvider>,
|
|
145
152
|
)
|
|
146
153
|
|
|
@@ -160,7 +167,10 @@ describe('React hydration', () => {
|
|
|
160
167
|
const queryClient = createQueryClient({ queryCache })
|
|
161
168
|
|
|
162
169
|
function Page() {
|
|
163
|
-
const { data } = useQuery(
|
|
170
|
+
const { data } = useQuery({
|
|
171
|
+
queryKey: ['string'],
|
|
172
|
+
queryFn: () => dataQuery(['string']),
|
|
173
|
+
})
|
|
164
174
|
return (
|
|
165
175
|
<div>
|
|
166
176
|
<h1>{data}</h1>
|
|
@@ -170,9 +180,9 @@ describe('React hydration', () => {
|
|
|
170
180
|
|
|
171
181
|
const rendered = render(
|
|
172
182
|
<QueryClientProvider client={queryClient}>
|
|
173
|
-
<
|
|
183
|
+
<HydrationBoundary state={dehydratedState}>
|
|
174
184
|
<Page />
|
|
175
|
-
</
|
|
185
|
+
</HydrationBoundary>
|
|
176
186
|
</QueryClientProvider>,
|
|
177
187
|
)
|
|
178
188
|
|
|
@@ -185,9 +195,9 @@ describe('React hydration', () => {
|
|
|
185
195
|
|
|
186
196
|
rendered.rerender(
|
|
187
197
|
<QueryClientProvider client={newClientQueryClient}>
|
|
188
|
-
<
|
|
198
|
+
<HydrationBoundary state={dehydratedState}>
|
|
189
199
|
<Page />
|
|
190
|
-
</
|
|
200
|
+
</HydrationBoundary>
|
|
191
201
|
</QueryClientProvider>,
|
|
192
202
|
)
|
|
193
203
|
|
|
@@ -206,13 +216,14 @@ describe('React hydration', () => {
|
|
|
206
216
|
const hydrateSpy = jest.spyOn(coreModule, 'hydrate')
|
|
207
217
|
|
|
208
218
|
function Page() {
|
|
209
|
-
useHydrate(null)
|
|
210
219
|
return null
|
|
211
220
|
}
|
|
212
221
|
|
|
213
222
|
render(
|
|
214
223
|
<QueryClientProvider client={queryClient}>
|
|
215
|
-
<
|
|
224
|
+
<HydrationBoundary state={null}>
|
|
225
|
+
<Page />
|
|
226
|
+
</HydrationBoundary>
|
|
216
227
|
</QueryClientProvider>,
|
|
217
228
|
)
|
|
218
229
|
|
|
@@ -229,13 +240,14 @@ describe('React hydration', () => {
|
|
|
229
240
|
const hydrateSpy = jest.spyOn(coreModule, 'hydrate')
|
|
230
241
|
|
|
231
242
|
function Page() {
|
|
232
|
-
useHydrate(undefined)
|
|
233
243
|
return null
|
|
234
244
|
}
|
|
235
245
|
|
|
236
246
|
render(
|
|
237
247
|
<QueryClientProvider client={queryClient}>
|
|
238
|
-
<
|
|
248
|
+
<HydrationBoundary state={undefined}>
|
|
249
|
+
<Page />
|
|
250
|
+
</HydrationBoundary>
|
|
239
251
|
</QueryClientProvider>,
|
|
240
252
|
)
|
|
241
253
|
|