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

Conversation

pshihn
Copy link

@pshihn pshihn commented Oct 15, 2018

@pshihn pshihn requested a review from dfreedm as a code owner October 15, 2018 18:27
Copy link
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

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

This SFTM, but I would still like to add a regression test for this. I am quite busy right now, but I will put this on my list.

@TimvdLippe TimvdLippe self-assigned this Oct 15, 2018
@pshihn
Copy link
Author

pshihn commented Oct 15, 2018

I can try adding a test as well when I get a chance. To properly recreate this I need to load larger scripts/css files through a URL, Is it safe to load an external package like (https://unpkg.com/three@0.94.0/build/three.js) to the test case?

@TimvdLippe
Copy link
Contributor

TimvdLippe commented Oct 15, 2018 via email

@pshihn
Copy link
Author

pshihn commented Oct 15, 2018

Just a while loop will not do it because the async script needs to run while browser is still waiting for a sync script to fetch. So a while loop followed by a script sourced to a javascript file may do the trick.
I'll try it out.

@pshihn
Copy link
Author

pshihn commented Oct 15, 2018

I have added a test that consistently fails in Firefox without the fix, and passes with the fix.

@TimvdLippe
Copy link
Contributor

All tests are passing so that is fine. I will pull in the code to run tests on older browsers.

Copy link
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

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

I suddenly thought of two more little things. Could you update? Then this all LGTM.

<script>
const start = Date.now();
let diff = 0;
while (diff < 5000) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a clarifying comment here. Something like we mimic a long loading script to make sure the document readystate is loading when the loader executes.

Copy link
Author

Choose a reason for hiding this comment

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

Added a detailed explanation in the comments

// 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.

@TimvdLippe
Copy link
Contributor

The tests fail on Edge 17 and IE11. Are you able to debug these and potentially fix them or should I do so?

@pshihn
Copy link
Author

pshihn commented Oct 16, 2018

I don't have access to a windows machine right now. :(

@dfreedm
Copy link
Contributor

dfreedm commented Jun 10, 2019

New issue: webcomponents/polyfills#57

@dfreedm
Copy link
Contributor

dfreedm commented Jun 10, 2019

Sorry for the delay on this

If this is an issue that is still important to you, could you remake this PR in the new monorepo? https://github.com/webcomponents/polyfills

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants