Open pixleight opened 7 months ago
I also ran into this. I solved it by wrapping things in useNuxtApp().runWithContext(async () => { /* my code here */ })
I think this is more like a limitation of Nuxt, perhaps? After awaiting an async call, it's like I have been transported out of the usual Nuxt context and into a then
-function of a Promise. So context probably has to be re-established.
Relevant Nuxt documentation:
The context is unset by Nuxt/Vue after the first await leading to the error on the second.
I think you can either use runWithContext
as suggested by @filiphazardous or for for example multiple await $fetch()
calls, I've wrapped them in an async handler function that I use with useAsyncData(handler, ...)
.
Environment
Build Modules: -
Describe the bug
Calling
useAsyncQuery
more than once inside a composable function results in a 500 error when loading a SSR route, with the following error message:Expected behaviour
Should be able to execute more than a single query in a composable function.
Reproduction
https://stackblitz.com/edit/github-tfy4rs?file=composables%2FuseMultipleQuery.ts
Example composable function:
Additional context
Executing multiple queries with
useAsyncQuery
works as expected when inside<script setup>
or loading a route in client-side context.Logs