@@ -139,19 +139,15 @@ export function hydrate(
139139 )
140140 } )
141141
142- queries . forEach ( ( dehydratedQuery ) => {
143- const query = queryCache . get ( dehydratedQuery . queryHash )
144-
145- // Reset fetch status to idle in the dehydrated state to avoid
146- // query being stuck in fetching state upon hydration
147- const dehydratedQueryState = {
148- ...dehydratedQuery . state ,
149- fetchStatus : 'idle' as const ,
150- }
142+ queries . forEach ( ( { queryKey, state, queryHash } ) => {
143+ const query = queryCache . get ( queryHash )
151144
152145 // Do not hydrate if an existing query exists with newer data
153146 if ( query ) {
154- if ( query . state . dataUpdatedAt < dehydratedQueryState . dataUpdatedAt ) {
147+ if ( query . state . dataUpdatedAt < state . dataUpdatedAt ) {
148+ // omit fetchStatus from dehydrated state
149+ // so that query stays in its current fetchStatus
150+ const { fetchStatus : _ignored , ...dehydratedQueryState } = state
155151 query . setState ( dehydratedQueryState )
156152 }
157153 return
@@ -162,10 +158,15 @@ export function hydrate(
162158 client ,
163159 {
164160 ...options ?. defaultOptions ?. queries ,
165- queryKey : dehydratedQuery . queryKey ,
166- queryHash : dehydratedQuery . queryHash ,
161+ queryKey,
162+ queryHash,
163+ } ,
164+ // Reset fetch status to idle to avoid
165+ // query being stuck in fetching state upon hydration
166+ {
167+ ...state ,
168+ fetchStatus : 'idle' ,
167169 } ,
168- dehydratedQueryState ,
169170 )
170171 } )
171172}
0 commit comments