Skip to content

Commit

Permalink
Editor: Ensure defer loading strategy is only applied to a block's vi…
Browse files Browse the repository at this point in the history
…ewScript.

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


git-svn-id: https://develop.svn.wordpress.org/trunk@56403 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
westonruter committed Aug 17, 2023
1 parent cc828e2 commit 2bd2a2f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,19 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) {
: 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_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array();
$result = wp_register_script(
$script_handle,
$script_uri,
$script_dependencies,
isset( $script_asset['version'] ) ? $script_asset['version'] : false,
array( 'strategy' => 'defer' )
$script_args
);
if ( ! $result ) {
return false;
Expand Down

0 comments on commit 2bd2a2f

Please sign in to comment.