Commit 4bd9f4da4e1 for woocommerce

commit 4bd9f4da4e15cbbf25510aab075ffa32c6a64e0d
Author: Vladimir Reznichenko <kalessil@gmail.com>
Date:   Tue Dec 1 08:50:07 2026 +0100

    [Performance] Introduce lazy block registration for product filters blocks (#71213)

diff --git a/plugins/woocommerce/changelog/performance-optimize-blocks-registration-product-filters b/plugins/woocommerce/changelog/performance-optimize-blocks-registration-product-filters
new file mode 100644
index 00000000000..688788a38af
--- /dev/null
+++ b/plugins/woocommerce/changelog/performance-optimize-blocks-registration-product-filters
@@ -0,0 +1,4 @@
+Significance: minor
+Type: performance
+
+Introduced lazy block registration for product filters blocks.
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/clear-button/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/clear-button/block.json
index fe72d4dfe1a..da07ff9a626 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/clear-button/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/clear-button/block.json
@@ -5,6 +5,10 @@
 	"description": "Let shoppers clear any active filters.",
 	"category": "woocommerce",
 	"keywords": [ "WooCommerce", "clear filters" ],
+	"style": [
+		"wc-blocks-style",
+		"file:../product-filter-clear-button.css"
+	],
 	"textdomain": "woocommerce",
 	"apiVersion": 3,
 	"ancestor": [ "woocommerce/product-filter-active" ],
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilterActive.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilterActive.php
index 96e0ec2d8b8..60f035ba26a 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilterActive.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilterActive.php
@@ -10,6 +10,8 @@ use WP_Block;
  * Product Filter: Active Block.
  */
 final class ProductFilterActive extends AbstractBlock {
+	use EnableBlockJsonAssetsTrait;
+
 	/**
 	 * Block name.
 	 *
@@ -117,32 +119,4 @@ final class ProductFilterActive extends AbstractBlock {
 			)
 		);
 	}
-
-	/**
-	 * Get the frontend style handle for this block type.
-	 *
-	 * @return null
-	 */
-	protected function get_block_type_style() {
-		return null;
-	}
-
-	/**
-	 * Disable the editor style handle for this block type.
-	 *
-	 * @return null
-	 */
-	protected function get_block_type_editor_style() {
-		return null;
-	}
-
-	/**
-	 * Disable the script handle for this block type. We use block.json to load the script.
-	 *
-	 * @param string|null $key The key of the script to get.
-	 * @return null
-	 */
-	protected function get_block_type_script( $key = null ) {
-		return null;
-	}
 }
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilterClearButton.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilterClearButton.php
index b0a53943269..b870c10e55e 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilterClearButton.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilterClearButton.php
@@ -8,6 +8,7 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes;
  * Product Filter: Clear Button Block.
  */
 final class ProductFilterClearButton extends AbstractBlock {
+	use EnableBlockJsonAssetsTrait;

 	/**
 	 * Block name.
@@ -16,17 +17,6 @@ final class ProductFilterClearButton extends AbstractBlock {
 	 */
 	protected $block_name = 'product-filter-clear-button';

-	/**
-	 * Get the frontend script handle for this block type.
-	 *
-	 * @param string $key Data to get, or default to everything.
-	 *
-	 * @return null
-	 */
-	protected function get_block_type_script( $key = null ) {
-		return null;
-	}
-
 	/**
 	 * Include and render the block.
 	 *
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilters.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilters.php
index 6c815b694bc..56e2994932d 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilters.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductFilters.php
@@ -14,6 +14,7 @@ use WP_Block;
  * ProductFilters class.
  */
 class ProductFilters extends AbstractBlock {
+	use EnableBlockJsonAssetsTrait;

 	/**
 	 * Block name.
@@ -384,34 +385,6 @@ CSS;
 		);
 	}

-	/**
-	 * Disable the style handle for this block type. We use block.json to load the style.
-	 *
-	 * @return null
-	 */
-	protected function get_block_type_style() {
-		return null;
-	}
-
-	/**
-	 * Disable the editor style handle for this block type. We use block.json to load the style.
-	 *
-	 * @return null
-	 */
-	protected function get_block_type_editor_style() {
-		return null;
-	}
-
-	/**
-	 * Disable the script handle for this block type. We use block.json to load the script.
-	 *
-	 * @param string|null $key The key of the script to get.
-	 * @return null
-	 */
-	protected function get_block_type_script( $key = null ) {
-		return null;
-	}
-
 	/**
 	 * Get the canonical URL without pagination.
 	 *
diff --git a/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php b/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
index 239df61caf6..fa9c6fdc8b5 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
@@ -91,6 +91,7 @@ final class BlockTypesLazyController {
 			$this->get_product_grid_blocks(),
 			$this->get_product_listing_blocks(),
 			$this->get_product_reviews_blocks(),
+			$this->get_filter_blocks(),
 		);
 		foreach ( $block_groups as $blocks_group ) {
 			foreach ( $blocks_group as $block_name => $block_class ) {
@@ -406,4 +407,32 @@ final class BlockTypesLazyController {
 			'product-review-template'             => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewTemplate::class,
 		);
 	}
+
+	/**
+	 * Side effect free and stateless filter blocks.
+	 *
+	 * @return array<string,string>
+	 */
+	private function get_filter_blocks(): array {
+		// Legacy filter blocks (ActiveFilters, AttributeFilter, PriceFilter, RatingFilter, StockFilter, FilterWrapper): excluded — frontend scripts not declared in block.json.
+		// ProductFilterStatus: excluded — overrides initialize() with woocommerce_blocks_product_filters_selected_items filter.
+		// ProductFilterPrice: excluded — overrides initialize() with woocommerce_blocks_product_filters_selected_items filter.
+		// ProductFilterAttribute: excluded — overrides initialize() with selected_items filter, deleted_transient, wp_loaded → patterns.
+		// ProductFilterRating: excluded — overrides initialize() with woocommerce_blocks_product_filters_selected_items filter.
+		// ProductFilterTaxonomy: excluded — overrides initialize() with selected_items filter, REST field registration.
+		$list = array(
+			'product-filter-price-slider'    => \Automattic\WooCommerce\Blocks\BlockTypes\ProductFilterPriceSlider::class,
+			'product-filter-active'          => \Automattic\WooCommerce\Blocks\BlockTypes\ProductFilterActive::class,
+			'product-filter-removable-chips' => \Automattic\WooCommerce\Blocks\BlockTypes\ProductFilterRemovableChips::class,
+			'product-filter-clear-button'    => \Automattic\WooCommerce\Blocks\BlockTypes\ProductFilterClearButton::class,
+			'product-filter-checkbox-list'   => \Automattic\WooCommerce\Blocks\BlockTypes\ProductFilterCheckboxList::class,
+		);
+		if ( ! is_admin() ) {
+			// These blocks override enqueue_data() with editor-visible data, hence load eagerly in admin.
+			$list['product-filters']      = \Automattic\WooCommerce\Blocks\BlockTypes\ProductFilters::class;
+			$list['product-filter-chips'] = \Automattic\WooCommerce\Blocks\BlockTypes\ProductFilterChips::class;
+		}
+
+		return $list;
+	}
 }