From faf8af8da911ffe048daa434ab319923f25d931a Mon Sep 17 00:00:00 2001 From: Nicolai Moraru Date: Thu, 22 Aug 2024 18:24:45 +0300 Subject: [PATCH] fix: onServerPrefetch calls outside components setup --- packages/vue-apollo-composable/src/useQuery.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/vue-apollo-composable/src/useQuery.ts b/packages/vue-apollo-composable/src/useQuery.ts index 92544691..3d7f5c56 100644 --- a/packages/vue-apollo-composable/src/useQuery.ts +++ b/packages/vue-apollo-composable/src/useQuery.ts @@ -6,6 +6,7 @@ import { watch, onServerPrefetch, getCurrentScope, + getCurrentInstance, onScopeDispose, nextTick, shallowRef, @@ -152,6 +153,7 @@ export function useQueryImpl< lazy = false, ): UseQueryReturn { const currentScope = getCurrentScope() + const currentInstance = getCurrentInstance() const currentOptions = ref>() @@ -200,7 +202,7 @@ export function useQueryImpl< firstRejectError = undefined } - currentScope && onServerPrefetch?.(() => { + currentInstance && onServerPrefetch?.(() => { if (!isEnabled.value || (isServer && currentOptions.value?.prefetch === false)) return return new Promise((resolve, reject) => {