Make WordPress Core

Changeset 56092


Ignore:
Timestamp:
06/28/2023 02:14:58 PM (17 months ago)
Author:
azaozz
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-scripts.php

    r56033 r56092  
    908908     */
    909909    private function get_eligible_loading_strategy( $handle ) {
    910         $eligible = $this->filter_eligible_strategies( $handle );
    911 
    912         // Bail early once we know the eligible strategy is blocking.
     910        $intended = (string) $this->get_data( $handle, 'strategy' );
     911
     912        // Bail early if there is no intended strategy.
     913        if ( ! $intended ) {
     914            return '';
     915        }
     916
     917        // If the intended strategy is 'defer', limit the initial list of eligibles.
     918        $initial = ( 'defer' === $intended ) ? array( 'defer' ) : null;
     919
     920        $eligible = $this->filter_eligible_strategies( $handle, $initial );
     921
     922        // Return early once we know the eligible strategy is blocking.
    913923        if ( empty( $eligible ) ) {
    914924            return '';
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r56033 r56092  
    29332933
    29342934    /**
     2935     * Ensure tinymce scripts aren't loading async.
     2936     *
     2937     * @ticket 58648
     2938     */
     2939    public function test_printing_tinymce_scripts() {
     2940        global $wp_scripts;
     2941
     2942        wp_register_tinymce_scripts( $wp_scripts, true );
     2943
     2944        $actual = get_echo( 'wp_print_scripts', array( array( 'wp-tinymce' ) ) );
     2945
     2946        $this->assertStringNotContainsString( 'async', $actual );
     2947    }
     2948
     2949    /**
    29352950     * Parse an HTML markup fragment.
    29362951     *
Note: See TracChangeset for help on using the changeset viewer.