@@ -196,6 +196,7 @@ export function useQueryImpl<
196
196
const query : Ref < ObservableQuery < TResult , TVariables > | null | undefined > = ref ( )
197
197
let observer : ObservableSubscription | undefined
198
198
let started = false
199
+ let ignoreNextResult = false
199
200
200
201
/**
201
202
* Starts watching the query
@@ -228,6 +229,20 @@ export function useQueryImpl<
228
229
229
230
startQuerySubscription ( )
230
231
232
+ // Make the cache data available to the component immediately
233
+ // This prevents SSR hydration mismatches
234
+ if ( ! isServer && ( currentOptions . value ?. fetchPolicy !== 'no-cache' || currentOptions . value . notifyOnNetworkStatusChange ) ) {
235
+ const currentResult = query . value . getCurrentResult ( false )
236
+
237
+ if ( ! currentResult . loading || currentResult . partial || currentOptions . value ?. notifyOnNetworkStatusChange ) {
238
+ onNextResult ( currentResult )
239
+ ignoreNextResult = true
240
+ } else if ( currentResult . error ) {
241
+ onError ( currentResult . error )
242
+ ignoreNextResult = true
243
+ }
244
+ }
245
+
231
246
if ( ! isServer ) {
232
247
for ( const item of subscribeToMoreItems ) {
233
248
addSubscribeToMore ( item )
@@ -240,13 +255,19 @@ export function useQueryImpl<
240
255
if ( ! query . value ) return
241
256
242
257
// Create subscription
258
+ ignoreNextResult = false
243
259
observer = query . value . subscribe ( {
244
260
next : onNextResult ,
245
261
error : onError ,
246
262
} )
247
263
}
248
264
249
265
function onNextResult ( queryResult : ApolloQueryResult < TResult > ) {
266
+ if ( ignoreNextResult ) {
267
+ ignoreNextResult = false
268
+ return
269
+ }
270
+
250
271
// Remove any previous error that may still be present from the last fetch (so result handlers
251
272
// don't receive old errors that may not even be applicable anymore).
252
273
error . value = null
@@ -273,6 +294,11 @@ export function useQueryImpl<
273
294
}
274
295
275
296
function onError ( queryError : unknown ) {
297
+ if ( ignoreNextResult ) {
298
+ ignoreNextResult = false
299
+ return
300
+ }
301
+
276
302
// any error should already be an ApolloError, but we make sure
277
303
const apolloError = toApolloError ( queryError )
278
304
const client = resolveClient ( currentOptions . value ?. clientId )
0 commit comments