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.

This is continuation for #5351.

The problem is that there’s no way to render an asynchronously loaded component on SSR. My use-case for asynchronously loaded components is rendering JAM-stack site’s content from JSON files. My JSON-files describe page content as blocks, that are different components (type) and their props (data).

I want to have top-level await support for component’s <script> that will allow awaiting for promises before component’s initialization is finished.

I’ve done an implementation for this, but changing initialization asynchronous is quite a breaking change. After the change it’s not possible to initialize component with constructor, but instead we have to use a static async builder method Component.init(options). Not being able to initialize synchronously breaks custom elements. Component updating also becomes asynchronous so assignments to props don’t get reflected to DOM synchronously. That will also break a lot of code.

If I make async initialization a compiler option, so that it doesn’t trash backwards compatibility, would maintainers be willing to merge the changes? Is there any demand for this feature?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:30
  • Comments:27 (4 by maintainers)

github_iconTop GitHub Comments

15reactions
98muxcommented, Apr 12, 2021

@joas8211 Sorry for my noobness, could it be possible to add syntax for async instead of a compiler option? Like this:

<script async>

</script>
7reactions
joas8211commented, Oct 15, 2020

@antony What do you mean? Acorn already supports “top-level await” with allowAwaitOutsideFunction: true. And I’m not trying to have a real top-level await (top-level of module). I’m just trying to have await for component’s script-tag (init script) that is actually wrapped in a function that can be changed to an async function just like I did in my fork.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top-level await - V8 JavaScript engine
Top-level await enables developers to use the await keyword outside of async functions. It acts like a big async function causing other ...
Read more >
await - JavaScript - MDN Web Docs
You can use the await keyword on its own (outside of an async function) at the top level of a module. This means...
Read more >
ECMAScript proposal: Top-level await - GitHub
Top-level await enables modules to act as big async functions: With top-level await , ECMAScript Modules (ESM) can await resources, causing other modules ......
Read more >
ECMAScript: Top-level await | Saeloun Blog
Top-level await enables modules to act as big async functions. With top-level await, ECMAScript Modules (ESM) can await resources. Other modules ...
Read more >
javascript - How can I use async/await at the top level?
when a module using top-level await is evaluated, it returns a promise to the module loader (like an async function does), which waits...
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 Hashnode Post

No results found