-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: top-level await issue #4231
Comments
Hey @runr02 👋 Thanks for the issue! I don't believe this is an issue with Stencil specifically, as CommonJS (cjs) does not support top-level await. Can you describe your use case a little bit more for us? |
We are using dexie (https://dexie.org/) as wrapper for indexed db however this always returns a promise. We want to abstract the dexie call and simply return an object. This way we don't have to await at a higher level of the application (i.e., stencil component).
then reference 'user' inside a stencil component. To add we have set module to esnext and target to es2019. Typescript doesn't complain. We only get an error upon build. Have not set anything that would suggest output format to be cjs. Here's git hub repo of starter project with replicated issue: https://github.com/runr02/toplevelawaitissue.git |
Thanks! I'm going to label this to get it into our backlog for the team to refine. |
To add to this, I was until recently building a stencil app which used top level await, and it built fine. So something changed and caused this to regress. What's even weirder is: I didn't change my app/package.json/package-lock.json i just reinstalled the modules with |
fixes ionic-team#4231 By default the `vdomRender` build flag is `false`. The Stencil parser detects any usage of a `h` function, this flag will be switched. In the component provided by author of the bug there hasn't been any vDOM to be parsed, therefor there was no usage of the function `h`. Now, in `callRender` if we end up not having to render any vDOM we used to just attach the string (can also be a boolean or number) as text to the host element. This however doesn't work when a shadow DOM is registered for the component. In this case the text content is added to the light dom which is not being rendered. To fix this we check if the component has a shadow DOM if attach the text node to that node.
fixes ionic-team#4231 By default the `vdomRender` build flag is `false`. The Stencil parser detects any usage of a `h` function, this flag will be switched. In the component provided by author of the bug there hasn't been any vDOM to be parsed, therefor there was no usage of the function `h`. Now, in `callRender` if we end up not having to render any vDOM we used to just attach the string (can also be a boolean or number) as text to the host element. This however doesn't work when a shadow DOM is registered for the component. In this case the text content is added to the light dom which is not being rendered. To fix this we check if the component has a shadow DOM if attach the text node to that node.
fixes ionic-team#4231 By default the `vdomRender` build flag is `false`. The Stencil parser detects any usage of a `h` function, this flag will be switched. In the component provided by author of the bug there hasn't been any vDOM to be parsed, therefor there was no usage of the function `h`. Now, in `callRender` if we end up not having to render any vDOM we used to just attach the string (can also be a boolean or number) as text to the host element. This however doesn't work when a shadow DOM is registered for the component. In this case the text content is added to the light dom which is not being rendered. To fix this we check if the component has a shadow DOM if attach the text node to that node.
@runr02 I am able to get the component to render after applying this patch: diff --git a/src/components/my-component/my-component.tsx b/src/components/my-component/my-component.tsx
index eb17b68..acb7f88 100644
--- a/src/components/my-component/my-component.tsx
+++ b/src/components/my-component/my-component.tsx
@@ -1,4 +1,4 @@
-import { Component, Prop } from '@stencil/core';
+import { Component, Prop, h } from '@stencil/core';
// import { format } from '../../utils/utils';
import { message } from '../../utils/toplevelawaitissue';
@@ -29,6 +29,6 @@ export class MyComponent {
render() {
// return <div>Hello, World! I'm {this.getText()}</div>;
- return message;
+ return <div>{message}</div>;
}
} Am I missing something here to reproduce this? |
@HansClaasen it’s been a while and can take a closer look tomorrow but the issue presented itself when you build “npm run build” |
@runr02 you are right. I actually didn't run the build command and only called After further investigation it turns out that the Stencil compiler always creates CJS artifacts by calling I could see two options here:
Any advice from the Stencil team would be appreciated. Thanks! |
* fix(runtime): apply textnodes to shadow DOM instead of light dom fixes #4231 By default the `vdomRender` build flag is `false`. The Stencil parser detects any usage of a `h` function, this flag will be switched. In the component provided by author of the bug there hasn't been any vDOM to be parsed, therefor there was no usage of the function `h`. Now, in `callRender` if we end up not having to render any vDOM we used to just attach the string (can also be a boolean or number) as text to the host element. This however doesn't work when a shadow DOM is registered for the component. In this case the text content is added to the light dom which is not being rendered. To fix this we check if the component has a shadow DOM if attach the text node to that node. * fix unit test * use component meta flags to detect shadow dom --------- Co-authored-by: Hans Claasen <[email protected]> Co-authored-by: Christian Bromann <[email protected]>
Prerequisites
Stencil Version
2.21.0
Current Behavior
Get build error when using top-level await.
"Module format cjs does not support top-level await."
Expected Behavior
Solution should build successfully.
System Info
Steps to Reproduce
in ts file:
`export class Hello{
static async SayHello() {
return Promise.resolve('Hello World');
}
}
export const hello= await Profile.SayHello();
`
in another ts file import variable hello and use. Then build npm run build. You will receive the error.
Code Reproduction URL
Code
Additional Information
No response
The text was updated successfully, but these errors were encountered: