question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

async setup() failing to inject villus after first await

See original GitHub issue

Hello,

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
staticglitchcommented, Jan 21, 2021

Yeah, looks like await breaks it, even if used on await console.log(1), but it all works if all inject’s happen before it. Seems like it’s also like that without suspense. A bit sketchy. It’s probably best to just use isFetching for now with local loading indicator.

0reactions
staticglitchcommented, Jan 23, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found