-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
Make sure renderInit only runs after DOMContentLoaded #1540
Conversation
node_package/src/clientStartup.ts
Outdated
// If lazy asynch loading is used, such as with loadable-components, then the init | ||
// function will install some handler that will properly know when to do hyrdation. | ||
if (document.readyState !== 'loading') { | ||
if (document.readyState === 'complete') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the way the code used to be, which I changed in 7b301f9.
We need to ensure that we don't break the use case of loadable-components.
Maybe we should allow an opt-in to loading scripts so long as the readState !== 'loading'
?
node_package/src/clientStartup.ts
Outdated
// If lazy asynch loading is used, such as with loadable-components, then the init | ||
// function will install some handler that will properly know when to do hyrdation. | ||
if (document.readyState !== 'loading') { | ||
if (document.readyState === 'complete') { | ||
window.setTimeout(renderInit); | ||
} else { | ||
document.addEventListener('DOMContentLoaded', renderInit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From MDN:
The DOMContentLoaded event fires when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.
readyState === 'complete': The document and all sub-resources have finished loading. The state indicates that the load event is about to fire.
The event listener and the if statement correspond to different stages of page load.
Should it be something like the code below?
function onPageReady(callback) {
if (document.readyState === "complete") {
callback();
} else {
document.addEventListener("readystatechange", function onReadyStateChange() {
onPageReady(callback);
document.removeEventListener("readystatechange", onReadyStateChange);
});
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right, @Romex91.
Do you think this change, with your suggestions included, could cause any sort of performance regression for our clients?
84ad614
to
6739ecf
Compare
6739ecf
to
a46fc0f
Compare
@Judahmeek this PR is ready to merge. |
Fixed the race condition revealed by #1539
This change is