Skip to content

Commit

Permalink
Script Loader: Fix unintended adding of async to scripts that are p…
Browse files Browse the repository at this point in the history
…rinted directly with `wp_print_scripts()` without enqueueing them beforehand.

Props: joemcgill, westonruter, felixarntz, peterwilsoncc.
See: #58648.

git-svn-id: https://develop.svn.wordpress.org/trunk@56092 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
azaozz committed Jun 28, 2023
1 parent a63be5a commit 80e424a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/wp-includes/class-wp-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,9 +907,19 @@ private function is_delayed_strategy( $strategy ) {
* @return string The best eligible loading strategy.
*/
private function get_eligible_loading_strategy( $handle ) {
$eligible = $this->filter_eligible_strategies( $handle );
$intended = (string) $this->get_data( $handle, 'strategy' );

// Bail early once we know the eligible strategy is blocking.
// Bail early if there is no intended strategy.
if ( ! $intended ) {
return '';
}

// If the intended strategy is 'defer', limit the initial list of eligibles.
$initial = ( 'defer' === $intended ) ? array( 'defer' ) : null;

$eligible = $this->filter_eligible_strategies( $handle, $initial );

// Return early once we know the eligible strategy is blocking.
if ( empty( $eligible ) ) {
return '';
}
Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit/tests/dependencies/scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2931,6 +2931,21 @@ static function() {
$this->assertSame( $expected, $print_scripts );
}

/**
* Ensure tinymce scripts aren't loading async.
*
* @ticket 58648
*/
public function test_printing_tinymce_scripts() {
global $wp_scripts;

wp_register_tinymce_scripts( $wp_scripts, true );

$actual = get_echo( 'wp_print_scripts', array( array( 'wp-tinymce' ) ) );

$this->assertStringNotContainsString( 'async', $actual );
}

/**
* Parse an HTML markup fragment.
*
Expand Down

0 comments on commit 80e424a

Please sign in to comment.