gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

`gutenberg_register_packages_scripts()` can only be run once

Open mdawaffe opened this issue 7 years ago • 0 comments

Describe the bug

If gutenberg_register_packages_scripts() is run more than once, the dependencies for any packages' scripts with a core handle are removed.

The require_once() call will return true on all but the first run of gutenberg_register_packages_scripts(), which will wipe out any dependencies.

https://github.com/WordPress/gutenberg/blob/6fc0b707331e293c20866963b342cf2a4ca913de/lib/client-assets.php#L240-L243

Introduced in #17298.

To reproduce Steps to reproduce the behavior:

  1. Install an mu-plugin:
    <?php
    
    add_action( 'after_setup_theme', function() {
            wp_enqueue_script( 'jquery' );
    } );
    
    add_action( 'init', function() {
            wp_enqueue_script( 'wp-a11y' );
    } );
    
  2. Go to the homepage.
  3. See the following error in the JS Console:
    Uncaught TypeError: o(...) is not a function
       at Module.321 (index.js?ver=1574117808:1)
       at n (index.js?ver=1574117808:1)
       at wp.a11y.186 (index.js?ver=1574117808:1)
       at index.js?ver=1574117808:1
    
  4. View the homepage's HTML source.
  5. See that a11y has been included, but not dom-ready.

Expected behavior

gutenberg_register_packages_scripts() should be able to be run more than once.

Additional context

  • Gutenberg 6.9.0

mdawaffe avatar Nov 18 '19 23:11 mdawaffe