Skip to content
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: globalScript not supporting async #3392

Closed
3 tasks done
mikaelkaron opened this issue May 30, 2022 · 7 comments · Fixed by #5158
Closed
3 tasks done

bug: globalScript not supporting async #3392

mikaelkaron opened this issue May 30, 2022 · 7 comments · Fixed by #5158
Assignees
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@mikaelkaron
Copy link

mikaelkaron commented May 30, 2022

Prerequisites

Stencil Version

2.15.2

Current Behavior

according to the globalScript documentation the exported method supports async, however when testing this the bootstrapping is not_ async.

With a little bit debugging I can see that the generated bootstrap methods won't await my code.

const globalScripts = () => {
  appComponentsGlobalScript();
  initialize();
};
patchBrowser().then(options => {
  globalScripts();
  return bootstrapLazy(JSON.parse('lotsOfJsonHere'), options);
});

Expected Behavior

That my async code is properly awaited before bootstrapLazy is executed

Steps to Reproduce

just export an async method in globalScripts file and put something in componentDidLoad on a component - check order of execution.

I've done this in the reprocuction URL with four console.log statements.

The expected order should be:

global:start 
global:end
component:willLoad 
component:didLoad 

The current order:

global:start 
component:willLoad 
component:didLoad 
global:end 

Code Reproduction URL

https://codesandbox.io/s/stencil-globalscript-bug-r87gn2

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label May 30, 2022
@mikaelkaron mikaelkaron changed the title bug: bug: globalScript not supporting async May 30, 2022
@alicewriteswrongs
Copy link
Member

Hey @mikaelkaron thanks for reporting this issue and for providing a repro! I was able to reproduce the issue and confirm that this is a bug in the code that Stencil uses to generate the relevant entry point. Ideally in this case Stencil would detect whether the globalScripts function is async and, if so, produce code that awaits it before continuing on. I'm going to add this to our backlog and the team will take a look. Thanks again for the detailed issue and repro case!

@alicewriteswrongs alicewriteswrongs added the Bug: Validated This PR or Issue is verified to be a bug within Stencil label May 31, 2022
@ionitron-bot ionitron-bot bot removed the triage label May 31, 2022
@rwaskiewicz rwaskiewicz added Bug: Validated This PR or Issue is verified to be a bug within Stencil and removed Bug: Validated This PR or Issue is verified to be a bug within Stencil labels May 31, 2022
@ghost
Copy link

ghost commented Dec 8, 2023

Where is this at in your backlog? Any idea when the fix will be available?

Hey @mikaelkaron thanks for reporting this issue and for providing a repro! I was able to reproduce the issue and confirm that this is a bug in the code that Stencil uses to generate the relevant entry point. Ideally in this case Stencil would detect whether the globalScripts function is async and, if so, produce code that awaits it before continuing on. I'm going to add this to our backlog and the team will take a look. Thanks again for the detailed issue and repro case!

@christian-bromann christian-bromann self-assigned this Dec 9, 2023
@christian-bromann
Copy link
Member

@metsylvainlajoie happy to take a look!

christian-bromann added a commit that referenced this issue Dec 11, 2023
christian-bromann added a commit that referenced this issue Dec 11, 2023
christian-bromann added a commit that referenced this issue Dec 12, 2023
@christian-bromann
Copy link
Member

@mikaelkaron @metsylvainlajoie I raised a PR with a fix for this in #5158. However before we move on with this I would be interested in your use case here. Respecting an async function would mean that the screen would stay blank until the global script resolves. That seems to result in a bad user experience but I might have not enough context to understand in what way you are using global scripts. I want to make sure we are fixing the right problem at hand,

Therefore can you elaborate how you use global scripts? Thanks a lot for providing more information.

christian-bromann added a commit that referenced this issue Feb 2, 2024
christian-bromann added a commit that referenced this issue Feb 8, 2024
github-merge-queue bot pushed a commit that referenced this issue Feb 8, 2024
* fix(compiler): support async globalScripts functions

fixes #3392
STENCIL-467

PR feedback

* remove unused file
@tanner-reits
Copy link
Member

A fix for this was included in today's v4.12.2 release!

@ghost
Copy link

ghost commented Feb 12, 2024 via email

@joewoodhouse
Copy link
Contributor

joewoodhouse commented Mar 11, 2024

@tanner-reits I've not got to the bottom of it yet but I have a Stencil app that uses jeep-sqlite, which has started failing to run on the latest stencil version. By process of elimination I found this build (4.12.2) to be the problem, I'll hopefully get to the bottom of it, but something to do with how the custom elements are loaded onto the page seems to have changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants