File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -19,33 +19,30 @@ export const PersistQueryClientProvider = ({
19
19
} : PersistQueryClientProviderProps ) : JSX . Element => {
20
20
const [ isHydrating , setIsHydrating ] = React . useState ( true )
21
21
const refs = React . useRef ( { persistOptions, onSuccess } )
22
- const previousPromise = React . useRef ( Promise . resolve ( ) )
23
22
24
23
React . useEffect ( ( ) => {
25
24
refs . current = { persistOptions, onSuccess }
26
25
} )
27
26
28
27
React . useEffect ( ( ) => {
28
+ let isStale = false
29
29
setIsHydrating ( true )
30
30
const [ unsubscribe , promise ] = persistQueryClient ( {
31
31
...refs . current . persistOptions ,
32
32
queryClient : client ,
33
33
} )
34
34
35
- async function handlePersist ( ) {
36
- try {
37
- await previousPromise . current
38
- previousPromise . current = promise
39
- await promise
35
+ promise . then ( ( ) => {
36
+ if ( ! isStale ) {
40
37
refs . current . onSuccess ?.( )
41
- } finally {
42
38
setIsHydrating ( false )
43
39
}
44
- }
45
-
46
- void handlePersist ( )
40
+ } )
47
41
48
- return unsubscribe
42
+ return ( ) => {
43
+ isStale = true
44
+ unsubscribe ( )
45
+ }
49
46
} , [ client ] )
50
47
51
48
return (
You can’t perform that action at this time.
0 commit comments