Skip to content

Commit

Permalink
fix: onServerPrefetch calls outside components setup
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmessing committed Aug 22, 2024
1 parent 732e66e commit faf8af8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vue-apollo-composable/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
watch,
onServerPrefetch,
getCurrentScope,
getCurrentInstance,
onScopeDispose,
nextTick,
shallowRef,
Expand Down Expand Up @@ -152,6 +153,7 @@ export function useQueryImpl<
lazy = false,
): UseQueryReturn<TResult, TVariables> {
const currentScope = getCurrentScope()
const currentInstance = getCurrentInstance()

const currentOptions = ref<UseQueryOptions<TResult, TVariables>>()

Expand Down Expand Up @@ -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<void>((resolve, reject) => {
Expand Down

0 comments on commit faf8af8

Please sign in to comment.