From 80e424ad55e0ef4d48959a9c91b226eae45b6a77 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 28 Jun 2023 14:14:58 +0000 Subject: [PATCH] Script Loader: Fix unintended adding of `async` to scripts that are printed 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 --- src/wp-includes/class-wp-scripts.php | 14 ++++++++++++-- tests/phpunit/tests/dependencies/scripts.php | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-scripts.php b/src/wp-includes/class-wp-scripts.php index 857f1e948b..0c85201bad 100644 --- a/src/wp-includes/class-wp-scripts.php +++ b/src/wp-includes/class-wp-scripts.php @@ -907,9 +907,19 @@ JS; * @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 ''; } diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 6395f18f8d..b3ff0ad123 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -2931,6 +2931,21 @@ HTML $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. *