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

requirejs/domReady.js can severely delay rendering of content #22909

Closed
DrewML opened this issue May 15, 2019 · 13 comments
Closed

requirejs/domReady.js can severely delay rendering of content #22909

DrewML opened this issue May 15, 2019 · 13 comments
Assignees
Labels
Component: Framework/Component Fixed in 2.3.x The issue has been fixed in 2.3 release line Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@DrewML
Copy link

DrewML commented May 15, 2019

Preconditions (*)

  1. Have a store running with an optimal Varnish setup (aka be fast to flush the HTML from the server)
  2. Use a handler registered with requirejs/domReady.js to render some content on the page. As an example, the Private Content feature of Magento works this way, so a default Luma setup is ready to go.

I haven't tested, but I assume this problem does not exist if bundling has been used. When bundling, domReady.js will be in a bundle loaded synchronously, so DOMContentLoaded will always fire after.

Steps to reproduce (*)

  1. In the initial HTML for any page, add a non-blocking resource (async script/img/etc), and make sure the file is served with a severe delay (10+ seconds). <img src="https://httpstat.us/404?sleep=10000" /> can be used for testing. This is done to simulate real-world delays that can happen with 3rd party content
  2. Navigate to the page the 3rd party content (with the simulated delay) has been added to

Note that, after refreshing the page several times, sometimes (race condition) the private content does not render until 10+ seconds have passed.

Expected result (*)

I expect domReady.js to invoke its registered handlers at either of the following times (whichever is observed first):

  • When the DOMContentLoaded event is fired on the document
  • When document.readyState !== 'loading'

The problem right now is that, if domReady.js loads/executes after the DOMContentLoaded event has been fired on the document, the code falls back to waiting for the load event. This is bad, and was a hack for older versions of IE to avoid doing browser sniffing.

We should basically borrow jQuery's implementation of this, as we know it's supported by all our target browsers. We should not import jQuery into domReady.js, though. Just copy/paste the implementation (few LOC).

Actual result (*)

If domReady.js loads and executes after DOMContentLoaded has already fired, registered handlers will not be invoked until every pending request for a resource has completed. This includes requests for non-critical, 3rd party resources.

Example
image

What scripts/content get delayed currently by this?

Additional Info

This problem is still present in the latest version of requirejs/domReady, to support browsers that Magento does not support.

As requirejs/domReady.js is from an older library that really doesn't change much, and is a small amount of code, I'm comfortable with us basically forking the domReady loader here and changing the logic inline.

@m2-assistant
Copy link

m2-assistant bot commented May 15, 2019

Hi @DrewML. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@DrewML do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label May 15, 2019
@DrewML DrewML changed the title Bug in requirejs/domReady.min.js can severely delay "Private Content" rendering requirejs/domReady.min.js can severely delay rendering of content May 16, 2019
@DrewML DrewML changed the title requirejs/domReady.min.js can severely delay rendering of content requirejs/domReady.js can severely delay rendering of content May 16, 2019
@kandy
Copy link
Contributor

kandy commented May 23, 2019

Looks like it enough to change

if (document.readyState === "complete") {

if ( document.readyState !== "loading") {

I don't see any other different compare to https://github.com/jquery/jquery/blob/master/src/core/ready.js

@DrewML
Copy link
Author

DrewML commented May 23, 2019

@kandy Pretty much!

@dmanners dmanners added good first issue Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Jun 18, 2019
@magento-engcom-team
Copy link
Contributor

@dmanners Thank you for verifying the issue.

Unfortunately, not enough information was provided to acknowledge ticket. Please consider adding the following:

  • Add "Component: " label(s) to this ticket based on verification result. If uncertain, you may follow the best guess
  • Add "Reproduced on " label(s) to this ticket based on verification result

Once all required information is added, please add label "Issue: Confirmed" again.
Thanks!

@magento-engcom-team magento-engcom-team removed the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Jun 18, 2019
@dmanners dmanners added Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Jun 18, 2019
@magento-engcom-team magento-engcom-team removed the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Jun 18, 2019
@magento-engcom-team
Copy link
Contributor

@dmanners Thank you for verifying the issue.

Unfortunately, not enough information was provided to acknowledge ticket. Please consider adding the following:

  • Add "Component: " label(s) to this ticket based on verification result. If uncertain, you may follow the best guess

Once all required information is added, please add label "Issue: Confirmed" again.
Thanks!

@dmanners dmanners added Component: Framework/Component Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Jun 18, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @dmanners
Thank you for verifying the issue. Based on the provided information internal tickets MC-17563 were created

Issue Available: @dmanners, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@johnhughes1984 johnhughes1984 self-assigned this Jun 18, 2019
@m2-assistant
Copy link

m2-assistant bot commented Jun 18, 2019

Hi @johnhughes1984. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 4. If the issue is not relevant or is not reproducible any more, feel free to close it.


Shubham0492 pushed a commit to Shubham0492/magento2 that referenced this issue Oct 30, 2019
@Shubham0492 Shubham0492 mentioned this issue Oct 30, 2019
4 tasks
@ihor-sviziev ihor-sviziev reopened this Nov 8, 2019
@ghost ghost unassigned johnhughes1984 Nov 8, 2019
@ghost ghost removed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed good first issue Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 8, 2019
@ghost ghost assigned johnhughes1984 Nov 8, 2019
@ihor-sviziev
Copy link
Contributor

This issue wasn't fixed yet, so re-opened

@ihor-sviziev ihor-sviziev added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Nov 8, 2019
@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Nov 8, 2019

@ihor-sviziev Thank you for verifying the issue.

Unfortunately, not enough information was provided to acknowledge ticket. Please consider adding the following:

  • Add "Reproduced on " label(s) to this ticket based on verification result

Once all required information is added, please add label "Issue: Confirmed" again.
Thanks!

@magento-engcom-team magento-engcom-team removed the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Nov 8, 2019
@ihor-sviziev ihor-sviziev added Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Nov 8, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @ihor-sviziev
Thank you for verifying the issue. Based on the provided information internal tickets MC-17563 were created

Issue Available: @ihor-sviziev, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@ihor-sviziev ihor-sviziev self-assigned this Nov 8, 2019
@m2-assistant
Copy link

m2-assistant bot commented Nov 8, 2019

Hi @ihor-sviziev. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


@ghost ghost unassigned ihor-sviziev Dec 10, 2019
@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Jan 23, 2020
@magento-engcom-team
Copy link
Contributor

Hi @DrewML, @johnhughes1984.

Thank you for your report and collaboration!

The issue was fixed by Magento team. The fix was delivered into magento/magento2:2.3-develop branch(es).
Related commit(s):

The fix will be available with the upcoming 2.3.5 release.

@krzksz
Copy link
Contributor

krzksz commented Feb 7, 2020

Closing as fixed via #23313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Framework/Component Fixed in 2.3.x The issue has been fixed in 2.3 release line Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

7 participants