Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Better check for 'script is synchronous' #1036

Closed
wants to merge 6 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions webcomponents-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@

var newScript = document.createElement('script');
newScript.src = url;
// if readyState is 'loading', this script is synchronous
if (document.readyState === 'loading') {
// if readyState is 'loading' and this script is synchronous
if (document.readyState === 'loading' && (!document.currentScript.async)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Iirc, document.currentscript does not exist in type="module". Could you verify? (In that case, it would need to be document.currentScript && ...

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

// make sure custom elements are batched whenever parser gets to the injected script
newScript.setAttribute('onload', 'window.WebComponents._batchCustomElements()');
document.write(newScript.outerHTML);
Expand Down