Commit 3c7b65d0e24 for woocommerce

commit 3c7b65d0e2481f7985d19c0f8e985906a7ee82ee
Author: Vladimir Reznichenko <kalessil@gmail.com>
Date:   Mon Nov 16 16:08:11 2026 +0100

    [Performance] Introduce lazy block registration for add to cart with options blocks (#70860)

diff --git a/plugins/woocommerce/changelog/performance-optimize-blocks-registration-add-to-cart b/plugins/woocommerce/changelog/performance-optimize-blocks-registration-add-to-cart
new file mode 100644
index 00000000000..80b2e16cd1a
--- /dev/null
+++ b/plugins/woocommerce/changelog/performance-optimize-blocks-registration-add-to-cart
@@ -0,0 +1,4 @@
+Significance: minor
+Type: performance
+
+Introduced lazy block registration for add to cart with options blocks.
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/AddToCartWithOptions.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/AddToCartWithOptions.php
index a2f919667ab..f7a9d11ba7f 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/AddToCartWithOptions.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/AddToCartWithOptions.php
@@ -16,7 +16,6 @@ use Automattic\WooCommerce\Internal\ShopperLists\ShopperListsController;
  * AddToCartWithOptions class.
  */
 class AddToCartWithOptions extends AbstractBlock {
-
 	use EnableBlockJsonAssetsTrait;

 	/**
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItem.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItem.php
index eed91c13526..24a9f3ae39e 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItem.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItem.php
@@ -12,7 +12,6 @@ use WP_Block;
  * It's responsible to render each child product in a form of a list item.
  */
 class GroupedProductItem extends AbstractBlock {
-
 	use EnableBlockJsonAssetsTrait;

 	/**
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItemLabel.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItemLabel.php
index 8eeef4255aa..bc9952152f2 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItemLabel.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItemLabel.php
@@ -13,7 +13,6 @@ use WP_Block;
  * It's responsible to render the label for each child product.
  */
 class GroupedProductItemLabel extends AbstractBlock {
-
 	use EnableBlockJsonAssetsTrait;

 	/**
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItemSelector.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItemSelector.php
index cf6fcd77e0f..0190d0ac851 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItemSelector.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductItemSelector.php
@@ -14,7 +14,6 @@ use WP_Block;
  * a checkbox, or a link.
  */
 class GroupedProductItemSelector extends AbstractBlock {
-
 	use EnableBlockJsonAssetsTrait;

 	/**
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductSelector.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductSelector.php
index 916b6c95cf8..46a2a9d516f 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductSelector.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/GroupedProductSelector.php
@@ -11,7 +11,6 @@ use Automattic\WooCommerce\Enums\ProductType;
  * Block type for grouped product selector in add to cart with options.
  */
 class GroupedProductSelector extends AbstractBlock {
-
 	use EnableBlockJsonAssetsTrait;

 	/**
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/QuantitySelector.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/QuantitySelector.php
index 0f49d60144b..a5233825305 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/QuantitySelector.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/QuantitySelector.php
@@ -13,7 +13,6 @@ use Automattic\WooCommerce\Enums\ProductType;
  * Block type for quantity selector in add to cart with options.
  */
 class QuantitySelector extends AbstractBlock {
-
 	use EnableBlockJsonAssetsTrait;

 	/**
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationDescription.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationDescription.php
index 6b743797752..e6f3feaeba0 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationDescription.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationDescription.php
@@ -9,7 +9,6 @@ use Automattic\WooCommerce\Blocks\BlockTypes\EnableBlockJsonAssetsTrait;
  * VariationDescription class.
  */
 class VariationDescription extends AbstractBlock {
-
 	use EnableBlockJsonAssetsTrait;

 	/**
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelector.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelector.php
index 4978c68464f..9a5ea8990df 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelector.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelector.php
@@ -11,7 +11,6 @@ use Automattic\WooCommerce\Enums\ProductType;
  * Block type for variation selector in add to cart with options.
  */
 class VariationSelector extends AbstractBlock {
-
 	use EnableBlockJsonAssetsTrait;

 	/**
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelectorAttribute.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelectorAttribute.php
index b1b3f6425c3..9f6f0a6f883 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelectorAttribute.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelectorAttribute.php
@@ -12,7 +12,6 @@ use WP_Block;
  * Block type for Variation Selector in the Add to Cart + Options block.
  */
 class VariationSelectorAttribute extends AbstractBlock {
-
 	use EnableBlockJsonAssetsTrait;

 	/**
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelectorAttributeName.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelectorAttributeName.php
index 27056a9e420..3e85392caec 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelectorAttributeName.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/VariationSelectorAttributeName.php
@@ -12,7 +12,6 @@ use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
  * It's responsible to render the attribute name.
  */
 class VariationSelectorAttributeName extends AbstractBlock {
-
 	use EnableBlockJsonAssetsTrait;

 	/**
diff --git a/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php b/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
index 03393d44330..d2c875186c5 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
@@ -67,7 +67,7 @@ final class BlockTypesLazyController {

 		foreach ( $inner_block_groups as $blocks_group ) {
 			foreach ( $blocks_group as $block_name => $block_class ) {
-				if ( isset( $whitelisted[ $block_class ] ) ) {
+				if ( isset( $whitelisted[ $block_class ] ) && false === has_action( "woocommerce_blocks_{$block_name}_block_registration" ) ) {
 					$registered_block_type = register_block_type_from_metadata(
 						$this->asset_api->generate_block_metadata_path( $block_name, 'inner-blocks/' ),
 						array(
@@ -86,10 +86,11 @@ final class BlockTypesLazyController {
 		$is_admin     = is_admin();
 		$block_groups = array(
 			$this->get_order_confirmation_blocks(),
+			$this->get_add_to_cart_with_options_blocks(),
 		);
 		foreach ( $block_groups as $blocks_group ) {
 			foreach ( $blocks_group as $block_name => $block_class ) {
-				if ( isset( $whitelisted[ $block_class ] ) ) {
+				if ( isset( $whitelisted[ $block_class ] ) && false === has_action( "woocommerce_blocks_{$block_name}_block_registration" ) ) {
 					// Backward compatibility: use original handles for the editor scripts and blocks styles.
 					if ( ! $unified_editor_assets && $is_admin ) {
 						$this->asset_api->register_script( 'wc-' . $block_name . '-block', $this->asset_api->get_block_asset_build_path( $block_name ), array( 'wc-blocks' ) );
@@ -267,4 +268,29 @@ final class BlockTypesLazyController {

 		return $list;
 	}
+
+	/**
+	 * Side effect free and stateless add to cart with options blocks.
+	 *
+	 * @return array<string,string>
+	 */
+	private function get_add_to_cart_with_options_blocks(): array {
+		$list = array(
+			'add-to-cart-with-options-quantity-selector'  => \Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions\QuantitySelector::class,
+			'add-to-cart-with-options-variation-description' => \Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions\VariationDescription::class,
+			'add-to-cart-with-options-variation-selector' => \Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions\VariationSelector::class,
+			'add-to-cart-with-options-variation-selector-attribute-name' => \Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions\VariationSelectorAttributeName::class,
+			'add-to-cart-with-options-grouped-product-selector' => \Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions\GroupedProductSelector::class,
+			'add-to-cart-with-options-grouped-product-item' => \Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions\GroupedProductItem::class,
+			'add-to-cart-with-options-grouped-product-item-selector' => \Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions\GroupedProductItemSelector::class,
+			'add-to-cart-with-options-grouped-product-item-label' => \Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions\GroupedProductItemLabel::class,
+		);
+		if ( ! is_admin() ) {
+			// These blocks override enqueue_data() with editor-visible data, hence load eagerly in admin.
+			$list['add-to-cart-with-options']                              = \Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions\AddToCartWithOptions::class;
+			$list['add-to-cart-with-options-variation-selector-attribute'] = \Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions\VariationSelectorAttribute::class;
+		}
+
+		return $list;
+	}
 }