Skip to content

Commit 1986127

Browse files
feat(hydration): move hydration utilities to core, keeping old exports (TanStack#2497)
1 parent 21f7b89 commit 1986127

File tree

8 files changed

+45
-17
lines changed

8 files changed

+45
-17
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { QueryClient } from '../core/queryClient'
2-
import type { Query, QueryState } from '../core/query'
1+
import type { QueryClient } from './queryClient'
2+
import type { Query, QueryState } from './query'
33
import type {
44
MutationKey,
55
MutationOptions,
66
QueryKey,
77
QueryOptions,
8-
} from '../core/types'
9-
import type { Mutation, MutationState } from '../core/mutation'
8+
} from './types'
9+
import type { Mutation, MutationState } from './mutation'
1010

1111
// TYPES
1212

src/core/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ export { focusManager } from './focusManager'
1212
export { onlineManager } from './onlineManager'
1313
export { hashQueryKey, isError } from './utils'
1414
export { isCancelledError } from './retryer'
15+
export { dehydrate, hydrate } from './hydration'
1516

1617
// Types
1718
export * from './types'
1819
export type { Query } from './query'
1920
export type { Logger } from './logger'
21+
export type {
22+
DehydrateOptions,
23+
DehydratedState,
24+
HydrateOptions,
25+
ShouldDehydrateMutationFunction,
26+
ShouldDehydrateQueryFunction,
27+
} from './hydration'
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mockNavigatorOnLine, sleep } from '../../react/tests/utils'
2-
import { QueryCache, QueryClient } from '../..'
2+
import { QueryCache } from '../queryCache'
3+
import { QueryClient } from '../queryClient'
34
import { dehydrate, hydrate } from '../hydration'
45

56
async function fetchData<TData>(value: TData, ms?: number): Promise<TData> {

src/hydration/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
export { dehydrate, hydrate } from './hydration'
2-
export { useHydrate, Hydrate } from './react'
1+
// This package once contained these functions, but they have now been moved
2+
// into the core and react packages.
3+
// They are re-exported here to avoid a breaking change, but this package
4+
// should be considered deprecated and removed in a future major version.
5+
export { dehydrate, hydrate, useHydrate, Hydrate } from 'react-query'
36

47
// Types
58
export type {
69
DehydrateOptions,
710
DehydratedState,
811
HydrateOptions,
12+
ShouldDehydrateMutationFunction,
913
ShouldDehydrateQueryFunction,
10-
} from './hydration'
11-
export type { HydrateProps } from './react'
14+
} from '../core/hydration'
15+
export type { HydrateProps } from '../react/Hydrate'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22

3-
import { useQueryClient } from 'react-query'
4-
import { hydrate, HydrateOptions } from './hydration'
3+
import { hydrate, HydrateOptions } from '../core'
4+
import { useQueryClient } from './QueryClientProvider'
55

66
export function useHydrate(state: unknown, options?: HydrateOptions) {
77
const queryClient = useQueryClient()

src/react/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ export { useMutation } from './useMutation'
1313
export { useQuery } from './useQuery'
1414
export { useQueries } from './useQueries'
1515
export { useInfiniteQuery } from './useInfiniteQuery'
16+
export { useHydrate, Hydrate } from './Hydrate'
1617

1718
// Types
1819
export * from './types'
1920
export type { QueryClientProviderProps } from './QueryClientProvider'
2021
export type { QueryErrorResetBoundaryProps } from './QueryErrorResetBoundary'
22+
export type { HydrateProps } from './Hydrate'
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import React from 'react'
22
import { render } from '@testing-library/react'
33

4-
import { QueryClient, QueryClientProvider, QueryCache, useQuery } from '../..'
5-
import { dehydrate, useHydrate, Hydrate } from '../'
6-
import { sleep } from '../../react/tests/utils'
4+
import {
5+
QueryClient,
6+
QueryClientProvider,
7+
QueryCache,
8+
useQuery,
9+
dehydrate,
10+
useHydrate,
11+
Hydrate,
12+
} from '../..'
13+
import { sleep } from './utils'
714

815
describe('React hydration', () => {
916
const fetchData: (value: string) => Promise<string> = value =>
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ import React from 'react'
22
import ReactDOM from 'react-dom'
33
import ReactDOMServer from 'react-dom/server'
44

5-
import { useQuery, QueryClient, QueryClientProvider, QueryCache } from '../..'
6-
import { dehydrate, hydrate } from '../'
5+
import {
6+
useQuery,
7+
QueryClient,
8+
QueryClientProvider,
9+
QueryCache,
10+
dehydrate,
11+
hydrate,
12+
} from '../..'
713
import * as utils from '../../core/utils'
8-
import { mockConsoleError, sleep } from '../../react/tests/utils'
14+
import { mockConsoleError, sleep } from './utils'
915

1016
// This monkey-patches the isServer-value from utils,
1117
// so that we can pretend to be in a server environment

0 commit comments

Comments
 (0)