Editor: Ensure defer loading strategy is only applied to a block's viewScript.

Amends [56398].
Props gziolo, westonruter.
Fixes #59115.

Built from https://develop.svn.wordpress.org/trunk@56403


git-svn-id: http://core.svn.wordpress.org/trunk@55915 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2023-08-17 16:39:18 +00:00
parent a8ab676b36
commit 36d24b511a
2 changed files with 7 additions and 2 deletions

View File

@ -164,6 +164,11 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) {
: get_theme_file_uri( str_replace( $stylesheet_path_norm, '', $script_path_norm ) ); : get_theme_file_uri( str_replace( $stylesheet_path_norm, '', $script_path_norm ) );
} }
$script_args = array();
if ( 'viewScript' === $field_name ) {
$script_args['strategy'] = 'defer';
}
$script_asset = require $script_asset_path; $script_asset = require $script_asset_path;
$script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array();
$result = wp_register_script( $result = wp_register_script(
@ -171,7 +176,7 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) {
$script_uri, $script_uri,
$script_dependencies, $script_dependencies,
isset( $script_asset['version'] ) ? $script_asset['version'] : false, isset( $script_asset['version'] ) ? $script_asset['version'] : false,
array( 'strategy' => 'defer' ) $script_args
); );
if ( ! $result ) { if ( ! $result ) {
return false; return false;

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.4-alpha-56402'; $wp_version = '6.4-alpha-56403';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.