From 445921a14583d18519c379c18762e373fb12e027 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 16 Jan 2024 09:51:20 +0100 Subject: [PATCH] fix: only use onServerPrefetch in components --- src/use-query.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/use-query.ts b/src/use-query.ts index b464e801..fb2bee25 100644 --- a/src/use-query.ts +++ b/src/use-query.ts @@ -144,20 +144,22 @@ export function useQuery( refetch, } satisfies UseQueryReturn - // only happens on server, app awaits this - onServerPrefetch(async () => { - await refresh() - // TODO: after adding a test, remove these lines and refactor the const queryReturn to just a return statement - // NOTE: workaround to https://github.com/vuejs/core/issues/5300 - // eslint-disable-next-line - queryReturn.data.value, - queryReturn.error.value, - queryReturn.isFetching.value, - queryReturn.isPending.value - }) - const hasCurrentInstance = getCurrentInstance() + if (hasCurrentInstance) { + // only happens on server, app awaits this + onServerPrefetch(async () => { + await refresh() + // TODO: after adding a test, remove these lines and refactor the const queryReturn to just a return statement + // NOTE: workaround to https://github.com/vuejs/core/issues/5300 + // eslint-disable-next-line + queryReturn.data.value, + queryReturn.error.value, + queryReturn.isFetching.value, + queryReturn.isPending.value + }) + } + // should we be watching entry let isActive = false if (hasCurrentInstance) {