[wp-trac] [WordPress Trac] #36448: When concatenating scripts in script-loader dependencies may not be honoured.

WordPress Trac noreply at wordpress.org
Fri Apr 8 09:34:01 UTC 2016


#36448: When concatenating scripts in script-loader dependencies may not be
honoured.
---------------------------+-----------------------------
 Reporter:  gitlost        |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Script Loader  |    Version:  4.4.2
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 This is a follow on from
 [https://core.trac.wordpress.org/ticket/36392#comment:13
 36392#comment:13]. Ticket #15833 looks to be related.

 When concatenating scripts, dependencies may not be honoured for scripts
 that trigger the use of `$print_html` (ie those outside the default
 directories or having conditionals or (if available!) inline scripts).

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

 {{{#!php
 <?php
 public function test_wp_script_conditional_concat_dependency() {
         global $wp_scripts;

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

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

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

         $wp_print_scripts = get_echo( 'wp_print_scripts' );
         $print_scripts = get_echo( '_print_scripts' );

         $expected  = "<!--[if blah]>\n";
         $expected .= "<script type='text/javascript'
 src='/directory/one.js?ver=1'></script>\n";
         $expected .= "<![endif]-->\n";
         $expected .= "<script type='text/javascript' src='/wp-admin/load-
 scripts.php?c=0&load%5B%5D=two,three&ver=1'></script>\n";

         $this->assertEquals( $expected, $print_scripts );
         $this->assertEquals( '', $wp_print_scripts );
 }
 }}}

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

 {{{
 <script type='text/javascript' src='/wp-admin/load-
 scripts.php?c=0&load%5B%5D=two,three&ver=1'></script>
 <!--[if blah]>
 <script type='text/javascript' src='/directory/one.js?ver=1'></script>
 <![endif]-->
 }}}

 The same is also true, ''mutatis mutandis'' (ahem), for styles, but I'll
 open a separate ticket for that.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36448>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list