Make sure renderInit only runs after DOMContentLoaded#1540
Merged
Conversation
justin808
reviewed
May 28, 2023
justin808
reviewed
May 29, 2023
justin808
reviewed
May 29, 2023
| // 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') { |
Member
There was a problem hiding this comment.
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'?
Romex91
reviewed
May 29, 2023
| if (document.readyState === 'complete') { | ||
| window.setTimeout(renderInit); | ||
| } else { | ||
| document.addEventListener('DOMContentLoaded', renderInit); |
Contributor
There was a problem hiding this comment.
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);
});
}
}
Contributor
Author
There was a problem hiding this comment.
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
Contributor
Author
|
@Judahmeek this PR is ready to merge. |
3 tasks
AbanoubGhadban
pushed a commit
that referenced
this pull request
Sep 25, 2025
Changes to spec/dummy: * Modified tsconfig.json in order to stop webpack recompilation loop * Updated react_on_rails to stop component initialization race condition per [ROR1540](#1540) * Modified prettierignore file to ignore generated packs * Provided render_options to load_pack_for_generated_component per [ROR1545](#1545)
AbanoubGhadban
pushed a commit
that referenced
this pull request
Sep 26, 2025
Changes to spec/dummy: * Modified tsconfig.json in order to stop webpack recompilation loop * Updated react_on_rails to stop component initialization race condition per [ROR1540](#1540) * Modified prettierignore file to ignore generated packs * Provided render_options to load_pack_for_generated_component per [ROR1545](#1545)
3 tasks
This was referenced Mar 8, 2026
This was referenced Mar 11, 2026
This was referenced Mar 21, 2026
This was referenced Mar 28, 2026
This was referenced Apr 18, 2026
This was referenced May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed the race condition revealed by #1539
This change is