1
1
import { QueryClient } from '../core'
2
2
import { getLogger } from '../core/logger'
3
- import { dehydrate , DehydratedState , hydrate } from '../hydration'
3
+ import { dehydrate , DehydratedState , DehydrateOptions , HydrateOptions , hydrate } from '../hydration'
4
4
import { Promisable } from 'type-fest'
5
5
6
6
export interface Persistor {
@@ -28,21 +28,27 @@ export interface PersistQueryClientOptions {
28
28
/** A unique string that can be used to forcefully
29
29
* invalidate existing caches if they do not share the same buster string */
30
30
buster ?: string
31
+ /** The options passed to the hydrate function */
32
+ hydrateOptions ?: HydrateOptions
33
+ /** The options passed to the dehydrate function */
34
+ dehydrateOptions ?: DehydrateOptions
31
35
}
32
36
33
37
export async function persistQueryClient ( {
34
38
queryClient,
35
39
persistor,
36
40
maxAge = 1000 * 60 * 60 * 24 ,
37
41
buster = '' ,
42
+ hydrateOptions,
43
+ dehydrateOptions,
38
44
} : PersistQueryClientOptions ) {
39
45
if ( typeof window !== 'undefined' ) {
40
46
// Subscribe to changes
41
47
const saveClient = ( ) => {
42
48
const persistClient : PersistedClient = {
43
49
buster,
44
50
timestamp : Date . now ( ) ,
45
- clientState : dehydrate ( queryClient ) ,
51
+ clientState : dehydrate ( queryClient , dehydrateOptions ) ,
46
52
}
47
53
48
54
persistor . persistClient ( persistClient )
@@ -59,7 +65,7 @@ export async function persistQueryClient({
59
65
if ( expired || busted ) {
60
66
persistor . removeClient ( )
61
67
} else {
62
- hydrate ( queryClient , persistedClient . clientState )
68
+ hydrate ( queryClient , persistedClient . clientState , hydrateOptions )
63
69
}
64
70
} else {
65
71
persistor . removeClient ( )
0 commit comments