From d329d4da69bc57d1b8d13245769d7ba3999506d0 Mon Sep 17 00:00:00 2001 From: Nick Messing Date: Fri, 23 Aug 2024 12:32:59 +0300 Subject: [PATCH] fix: improved pinia support (#1571) --- packages/vue-apollo-composable/src/useQuery.ts | 4 +++- packages/vue-apollo-composable/src/util/loadingTracking.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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) => { diff --git a/packages/vue-apollo-composable/src/util/loadingTracking.ts b/packages/vue-apollo-composable/src/util/loadingTracking.ts index 7b51bebb..3abb41ef 100644 --- a/packages/vue-apollo-composable/src/util/loadingTracking.ts +++ b/packages/vue-apollo-composable/src/util/loadingTracking.ts @@ -1,4 +1,4 @@ -import { Ref, watch, onUnmounted, ref, getCurrentScope, onScopeDispose } from 'vue-demi' +import { Ref, watch, ref, getCurrentScope, onScopeDispose } from 'vue-demi' import { isServer } from './env.js' import type { EffectScope } from 'vue-demi' @@ -36,7 +36,7 @@ export function getCurrentTracking () { subscriptions: ref(0), }) // Cleanup - onUnmounted(() => { + onScopeDispose(() => { globalTracking.components.delete(currentScope) }) } else {