Skip to content

Commit 87188c4

Browse files
committed
fix(ssr): hydration mismatch with keepPreviousResult
1 parent a9c6012 commit 87188c4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/vue-apollo-composable/src/useQuery.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export function useQueryImpl<
222222
let observer: ObservableSubscription | undefined
223223
let started = false
224224
let ignoreNextResult = false
225+
let firstStart = true
225226

226227
/**
227228
* Starts watching the query
@@ -257,7 +258,7 @@ export function useQueryImpl<
257258

258259
// Make the cache data available to the component immediately
259260
// This prevents SSR hydration mismatches
260-
if (!isServer && !currentOptions.value?.keepPreviousResult && (currentOptions.value?.fetchPolicy !== 'no-cache' || currentOptions.value.notifyOnNetworkStatusChange)) {
261+
if (!isServer && (firstStart || !currentOptions.value?.keepPreviousResult) && (currentOptions.value?.fetchPolicy !== 'no-cache' || currentOptions.value.notifyOnNetworkStatusChange)) {
261262
const currentResult = query.value.getCurrentResult(false)
262263

263264
if (!currentResult.loading || currentResult.partial || currentOptions.value?.notifyOnNetworkStatusChange) {
@@ -274,6 +275,8 @@ export function useQueryImpl<
274275
addSubscribeToMore(item)
275276
}
276277
}
278+
279+
firstStart = false
277280
}
278281

279282
function startQuerySubscription () {

0 commit comments

Comments
 (0)