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

feat: async script module support, close #3163 #4864

Merged
merged 5 commits into from
Sep 16, 2021
Merged

Conversation

patak-dev
Copy link
Member

@patak-dev patak-dev commented Sep 6, 2021

Description

See #3163 for details

Additional context

This PR assumes that every script module is bundled together (even if several chunks may be generated, as with the main index and vendor chunks). Every script module needs to be marked as async for the output script tag to be async. Mixed async and defer would end up with a defer tag as it is currently the default.

An alternative would be to break the bundling in async and defer chunks that could be loaded separately, but this would involve a bigger refactoring that may not be justified. If we end up doing this, it could be introduced as a separate PR in the future.

This PR may have conflicts with #4555, but should be easy to resolve no matter which one we merge first. @andylizi you may want to review this PR to double check.

@DylanPiercey @ryansolid could you check that this PR would enable the use of async in Solid and Marko as you expected?

Note: I'll send updated docs later to the PR


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@DylanPiercey
Copy link
Contributor

Looks great, appreciate the work on this @patak-js!

ryansolid
ryansolid previously approved these changes Sep 6, 2021
Copy link

@ryansolid ryansolid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thanks for putting this together.

@patak-dev
Copy link
Member Author

Thanks for the review. About mixed async and defer scripts, I'm thinking that silently falling back to defer may not be the best here because people are going to have a hard time understanding why their output script is not async if they missed one.

So we should at least issue a warning in this case, or directly error out the build. A hard error could be better if later we want to support the mixed case with a different strategy because that won't be a breaking change. If you have some input about this let me know. I'll bring this PR for approval to our next meeting with the team.

antfu
antfu previously approved these changes Sep 7, 2021
Shinigami92
Shinigami92 previously approved these changes Sep 7, 2021
@Shinigami92 Shinigami92 added the p2-nice-to-have Not breaking anything but nice to have (priority) label Sep 7, 2021
@patak-dev
Copy link
Member Author

Added the warning that we discussed in the last meeting, and merged and corrected the PR to work properly after #4555

@patak-dev patak-dev added this to the 2.6 milestone Sep 15, 2021
Comment on lines +217 to +219
everyScriptIsAsync &&= isAsync
someScriptsAreAsync ||= isAsync
someScriptsAreDefer ||= !isAsync
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

giphy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a good or a bad reaction? 😅
We may need to refactor this info as an array and then at the end just use every/some over it, if thus is not clear

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good reaction 🤣 It was just like a 😲
I also approved the PR 😸

@patak-dev patak-dev merged commit 3984569 into main Sep 16, 2021
@patak-dev patak-dev deleted the async-script-support branch September 16, 2021 13:35
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants