Consolidate use of DOMContentLoaded to wp-dom-ready package#13383
Merged
Consolidate use of DOMContentLoaded to wp-dom-ready package#13383
DOMContentLoaded to wp-dom-ready package#13383Conversation
Contributor
|
Caution: This PR has changes that must be merged to WordPress.com |
Collaborator
|
Thank you for the great PR description! When this PR is ready for review, please apply the Scheduled Jetpack release: September 3, 2019. |
This was referenced Oct 2, 2019
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.
Consolidates all various usages of
DOMContentLoadedevent to external@wordpress/dom-readypackage.I checked that it's shipped in WordPress 5.1.1 at least, maybe even earlier.
domReadyis super simple but it does a couple important checks in case the code runs afterDOMContentLoadedevent has already fired in case the script loads late. There are various ways to do this by checkingreadyState(or forgetting to check at all 😉) but like this we can ensure the same pattern everywhere.This also saves a bit of code by sharing it from a package but that's not very significant. ;-) On the cons side it adds one network request but it'll get concatenated by caching plugins anyway.
Changes proposed in this Pull Request:
wp.domReady. Enqueued dependencies for blocks are handled automatically so this will get loaded without manually adding it to anywhere.wp.domReadyand add package to dependencies.document.body.addEventListener(documentis in factwindow.document)Is this a new feature or does it add/remove features to an existing part of Jetpack?
Testing instructions:
Blocks
yarn build)wp-dom-readyscript? You can also confirm that_inc/blocks/BLOCK_NAME/view.deps.jsonfile haswp-dom-readyPhoton
modules/photon/photon(.min).jsis loaded, doesrestore_dimsfunction run? (maybe add console log to it to confirm?).Proposed changelog entry for your changes:
–