async setup() failing to inject villus after first await
See original GitHub issueHello,
I have a simple situation when I want to prefetch data in a component, and then also allow mutation in that same component by executing a form. If I do async setup()
and await useQuery()
, then the following useMutation
fails to recognize villus client.
export default {
async setup() {
const { data } = await useQuery(`...`);
const { execute } = useMutation(`...`);
}
};
The useMutation()
produces: Uncaught (in promise) Error: Cannot detect villus Client, did you forget to call 'useClient'?
If I remove async/await
it all works correctly. I’m assuming this is related to vue’s setup lifecycle, but I can’t figure it out from the docs - is this likely my error or a bug?
The intended use is with <suspense>
one level above. I understand I could have a workaround in this component by using { isFetching }
on the useQuery
and show a fallback that way.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
async setup usability · Discussion #234 · vuejs/rfcs - GitHub
The problem is that after an await , or a Promise.then , the continuation doesn't run as part of setup() , which has...
Read more >Because I can't run await on the top level, I have to put it into ...
An async function is simply a function that returns a Promise. The await keyword is there to introduce, basically, a .then() call around...
Read more >Async IO in Python: A Complete Walkthrough
This tutorial will give you a firm grasp of Python's approach to async IO, which is a concurrent programming design that has received...
Read more >Async Components - Vue.js
The resulting AsyncComp is a wrapper component that only calls the loader function when it is actually rendered on the page. In addition,...
Read more >Concurrency and async / await - FastAPI
If your application (somehow) doesn't have to communicate with anything else and wait for it to respond, use async def . If you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, looks like
await
breaks it, even if used onawait console.log(1)
, but it all works if allinject
’s happen before it. Seems like it’s also like that without suspense. A bit sketchy. It’s probably best to just useisFetching
for now with local loading indicator.For completeness sake in case anyone stumbles here… This is not a bug and inject simply doesn’t work after
await
, reference:https://forum.vuejs.org/t/vue-3-inject-can-only-be-used-inside-setup-or-functional-components/108672/4