-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Reuse wp_script_attributes filter for adding data-wp-router-options attribute to script module #72489
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
Reuse wp_script_attributes filter for adding data-wp-router-options attribute to script module #72489
Conversation
…ttribute to script module
…pdate/script-module-router-options-attributes
…pdate/script-module-router-options-attributes
…-router-options-attributes
luisherranz
left a comment
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.
Hey Sam, we need to move the compatibility code to the compat folder.
Apart from that, when the WordPress version is 6.9 or higher but Gutenberg is installed, Gutenberg replaces the Core scripts with its own scripts. In that case, we need to make sure that the directive is also being added correctly. That logic needs to be outside of the compat folder, but we can use the new methods introduced in WordPress 6.9.
lib/client-assets.php
Outdated
| */ | ||
| remove_action( 'wp_enqueue_scripts', 'wp_enqueue_stored_styles' ); | ||
| remove_action( 'wp_footer', 'wp_enqueue_stored_styles', 1 ); | ||
| if ( version_compare( get_bloginfo( 'version' ), '6.9.0', '<' ) ) { |
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.
We need to move this to the compat/wordpress-6.9 folder so that it gets deleted when Gutenberg no longer needs to support versions older than WordPress 6.9.
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.
Gotcha thanks
…en re-registering existing core blocks
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
…ttribute to script module (#72489) * Reuse wp_script_attributes filter for adding data-wp-router-options attribute to script module * Use wp_json_encode() * Make gutenberg_script_module_add_router_options_attributes() more concise * Improve phpdoc return tags * Remove compat/wordpress-6.9/script-modules.php * Update backport changelog * (WIP) Use render_block_data to filter all blocks co-authored: @samueljseay * Adjust manual registration of blocks in e2e tests * We should not need any manual registration now. * Update changelog to match new wordpress-develop PR. * Fix merge conflict mistake * Remove redundant white space change * Fix merge conflict mistake * Move conditional code to compat, check for existence of new method when re-registering existing core blocks * Fix typo in code comment. Co-authored-by: Luis Herranz <luisherranz@gmail.com> * Simplify the compatibility check. --------- Co-authored-by: westonruter <westonruter@git.wordpress.org> Co-authored-by: luisherranz <luisherranz@git.wordpress.org> Co-authored-by: samueljseay <samueljseay@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
|
I just cherry-picked this PR to the release/21.9 branch to get it included in the next release: 0926b18 |
…ttribute to script module (#72489) * Reuse wp_script_attributes filter for adding data-wp-router-options attribute to script module * Use wp_json_encode() * Make gutenberg_script_module_add_router_options_attributes() more concise * Improve phpdoc return tags * Remove compat/wordpress-6.9/script-modules.php * Update backport changelog * (WIP) Use render_block_data to filter all blocks co-authored: @samueljseay * Adjust manual registration of blocks in e2e tests * We should not need any manual registration now. * Update changelog to match new wordpress-develop PR. * Fix merge conflict mistake * Remove redundant white space change * Fix merge conflict mistake * Move conditional code to compat, check for existence of new method when re-registering existing core blocks * Fix typo in code comment. Co-authored-by: Luis Herranz <luisherranz@gmail.com> * Simplify the compatibility check. --------- Co-authored-by: westonruter <westonruter@git.wordpress.org> Co-authored-by: luisherranz <luisherranz@git.wordpress.org> Co-authored-by: samueljseay <samueljseay@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
|
Even though these are PHP changes only, and already back ported in core, we should still backport it to the 6.9 branch in Gutenberg so that the test plugin is updated and the e2e tests run fine without GB active. |
|
For some reason, the automatic cherry-pick to the 6.9 branch isn't happening. I'll try re-adding the label. |
Unfortunately, the CI failed. Maybe it doesn't work for PRs submitted from forked repositories. I'd like to manually create a PR for the backport. |
…ttribute to script module (#72489) * Reuse wp_script_attributes filter for adding data-wp-router-options attribute to script module * Use wp_json_encode() * Make gutenberg_script_module_add_router_options_attributes() more concise * Improve phpdoc return tags * Remove compat/wordpress-6.9/script-modules.php * Update backport changelog * (WIP) Use render_block_data to filter all blocks co-authored: @samueljseay * Adjust manual registration of blocks in e2e tests * We should not need any manual registration now. * Update changelog to match new wordpress-develop PR. * Fix merge conflict mistake * Remove redundant white space change * Fix merge conflict mistake * Move conditional code to compat, check for existence of new method when re-registering existing core blocks * Fix typo in code comment. Co-authored-by: Luis Herranz <luisherranz@gmail.com> * Simplify the compatibility check. --------- Co-authored-by: westonruter <westonruter@git.wordpress.org> Co-authored-by: luisherranz <luisherranz@git.wordpress.org> Co-authored-by: samueljseay <samueljseay@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
…ttribute to script module (#72489) * Reuse wp_script_attributes filter for adding data-wp-router-options attribute to script module * Use wp_json_encode() * Make gutenberg_script_module_add_router_options_attributes() more concise * Improve phpdoc return tags * Remove compat/wordpress-6.9/script-modules.php * Update backport changelog * (WIP) Use render_block_data to filter all blocks co-authored: @samueljseay * Adjust manual registration of blocks in e2e tests * We should not need any manual registration now. * Update changelog to match new wordpress-develop PR. * Fix merge conflict mistake * Remove redundant white space change * Fix merge conflict mistake * Move conditional code to compat, check for existence of new method when re-registering existing core blocks * Fix typo in code comment. Co-authored-by: Luis Herranz <luisherranz@gmail.com> * Simplify the compatibility check. --------- Co-authored-by: westonruter <westonruter@git.wordpress.org> Co-authored-by: luisherranz <luisherranz@git.wordpress.org> Co-authored-by: samueljseay <samueljseay@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
…ttribute to script module (#72489) (#73512) * Reuse wp_script_attributes filter for adding data-wp-router-options attribute to script module * Use wp_json_encode() * Make gutenberg_script_module_add_router_options_attributes() more concise * Improve phpdoc return tags * Remove compat/wordpress-6.9/script-modules.php * Update backport changelog * (WIP) Use render_block_data to filter all blocks co-authored: @samueljseay * Adjust manual registration of blocks in e2e tests * We should not need any manual registration now. * Update changelog to match new wordpress-develop PR. * Fix merge conflict mistake * Remove redundant white space change * Fix merge conflict mistake * Move conditional code to compat, check for existence of new method when re-registering existing core blocks * Fix typo in code comment. * Simplify the compatibility check. --------- Co-authored-by: westonruter <westonruter@git.wordpress.org> Co-authored-by: luisherranz <luisherranz@git.wordpress.org> Co-authored-by: samueljseay <samueljseay@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
|
This PR was manually backported into the |
What?
Closes #70873
Why?
This improves the selective pre-loading of script modules, by using the same approach implemented in core in WordPress/wordpress-develop#10357 utilizing the
wp_script_attributesfilter to adddata-wp-router-optionsto the script module tags that do need to pre loaded for client-side navigation.How?
For versions of WP before 6.9 we add our own static registry of modules that should have the data attribute added. For everything else we rely on WordPress/wordpress-develop#10357 which will add script modules to preload based on their interactivity support declared in
block.json.Testing Instructions
{ "loadOnClientNavigation": true }