Skip to content

Commit 59e81ef

Browse files
authored
Merge pull request #12 from guendev/fix-ssr-hook
fix(core): trigger onResult and onError event hooks during SSR in useQuery
2 parents 241ed9f + d9aeeaf commit 59e81ef

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.changeset/witty-swans-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue3-apollo/core": patch
3+
---
4+
5+
fix(core): trigger onResult and onError event hooks during SSR in useQuery

packages/core/src/composables/useQuery.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,16 @@ export function useQuery<TData = unknown, TVariables extends OperationVariables
199199
loading.value = false
200200
if (queryResult.error) {
201201
error.value = queryResult.error
202+
void onErrorEvent.trigger(queryResult.error, { client })
203+
}
204+
else if (isDefined(result.value)) {
205+
void onResult.trigger(result.value, { client })
202206
}
203207
}
204208
catch (e) {
205209
error.value = e as ErrorLike
206210
loading.value = false
211+
void onErrorEvent.trigger(error.value, { client })
207212
}
208213
})
209214
}

packages/nuxt/playground/pages/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ onResult((data) => {
5959
6060
// Composables
6161
const route = useRoute()
62-
const isGlobalLoading = useGlobalLoading()
62+
const isLoading = useQueriesLoading()
6363
const { finish, start } = useLoadingIndicator()
6464
6565
// Watchers
66-
watch(isGlobalLoading, (loading) => {
66+
watch(isLoading, (loading) => {
6767
if (loading) {
6868
start()
6969
}

0 commit comments

Comments
 (0)