11import { QueryClient } from '../core'
22import { getLogger } from '../core/logger'
3- import { dehydrate , DehydratedState , hydrate } from '../hydration'
3+ import { dehydrate , DehydratedState , DehydrateOptions , HydrateOptions , hydrate } from '../hydration'
44import { Promisable } from 'type-fest'
55
66export interface Persistor {
@@ -28,21 +28,27 @@ export interface PersistQueryClientOptions {
2828 /** A unique string that can be used to forcefully
2929 * invalidate existing caches if they do not share the same buster string */
3030 buster ?: string
31+ /** The options passed to the hydrate function */
32+ hydrateOptions ?: HydrateOptions
33+ /** The options passed to the dehydrate function */
34+ dehydrateOptions ?: DehydrateOptions
3135}
3236
3337export async function persistQueryClient ( {
3438 queryClient,
3539 persistor,
3640 maxAge = 1000 * 60 * 60 * 24 ,
3741 buster = '' ,
42+ hydrateOptions,
43+ dehydrateOptions,
3844} : PersistQueryClientOptions ) {
3945 if ( typeof window !== 'undefined' ) {
4046 // Subscribe to changes
4147 const saveClient = ( ) => {
4248 const persistClient : PersistedClient = {
4349 buster,
4450 timestamp : Date . now ( ) ,
45- clientState : dehydrate ( queryClient ) ,
51+ clientState : dehydrate ( queryClient , dehydrateOptions ) ,
4652 }
4753
4854 persistor . persistClient ( persistClient )
@@ -59,7 +65,7 @@ export async function persistQueryClient({
5965 if ( expired || busted ) {
6066 persistor . removeClient ( )
6167 } else {
62- hydrate ( queryClient , persistedClient . clientState )
68+ hydrate ( queryClient , persistedClient . clientState , hydrateOptions )
6369 }
6470 } else {
6571 persistor . removeClient ( )
0 commit comments