Waiting for tag value consistently not working in some cases in Astro components
What version of astro are you using?
2.5.7
Are you using an SSR adapter? If so, which one?
no
What package manager are you using?
pnpm
What operating system are you using?
Windows
What browser are you using?
Chrome
Describe the Bug
In some cases this consistently works.
The error says:
"await" can only be used inside an "async" function
or
Parse failure: Cannot use keyword 'await' outside an async function
if I try it a bit differently
Examples:
---
---
<<any element name> set:html={await method()}/>
---
---
{await method()}
---
---
{await value}
In this case for example it does not work:
- withastro/astro#7292
In this case for example it does work (consistently) (with the bug described in the (below) issue (but as I am trying the same in the context of this issue it is consistently not working)):
- withastro/astro#7289
Link to Minimal Reproducible Example
⠀
Participation
- [ ] I am willing to submit a pull request for this issue.
Can you provide a repro showing that it's not working? It seems to be working for me (stackblitz). Maybe https://live-astro-compiler.vercel.app can help you visualize how the await gets evaluated.
Sure:
- https://stackblitz.com/edit/github-94pv4g-ymhcxm?file=src%2Fpages%2Findex.astro
Looks like the problem is that you can't use set:html={await ...} in a Fragment (or any component), because it generates code like:
`${$$renderComponent($$result,'Fragment',Fragment,{},{"default": () => $$render`${$$unescapeHTML(await value)}`,})}`
Maybe it could be ... "default": async () ... to fix it.
Ah that's a good callout @bluwy. This is technically a compiler issue, I'm going to transfer this over there.