From 87188c49a1db8ddb10b41f157d84432531e1e5c2 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Tue, 13 Jun 2023 16:07:07 +0200 Subject: [PATCH] fix(ssr): hydration mismatch with keepPreviousResult --- packages/vue-apollo-composable/src/useQuery.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/vue-apollo-composable/src/useQuery.ts b/packages/vue-apollo-composable/src/useQuery.ts index d472cc0..3e1aac6 100644 --- a/packages/vue-apollo-composable/src/useQuery.ts +++ b/packages/vue-apollo-composable/src/useQuery.ts @@ -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 () {