-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Close a tiny gap in A-Frame loading order #5248
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
Merged
dmarcos
merged 1 commit into
aframevr:master
from
wmurphyrd:5228-track-dom-content-loaded-state
Feb 26, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
what about if we check for
document.readyState !== 'complete'instead? I think that would wait until deferred scripts have already runThere 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.
would need to call this.doConnectedCallback in the
DOMContentLoadedevent handlerThere 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.
alternatively we can listen to readystatechange and wait for document.readyState === 'complete' instead of listening to DOMContentLoaded
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.
If we checked against readyState complete but still listened for DOMContentLoaded, that would open another gap in the loading order:
During step 5, the readyState would still be interactive, so any entities attached from inside a DOMContentLoaded listener would never initialize as they would exit early from their connectedCallback and stay forever waiting for the DOMContentLoaded event that has already passed
It does call through to
doConnectedCallbackas-is because the listener for the ANode static property is registered first and thus updatesANode.DOMContentHasLoadedbefore this comes back in via DOMContentLoaded listener. However, if you're open to updating all of these listeners to calldoConnectedCallbackI would love to make that change because it makes it much easier to subclass these when they call into doConnectedCallback viathisrather thanprototype.doConnectedCallbacklike how a-entity does currentlyYes I proposed this as one of the two possible solutions when opening #5228. So that would look like:
Note this would conflict with the previous suggesting about changing the callback to doConnectedCallback. If we still wanted to do that as well, we'd need to add an event handler function that checked the current readyState to make sure it was complete before calling doConnectedCallback
Uh oh!
There was an error while loading. Please reload this page.
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.
oops on second thought the
readystatechangesolution proposed above would not work; it could stack listeners and initialize twice. Would have to go with the creating a readystatechange handlerThere 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.
Thanks for all the info and patience. I think this solution looks simpler. Can we incorporate in the PR?
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.
Sounds good
Uh oh!
There was an error while loading. Please reload this page.
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.
@dmarcos I did the readystatechange version, but it occurred to me during the work that this could be a breaking change. Anyone using
DOMContentLoadedlisteners of their own with A-Frame probably expects the scene and entities to be initialized (although I guess that would depend on whether they registered their listerens before or after A-Frame), but this would change it so scene and entities are never initialized duringDOMContentLoadedlistener callbacks.The unit tests may also be bearing this out, as the readystatechange version has one failure whereas this current version had none:
So just wanted to check in if you still want to go this direction with readystatechange. If so, I'll dig into the unit test failure
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.
In A-Frame the 'loaded' event should be used.
DOMContentLoadedis not very useful since won't guarantee the scene, assets and entities are ready to go.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.
readystatechange version is up - that test failure I noted above - cannot get it to happen again. Tried several times locally and it passes in CI as well. Must have been a fluke.
This version still resolves my issues with deferred scripts & SVAWC