WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 5 months ago

#36449 new defect (bug)

When concatenating styles in script-loader dependencies may not be honoured.

Reported by: gitlost Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4.2
Component: Script Loader Keywords:
Focuses: Cc:
PR Number:

Description

This is the (not-really) evil twin of the scripts issue 36448.

When concatenating styles, dependencies may not be honoured for styles that trigger the use of $print_html (ie those outside the default directories or having conditionals or alts).

For instance this test where three depends on one and one has a conditional:

<?php
public function test_wp_style_conditional_concat_dependency() {
        global $wp_styles;

        $wp_styles->do_concat = true;
        $wp_styles->default_dirs = array( '/directory/' );
        $wp_styles->default_version = 1;

        wp_enqueue_style( 'one', '/directory/one.js', array(), 1 );
        wp_enqueue_style( 'two', '/directory/two.js', array(), 1 );
        wp_enqueue_style( 'three', '/directory/three.js', array( 'one' ), 1 );

        wp_style_add_data( 'one', 'conditional', 'blah' );

        $wp_print_styles = get_echo( 'wp_print_styles' );
        $print_styles = get_echo( '_print_styles' );

        $expected  = "<!--[if blah]>\n";
        $expected .= "<link rel='stylesheet' id='one-css'  href='/directory/one.js?ver=1' type='text/css' media='all' />\n";
        $expected .= "<![endif]-->\n";
        $expected .= "<link rel='stylesheet' href='/wp-admin/load-styles.php?c=0&amp;dir=ltr&amp;load%5B%5D=two,three&amp;ver=1' type='text/css' media='all' />\n";

        $this->assertEquals( $expected, $print_styles );
        $this->assertEquals( '', $wp_print_styles );
}

will fail, as the conditional stuff will always be outputted after the concatenated styles, resulting in one appearing after three:

<link rel='stylesheet' href='/wp-admin/load-styles.php?c=0&amp;dir=ltr&amp;load%5B%5D=two,three&amp;ver=1' type='text/css' media='all' />
<!--[if blah]>
<link rel='stylesheet' id='one-css'  href='/directory/one.js?ver=1' type='text/css' media='all' />
<![endif]-->

Attachments (1)

36449.batch.patch (7.2 KB) - added by gitlost 4 years ago.
Demo of "batch" stuff for styles.

Download all attachments as: .zip

Change History (2)

@gitlost
4 years ago

Demo of "batch" stuff for styles.

#1 @gitlost
4 years ago

The above patch is a first-pass at a styles version of the "batch" patch for scripts. It includes the test mentioned in the OP.

Note: See TracTickets for help on using tickets.