Commit ae3fd545d05 for woocommerce

commit ae3fd545d05374be87072d7a16b937b71bc153a0
Author: Vladimir Reznichenko <kalessil@gmail.com>
Date:   Fri Nov 27 10:46:37 2026 +0100

    [Performance] Introduce lazy block registration for product grids and listing blocks (#71212)

diff --git a/plugins/woocommerce/changelog/performance-optimize-blocks-registration-product-grids b/plugins/woocommerce/changelog/performance-optimize-blocks-registration-product-grids
new file mode 100644
index 00000000000..8bcfecdb090
--- /dev/null
+++ b/plugins/woocommerce/changelog/performance-optimize-blocks-registration-product-grids
@@ -0,0 +1,4 @@
+Significance: minor
+Type: performance
+
+Introduced lazy block registration for product listing and grids blocks.
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/handpicked-products/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/handpicked-products/block.json
index 2302da2be85..3ee81a9547c 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/handpicked-products/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/handpicked-products/block.json
@@ -78,6 +78,11 @@
 			"default": false
 		}
 	},
+	"editorStyle": "wc-blocks-editor-style",
+	"style": [
+		"wc-blocks-style",
+		"wc-blocks-style-all-products"
+	],
 	"textdomain": "woocommerce",
 	"apiVersion": 3,
 	"$schema": "https://schemas.wp.org/trunk/block.json"
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-best-sellers/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-best-sellers/block.json
index 8c9f9a003a7..01a9ef2ddc9 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-best-sellers/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-best-sellers/block.json
@@ -90,6 +90,11 @@
 			"default": "popularity"
 		}
 	},
+	"editorStyle": "wc-blocks-editor-style",
+	"style": [
+		"wc-blocks-style",
+		"wc-blocks-style-all-products"
+	],
 	"textdomain": "woocommerce",
 	"apiVersion": 3,
 	"$schema": "https://schemas.wp.org/trunk/block.json"
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-category/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-category/block.json
index 43228a85e71..acc5b9f9cc4 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-category/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-category/block.json
@@ -90,6 +90,11 @@
 			"default": "date"
 		}
 	},
+	"editorStyle": "wc-blocks-editor-style",
+	"style": [
+		"wc-blocks-style",
+		"wc-blocks-style-all-products"
+	],
 	"textdomain": "woocommerce",
 	"apiVersion": 3,
 	"$schema": "https://schemas.wp.org/trunk/block.json"
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-new/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-new/block.json
index cacd96da894..803436928d6 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-new/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-new/block.json
@@ -90,6 +90,11 @@
 			"default": "date"
 		}
 	},
+	"editorStyle": "wc-blocks-editor-style",
+	"style": [
+		"wc-blocks-style",
+		"wc-blocks-style-all-products"
+	],
 	"textdomain": "woocommerce",
 	"apiVersion": 3,
 	"$schema": "https://schemas.wp.org/trunk/block.json"
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-on-sale/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-on-sale/block.json
index 44450d0c6e1..c66490ec0f0 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-on-sale/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-on-sale/block.json
@@ -14,6 +14,11 @@
 		"html": false,
 		"inserter": false
 	},
+	"editorStyle": "wc-blocks-editor-style",
+	"style": [
+		"wc-blocks-style",
+		"wc-blocks-style-all-products"
+	],
 	"textdomain": "woocommerce",
 	"attributes": {
 		"columns": {
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-tag/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-tag/block.json
index 5f22f46223b..aa59a86fc1e 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-tag/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-tag/block.json
@@ -77,6 +77,11 @@
 			"type": "array"
 		}
 	},
+	"editorStyle": "wc-blocks-editor-style",
+	"style": [
+		"wc-blocks-style",
+		"wc-blocks-style-all-products"
+	],
 	"textdomain": "woocommerce",
 	"apiVersion": 3,
 	"$schema": "https://schemas.wp.org/trunk/block.json"
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-top-rated/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-top-rated/block.json
index f314a0c1f17..0c87e854aba 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-top-rated/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-top-rated/block.json
@@ -90,6 +90,11 @@
 			"default": "rating"
 		}
 	},
+	"editorStyle": "wc-blocks-editor-style",
+	"style": [
+		"wc-blocks-style",
+		"wc-blocks-style-all-products"
+	],
 	"textdomain": "woocommerce",
 	"apiVersion": 3,
 	"$schema": "https://schemas.wp.org/trunk/block.json"
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/products-by-attribute/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/products-by-attribute/block.json
index 457ef3f58c4..b61d0abf1bc 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/products-by-attribute/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/products-by-attribute/block.json
@@ -87,6 +87,11 @@
 			"type": "array"
 		}
 	},
+	"editorStyle": "wc-blocks-editor-style",
+	"style": [
+		"wc-blocks-style",
+		"wc-blocks-style-all-products"
+	],
 	"textdomain": "woocommerce",
 	"apiVersion": 3,
 	"$schema": "https://schemas.wp.org/trunk/block.json"
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/products/all-products/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/products/all-products/block.json
index a6adeb31d52..313880b41d6 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/products/all-products/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/products/all-products/block.json
@@ -39,5 +39,9 @@
 			"type": "boolean",
 			"default": false
 		}
-	}
+	},
+	"style": [
+		"wc-blocks-style",
+		"file:../all-products.css"
+	]
 }
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AbstractProductGrid.php b/plugins/woocommerce/src/Blocks/BlockTypes/AbstractProductGrid.php
index 07b01f6ca48..8f63248d1f9 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AbstractProductGrid.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AbstractProductGrid.php
@@ -715,10 +715,10 @@ abstract class AbstractProductGrid extends AbstractDynamicBlock {
 	/**
 	 * Get the frontend style handle for this block type.
 	 *
-	 * @return string[]
+	 * @return string[]|null
 	 */
 	protected function get_block_type_style() {
 		// Currently these blocks rely on the styles from the All Products block.
-		return [ 'wc-blocks-style', 'wc-blocks-style-all-products' ];
+		return array( 'wc-blocks-style', 'wc-blocks-style-all-products' );
 	}
 }
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AllProducts.php b/plugins/woocommerce/src/Blocks/BlockTypes/AllProducts.php
index a86664180bb..72d8313961c 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AllProducts.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AllProducts.php
@@ -5,6 +5,8 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes;
  * AllProducts class.
  */
 class AllProducts extends AbstractBlock {
+	// No EnableBlockJsonAssetsTrait: get_block_type_style() registers wc-blocks-style-all-products, which the grid blocks depend on.
+
 	/**
 	 * Block name.
 	 *
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/HandpickedProducts.php b/plugins/woocommerce/src/Blocks/BlockTypes/HandpickedProducts.php
index 80f29b2b180..df717a49649 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/HandpickedProducts.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/HandpickedProducts.php
@@ -7,6 +7,8 @@ use Automattic\WooCommerce\Enums\ProductStockStatus;
  * HandpickedProducts class.
  */
 class HandpickedProducts extends AbstractProductGrid {
+	use EnableBlockJsonAssetsTrait;
+
 	/**
 	 * Block name.
 	 *
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductBestSellers.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductBestSellers.php
index b1cc4467775..f6d7419f434 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductBestSellers.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductBestSellers.php
@@ -5,6 +5,7 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes;
  * ProductBestSellers class.
  */
 class ProductBestSellers extends AbstractProductGrid {
+	use EnableBlockJsonAssetsTrait;

 	/**
 	 * Block name.
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductCategory.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductCategory.php
index f0ae248192d..07f117af10a 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductCategory.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductCategory.php
@@ -5,6 +5,8 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes;
  * ProductCategory class.
  */
 class ProductCategory extends AbstractProductGrid {
+	use EnableBlockJsonAssetsTrait;
+
 	/**
 	 * Block name.
 	 *
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductNew.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductNew.php
index d2ac9acee72..1141b8dfc59 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductNew.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductNew.php
@@ -5,6 +5,7 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes;
  * ProductNew class.
  */
 class ProductNew extends AbstractProductGrid {
+	use EnableBlockJsonAssetsTrait;

 	/**
 	 * Block name.
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductOnSale.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductOnSale.php
index 7ad14cfa41a..3d747f5e976 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductOnSale.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductOnSale.php
@@ -5,6 +5,7 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes;
  * ProductOnSale class.
  */
 class ProductOnSale extends AbstractProductGrid {
+	use EnableBlockJsonAssetsTrait;

 	/**
 	 * Block name.
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductTag.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductTag.php
index fc0fdfe4f88..a9194f82a68 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductTag.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductTag.php
@@ -5,6 +5,8 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes;
  * ProductTag class.
  */
 class ProductTag extends AbstractProductGrid {
+	use EnableBlockJsonAssetsTrait;
+
 	/**
 	 * Block name.
 	 *
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductTopRated.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductTopRated.php
index db3cfbc7b39..96c286520d3 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductTopRated.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductTopRated.php
@@ -5,6 +5,7 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes;
  * ProductTopRated class.
  */
 class ProductTopRated extends AbstractProductGrid {
+	use EnableBlockJsonAssetsTrait;

 	/**
 	 * Block name.
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductsByAttribute.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductsByAttribute.php
index 8c75d1c39e5..21f06b5dd56 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductsByAttribute.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductsByAttribute.php
@@ -5,6 +5,7 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes;
  * ProductsByAttribute class.
  */
 class ProductsByAttribute extends AbstractProductGrid {
+	use EnableBlockJsonAssetsTrait;

 	/**
 	 * Block name.
diff --git a/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php b/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
index 3b9f7ad5f5b..8ac11940a55 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
@@ -88,6 +88,8 @@ final class BlockTypesLazyController {
 			$this->get_order_confirmation_blocks(),
 			$this->get_add_to_cart_with_options_blocks(),
 			$this->get_product_display_element_blocks(),
+			$this->get_product_grid_blocks(),
+			$this->get_product_listing_blocks(),
 		);
 		foreach ( $block_groups as $blocks_group ) {
 			foreach ( $blocks_group as $block_name => $block_class ) {
@@ -332,4 +334,52 @@ final class BlockTypesLazyController {

 		return $list;
 	}
+
+	/**
+	 * Side effect free and stateless product grid blocks.
+	 *
+	 * @return array<string,string>
+	 */
+	private function get_product_grid_blocks(): array {
+		if ( ! is_admin() ) {
+			// All inherit enqueue_data() from AbstractProductGrid with editor-visible theme support data.
+			return array(
+				'handpicked-products'   => \Automattic\WooCommerce\Blocks\BlockTypes\HandpickedProducts::class,
+				'product-best-sellers'  => \Automattic\WooCommerce\Blocks\BlockTypes\ProductBestSellers::class,
+				'product-new'           => \Automattic\WooCommerce\Blocks\BlockTypes\ProductNew::class,
+				'product-on-sale'       => \Automattic\WooCommerce\Blocks\BlockTypes\ProductOnSale::class,
+				'product-top-rated'     => \Automattic\WooCommerce\Blocks\BlockTypes\ProductTopRated::class,
+				'products-by-attribute' => \Automattic\WooCommerce\Blocks\BlockTypes\ProductsByAttribute::class,
+				'product-category'      => \Automattic\WooCommerce\Blocks\BlockTypes\ProductCategory::class,
+				'product-tag'           => \Automattic\WooCommerce\Blocks\BlockTypes\ProductTag::class,
+			);
+		}
+
+		return array();
+	}
+
+	/**
+	 * Side effect free and stateless product listing blocks (shop, category, tag pages).
+	 *
+	 * @return array<string,string>
+	 */
+	private function get_product_listing_blocks(): array {
+		// ProductCollection\Controller: excluded — query_loop_block_query_vars, pre_render_block, rest_api_init, render_block_data.
+		// ProductQuery: excluded — query_vars, pre_render_block, rest_product_query, render_block_core/*.
+		// ProductButton: excluded — hooks wp_enqueue_scripts in enqueue_assets() to dequeue legacy add-to-cart scripts.
+		// ProductTemplate: excluded — block_type_metadata_settings (before parent — must run during other blocks' registration).
+		// ProductResultsCount: excluded — custom get_block_type_style() with non-standard CSS path.
+		$list = array(
+			'catalog-sorting'               => \Automattic\WooCommerce\Blocks\BlockTypes\CatalogSorting::class,
+			'category-title'                => \Automattic\WooCommerce\Blocks\BlockTypes\CategoryTitle::class,
+			'category-description'          => \Automattic\WooCommerce\Blocks\BlockTypes\CategoryDescription::class,
+			'product-collection-no-results' => \Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection\NoResults::class,
+		);
+		if ( ! is_admin() ) {
+			// AllProducts overrides enqueue_data() with editor-visible theme support data, hence loads eagerly in admin.
+			$list['all-products'] = \Automattic\WooCommerce\Blocks\BlockTypes\AllProducts::class;
+		}
+
+		return $list;
+	}
 }