[wp-trac] [WordPress Trac] #36392: wp_add_inline_script() breaks script dependency order when using script loader (no SCRIPT_DEBUG)

WordPress Trac noreply at wordpress.org
Wed Apr 6 21:21:10 UTC 2016


#36392: wp_add_inline_script() breaks script dependency order when using script
loader (no SCRIPT_DEBUG)
----------------------------------------+-------------------------
 Reporter:  westonruter                 |       Owner:  swissspidy
     Type:  defect (bug)                |      Status:  assigned
 Priority:  high                        |   Milestone:  4.5
Component:  Script Loader               |     Version:  trunk
 Severity:  major                       |  Resolution:
 Keywords:  has-unit-tests needs-patch  |     Focuses:
----------------------------------------+-------------------------

Comment (by gitlost):

 However!.... there is a pre-4.5 issue here with the use of `$print_html`
 in that dependencies will not be honoured for handles which use it (ie
 those using conditionals or inline scripts), for instance this test (using
 pre-4.5 `wp_script_add_data()`):

 {{{#!php
 <?php
         /**
          * @ticket 36392
          */
         public function
 test_wp_script_conditional_with_concat_dependency() {
                 global $wp_scripts;

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

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

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

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

                 $ver = get_bloginfo( 'version' );

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

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

 }}}

 will fail, as the conditional stuff will always be outputted afterwards.

 I'll upload some demo code which puts the data into batches that seems to
 fix it.

 Should I just open a new ticket for this?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36392#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list