Skip to content

Commit

Permalink
fix: only use onServerPrefetch in components
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jan 16, 2024
1 parent b6e45fb commit 445921a
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/use-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,22 @@ export function useQuery<TResult, TError = Error>(
refetch,
} satisfies UseQueryReturn<TResult, TError>

// 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) {
Expand Down

0 comments on commit 445921a

Please sign in to comment.