fix(ssr): hydration mismatch with keepPreviousResult

This commit is contained in:
Guillaume Chau
2023-06-13 16:07:07 +02:00
parent a9c60128f6
commit 87188c49a1
@@ -222,6 +222,7 @@ export function useQueryImpl<
let observer: ObservableSubscription | undefined
let started = false
let ignoreNextResult = false
let firstStart = true
/**
* Starts watching the query
@@ -257,7 +258,7 @@ export function useQueryImpl<
// Make the cache data available to the component immediately
// This prevents SSR hydration mismatches
if (!isServer && !currentOptions.value?.keepPreviousResult && (currentOptions.value?.fetchPolicy !== 'no-cache' || currentOptions.value.notifyOnNetworkStatusChange)) {
if (!isServer && (firstStart || !currentOptions.value?.keepPreviousResult) && (currentOptions.value?.fetchPolicy !== 'no-cache' || currentOptions.value.notifyOnNetworkStatusChange)) {
const currentResult = query.value.getCurrentResult(false)
if (!currentResult.loading || currentResult.partial || currentOptions.value?.notifyOnNetworkStatusChange) {
@@ -274,6 +275,8 @@ export function useQueryImpl<
addSubscribeToMore(item)
}
}
firstStart = false
}
function startQuerySubscription () {