Skip to content

Commit

Permalink
feat(hydration): move hydration utilities to core, keeping old exports (
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianOsipiuk authored Sep 7, 2021
1 parent 21f7b89 commit 1986127
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/hydration/hydration.ts → src/core/hydration.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { QueryClient } from '../core/queryClient'
import type { Query, QueryState } from '../core/query'
import type { QueryClient } from './queryClient'
import type { Query, QueryState } from './query'
import type {
MutationKey,
MutationOptions,
QueryKey,
QueryOptions,
} from '../core/types'
import type { Mutation, MutationState } from '../core/mutation'
} from './types'
import type { Mutation, MutationState } from './mutation'

// TYPES

Expand Down
8 changes: 8 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ export { focusManager } from './focusManager'
export { onlineManager } from './onlineManager'
export { hashQueryKey, isError } from './utils'
export { isCancelledError } from './retryer'
export { dehydrate, hydrate } from './hydration'

// Types
export * from './types'
export type { Query } from './query'
export type { Logger } from './logger'
export type {
DehydrateOptions,
DehydratedState,
HydrateOptions,
ShouldDehydrateMutationFunction,
ShouldDehydrateQueryFunction,
} from './hydration'
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mockNavigatorOnLine, sleep } from '../../react/tests/utils'
import { QueryCache, QueryClient } from '../..'
import { QueryCache } from '../queryCache'
import { QueryClient } from '../queryClient'
import { dehydrate, hydrate } from '../hydration'

async function fetchData<TData>(value: TData, ms?: number): Promise<TData> {
Expand Down
12 changes: 8 additions & 4 deletions src/hydration/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
export { dehydrate, hydrate } from './hydration'
export { useHydrate, Hydrate } from './react'
// This package once contained these functions, but they have now been moved
// into the core and react packages.
// They are re-exported here to avoid a breaking change, but this package
// should be considered deprecated and removed in a future major version.
export { dehydrate, hydrate, useHydrate, Hydrate } from 'react-query'

// Types
export type {
DehydrateOptions,
DehydratedState,
HydrateOptions,
ShouldDehydrateMutationFunction,
ShouldDehydrateQueryFunction,
} from './hydration'
export type { HydrateProps } from './react'
} from '../core/hydration'
export type { HydrateProps } from '../react/Hydrate'
4 changes: 2 additions & 2 deletions src/hydration/react.tsx → src/react/Hydrate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

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

export function useHydrate(state: unknown, options?: HydrateOptions) {
const queryClient = useQueryClient()
Expand Down
2 changes: 2 additions & 0 deletions src/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export { useMutation } from './useMutation'
export { useQuery } from './useQuery'
export { useQueries } from './useQueries'
export { useInfiniteQuery } from './useInfiniteQuery'
export { useHydrate, Hydrate } from './Hydrate'

// Types
export * from './types'
export type { QueryClientProviderProps } from './QueryClientProvider'
export type { QueryErrorResetBoundaryProps } from './QueryErrorResetBoundary'
export type { HydrateProps } from './Hydrate'
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import React from 'react'
import { render } from '@testing-library/react'

import { QueryClient, QueryClientProvider, QueryCache, useQuery } from '../..'
import { dehydrate, useHydrate, Hydrate } from '../'
import { sleep } from '../../react/tests/utils'
import {
QueryClient,
QueryClientProvider,
QueryCache,
useQuery,
dehydrate,
useHydrate,
Hydrate,
} from '../..'
import { sleep } from './utils'

describe('React hydration', () => {
const fetchData: (value: string) => Promise<string> = value =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import React from 'react'
import ReactDOM from 'react-dom'
import ReactDOMServer from 'react-dom/server'

import { useQuery, QueryClient, QueryClientProvider, QueryCache } from '../..'
import { dehydrate, hydrate } from '../'
import {
useQuery,
QueryClient,
QueryClientProvider,
QueryCache,
dehydrate,
hydrate,
} from '../..'
import * as utils from '../../core/utils'
import { mockConsoleError, sleep } from '../../react/tests/utils'
import { mockConsoleError, sleep } from './utils'

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

0 comments on commit 1986127

Please sign in to comment.