Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix the order of enqueued scripts in the Mini-Cart block (#9749)
Browse files Browse the repository at this point in the history
* Fix the order of enqueued scripts in the Mini-Cart block

* Use again wp_script_is() to detect is a script has been enqueued or not
  • Loading branch information
Aljullu authored Jun 8, 2023
1 parent 3fb911b commit 49e6d96
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/BlockTypes/MiniCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ protected function initialize() {
parent::initialize();
add_action( 'wp_loaded', array( $this, 'register_empty_cart_message_block_pattern' ) );
add_action( 'wp_print_footer_scripts', array( $this, 'enqueue_wc_settings' ), 1 );
// We need this action to run after the equivalent in AssetDataRegistry.
add_action( 'wp_print_footer_scripts', array( $this, 'print_lazy_load_scripts' ), 3 );
// We need this action to run after enqueue_wc_settings() and dequeue_wc_settings(),
// otherwise it might incorrectly consider wc_settings script to be enqueued.
add_action( 'wp_print_footer_scripts', array( $this, 'print_lazy_load_scripts' ), 4 );
}

/**
Expand Down Expand Up @@ -220,7 +221,7 @@ public function enqueue_wc_settings() {
// AssetDataRegistry knows it's going to load.
wp_enqueue_script( 'wc-settings' );
// After AssetDataRegistry function runs, we dequeue `wc-settings`.
add_action( 'wp_print_footer_scripts', array( $this, 'dequeue_wc_settings' ), 4 );
add_action( 'wp_print_footer_scripts', array( $this, 'dequeue_wc_settings' ), 3 );
}

/**
Expand Down Expand Up @@ -332,7 +333,7 @@ protected function append_script_and_deps_src( $script ) {
$wp_scripts = wp_scripts();

// This script and its dependencies have already been appended.
if ( ! $script || array_key_exists( $script->handle, $this->scripts_to_lazy_load ) || isset( $wp_scripts->queue[ $script->handle ] ) ) {
if ( ! $script || array_key_exists( $script->handle, $this->scripts_to_lazy_load ) || wp_script_is( $script->handle, 'enqueued' ) ) {
return;
}

Expand Down

0 comments on commit 49e6d96

Please sign in to comment.