Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gutenberg_register_packages_scripts() can only be run once #18596

Closed
mdawaffe opened this issue Nov 18, 2019 · 0 comments · Fixed by #18599
Closed

gutenberg_register_packages_scripts() can only be run once #18596

mdawaffe opened this issue Nov 18, 2019 · 0 comments · Fixed by #18599
Assignees
Labels
[Status] In Progress Tracking issues with work in progress [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended [Type] Build Tooling Issues or PRs related to build tooling

Comments

@mdawaffe
Copy link
Contributor

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.

$asset = file_exists( $asset_file )
? require_once( $asset_file )
: null;
$dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : array();

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 mdawaffe added [Type] Bug An existing feature does not function as intended [Type] Build Tooling Issues or PRs related to build tooling [Tool] WP Scripts /packages/scripts labels Nov 18, 2019
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended [Type] Build Tooling Issues or PRs related to build tooling
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants