Commit e5a7d455787 for woocommerce
commit e5a7d4557873cc6098b9f033c3787adc8f7ef4e6
Author: Vladimir Reznichenko <kalessil@gmail.com>
Date: Fri Nov 27 11:31:13 2026 +0100
[Performance] Introduce lazy block registration for product reviews blocks (#71044)
diff --git a/plugins/woocommerce/changelog/performance-optimize-blocks-registration-product-review-blocks b/plugins/woocommerce/changelog/performance-optimize-blocks-registration-product-review-blocks
new file mode 100644
index 00000000000..3296ecf0ada
--- /dev/null
+++ b/plugins/woocommerce/changelog/performance-optimize-blocks-registration-product-review-blocks
@@ -0,0 +1,4 @@
+Significance: minor
+Type: performance
+
+Introduced lazy block registration for product reviews blocks.
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-author-name/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-author-name/block.json
index a0af2167bb3..1515dfb533b 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-author-name/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-author-name/block.json
@@ -64,5 +64,9 @@
"style": true
}
}
- }
+ },
+ "style": [
+ "wc-blocks-style",
+ "file:../product-review-author-name.css"
+ ]
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-content/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-content/block.json
index 18fedc64c4c..b46b7a86945 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-content/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-content/block.json
@@ -54,5 +54,9 @@
}
},
"html": false
- }
+ },
+ "style": [
+ "wc-blocks-style",
+ "file:../product-review-content.css"
+ ]
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-date/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-date/block.json
index 69f71147bc8..4d42446b1ba 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-date/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-date/block.json
@@ -60,5 +60,9 @@
"style": true
}
}
- }
+ },
+ "style": [
+ "wc-blocks-style",
+ "file:../product-review-date.css"
+ ]
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-template/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-template/block.json
index 9721133faa1..58a16505606 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-template/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/review-template/block.json
@@ -44,5 +44,9 @@
"style": true
}
}
- }
+ },
+ "style": [
+ "wc-blocks-style",
+ "file:../product-review-template.css"
+ ]
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-pagination/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-pagination/block.json
index 8493e4c9caf..f51923ecbbe 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-pagination/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-pagination/block.json
@@ -62,5 +62,9 @@
"interactivity": {
"clientNavigation": true
}
- }
+ },
+ "style": [
+ "wc-blocks-style",
+ "file:../product-reviews-pagination.css"
+ ]
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-title/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-title/block.json
index 7d4ca79271f..cdeee4675f0 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-title/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-reviews/inner-blocks/reviews-title/block.json
@@ -68,5 +68,9 @@
"interactivity": {
"clientNavigation": true
}
- }
+ },
+ "style": [
+ "wc-blocks-style",
+ "file:../product-reviews-title.css"
+ ]
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/all-reviews/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/all-reviews/block.json
index b9ded6da5a5..4a4db4ffc2f 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/all-reviews/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/all-reviews/block.json
@@ -18,5 +18,9 @@
"typography": {
"fontSize": true
}
- }
+ },
+ "style": [
+ "wc-blocks-style",
+ "file:../all-reviews.css"
+ ]
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-category/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-category/block.json
index 36a6293e741..90462dac453 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-category/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-category/block.json
@@ -18,5 +18,9 @@
"typography": {
"fontSize": true
}
- }
+ },
+ "style": [
+ "wc-blocks-style",
+ "file:../reviews-by-category.css"
+ ]
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-product/block.json b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-product/block.json
index 2f517ac231a..e75f722e7ba 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-product/block.json
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/reviews-by-product/block.json
@@ -18,5 +18,9 @@
"typography": {
"fontSize": true
}
- }
+ },
+ "style": [
+ "wc-blocks-style",
+ "file:../reviews-by-product.css"
+ ]
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewAuthorName.php b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewAuthorName.php
index ec1e15c66bc..fc2936b28c8 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewAuthorName.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewAuthorName.php
@@ -2,11 +2,14 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes\Reviews;
use Automattic\WooCommerce\Blocks\BlockTypes\AbstractBlock;
+use Automattic\WooCommerce\Blocks\BlockTypes\EnableBlockJsonAssetsTrait;
/**
* ProductReviewAuthorName class.
*/
class ProductReviewAuthorName extends AbstractBlock {
+ use EnableBlockJsonAssetsTrait;
+
/**
* Block name.
*
@@ -59,15 +62,4 @@ class ProductReviewAuthorName extends AbstractBlock {
$comment_author
);
}
-
- /**
- * Get the frontend script handle for this block type.
- *
- * @see $this->register_block_type()
- * @param string $key Data to get, or default to everything.
- * @return array|string|null
- */
- protected function get_block_type_script( $key = null ) {
- return null;
- }
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewContent.php b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewContent.php
index 5404513adac..7304f82263a 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewContent.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewContent.php
@@ -2,11 +2,14 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes\Reviews;
use Automattic\WooCommerce\Blocks\BlockTypes\AbstractBlock;
+use Automattic\WooCommerce\Blocks\BlockTypes\EnableBlockJsonAssetsTrait;
/**
* ProductReviewContent class.
*/
class ProductReviewContent extends AbstractBlock {
+ use EnableBlockJsonAssetsTrait;
+
/**
* Block name.
*
@@ -77,15 +80,4 @@ class ProductReviewContent extends AbstractBlock {
$comment_text
);
}
-
- /**
- * Get the frontend script handle for this block type.
- *
- * @see $this->register_block_type()
- * @param string $key Data to get, or default to everything.
- * @return array|string|null
- */
- protected function get_block_type_script( $key = null ) {
- return null;
- }
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewDate.php b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewDate.php
index fb0b1d34762..1f378cb74d7 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewDate.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewDate.php
@@ -2,11 +2,14 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes\Reviews;
use Automattic\WooCommerce\Blocks\BlockTypes\AbstractBlock;
+use Automattic\WooCommerce\Blocks\BlockTypes\EnableBlockJsonAssetsTrait;
/**
* ProductReviewDate class.
*/
class ProductReviewDate extends AbstractBlock {
+ use EnableBlockJsonAssetsTrait;
+
/**
* Block name.
*
@@ -54,15 +57,4 @@ class ProductReviewDate extends AbstractBlock {
$formatted_date
);
}
-
- /**
- * Get the frontend script handle for this block type.
- *
- * @see $this->register_block_type()
- * @param string $key Data to get, or default to everything.
- * @return array|string|null
- */
- protected function get_block_type_script( $key = null ) {
- return null;
- }
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewRating.php b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewRating.php
index acaece1baf9..dff229f17eb 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewRating.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewRating.php
@@ -2,11 +2,14 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes\Reviews;
use Automattic\WooCommerce\Blocks\BlockTypes\AbstractBlock;
+use Automattic\WooCommerce\Blocks\BlockTypes\EnableBlockJsonAssetsTrait;
/**
* ProductReviewRating class.
*/
class ProductReviewRating extends AbstractBlock {
+ use EnableBlockJsonAssetsTrait;
+
/**
* Block name.
*
@@ -14,15 +17,6 @@ class ProductReviewRating extends AbstractBlock {
*/
protected $block_name = 'product-review-rating';
- /**
- * Get the frontend style handle for this block type.
- *
- * @return string[]|null
- */
- protected function get_block_type_style() {
- return null;
- }
-
/**
* Render the block.
*
@@ -63,15 +57,4 @@ class ProductReviewRating extends AbstractBlock {
$html
);
}
-
- /**
- * Get the frontend script handle for this block type.
- *
- * @see $this->register_block_type()
- * @param string $key Data to get, or default to everything.
- * @return array|string|null
- */
- protected function get_block_type_script( $key = null ) {
- return null;
- }
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewTemplate.php b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewTemplate.php
index 7f397bb48df..8a8b9557aa4 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewTemplate.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewTemplate.php
@@ -2,6 +2,7 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes\Reviews;
use Automattic\WooCommerce\Blocks\BlockTypes\AbstractBlock;
+use Automattic\WooCommerce\Blocks\BlockTypes\EnableBlockJsonAssetsTrait;
use WP_Comment_Query;
use WP_Block;
use WP_Comment;
@@ -10,6 +11,8 @@ use WP_Comment;
* ProductReviewTemplate class.
*/
class ProductReviewTemplate extends AbstractBlock {
+ use EnableBlockJsonAssetsTrait;
+
/**
* Block name.
*
@@ -17,17 +20,6 @@ class ProductReviewTemplate extends AbstractBlock {
*/
protected $block_name = 'product-review-template';
- /**
- * Get the frontend script handle for this block type.
- *
- * @see $this->register_block_type()
- * @param string $key Data to get, or default to everything.
- * @return array|string|null
- */
- protected function get_block_type_script( $key = null ) {
- return null;
- }
-
/**
* Function that recursively renders a list of nested reviews.
*
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPagination.php b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPagination.php
index e105a668d16..4782def89c0 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPagination.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPagination.php
@@ -2,11 +2,14 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes\Reviews;
use Automattic\WooCommerce\Blocks\BlockTypes\AbstractBlock;
+use Automattic\WooCommerce\Blocks\BlockTypes\EnableBlockJsonAssetsTrait;
/**
* ProductReviewsPagination class.
*/
class ProductReviewsPagination extends AbstractBlock {
+ use EnableBlockJsonAssetsTrait;
+
/**
* Block name.
*
@@ -50,15 +53,4 @@ class ProductReviewsPagination extends AbstractBlock {
$p->get_updated_html()
);
}
-
- /**
- * Get the frontend script handle for this block type.
- *
- * @see $this->register_block_type()
- * @param string $key Data to get, or default to everything.
- * @return array|string|null
- */
- protected function get_block_type_script( $key = null ) {
- return null;
- }
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationNext.php b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationNext.php
index 0b97ab499ae..784add1e08b 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationNext.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationNext.php
@@ -2,11 +2,14 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes\Reviews;
use Automattic\WooCommerce\Blocks\BlockTypes\AbstractBlock;
+use Automattic\WooCommerce\Blocks\BlockTypes\EnableBlockJsonAssetsTrait;
/**
* ProductReviewsPaginationNext class.
*/
class ProductReviewsPaginationNext extends AbstractBlock {
+ use EnableBlockJsonAssetsTrait;
+
/**
* Block name.
*
@@ -73,24 +76,4 @@ class ProductReviewsPaginationNext extends AbstractBlock {
}
return null;
}
-
- /**
- * Get the frontend script handle for this block type.
- *
- * @see $this->register_block_type()
- * @param string $key Data to get, or default to everything.
- * @return array|string|null
- */
- protected function get_block_type_script( $key = null ) {
- return null;
- }
-
- /**
- * Get the frontend style handle for this block type.
- *
- * @return string|null
- */
- protected function get_block_type_style() {
- return null;
- }
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationNumbers.php b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationNumbers.php
index cff75a431e3..a3904a2d58b 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationNumbers.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationNumbers.php
@@ -2,11 +2,14 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes\Reviews;
use Automattic\WooCommerce\Blocks\BlockTypes\AbstractBlock;
+use Automattic\WooCommerce\Blocks\BlockTypes\EnableBlockJsonAssetsTrait;
/**
* ProductReviewsPaginationNumbers class.
*/
class ProductReviewsPaginationNumbers extends AbstractBlock {
+ use EnableBlockJsonAssetsTrait;
+
/**
* Block name.
*
@@ -55,24 +58,4 @@ class ProductReviewsPaginationNumbers extends AbstractBlock {
$content
);
}
-
- /**
- * Get the frontend script handle for this block type.
- *
- * @see $this->register_block_type()
- * @param string $key Data to get, or default to everything.
- * @return array|string|null
- */
- protected function get_block_type_script( $key = null ) {
- return null;
- }
-
- /**
- * Get the frontend style handle for this block type.
- *
- * @return string|null
- */
- protected function get_block_type_style() {
- return null;
- }
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationPrevious.php b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationPrevious.php
index b3d329559f1..aff27d116c2 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationPrevious.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsPaginationPrevious.php
@@ -2,11 +2,14 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes\Reviews;
use Automattic\WooCommerce\Blocks\BlockTypes\AbstractBlock;
+use Automattic\WooCommerce\Blocks\BlockTypes\EnableBlockJsonAssetsTrait;
/**
* ProductReviewsPaginationPrevious class.
*/
class ProductReviewsPaginationPrevious extends AbstractBlock {
+ use EnableBlockJsonAssetsTrait;
+
/**
* Block name.
*
@@ -69,24 +72,4 @@ class ProductReviewsPaginationPrevious extends AbstractBlock {
}
return null;
}
-
- /**
- * Get the frontend script handle for this block type.
- *
- * @see $this->register_block_type()
- * @param string $key Data to get, or default to everything.
- * @return array|string|null
- */
- protected function get_block_type_script( $key = null ) {
- return null;
- }
-
- /**
- * Get the frontend style handle for this block type.
- *
- * @return string|null
- */
- protected function get_block_type_style() {
- return null;
- }
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsTitle.php b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsTitle.php
index d0e6f4869ab..9207616cb47 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsTitle.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Reviews/ProductReviewsTitle.php
@@ -2,11 +2,14 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes\Reviews;
use Automattic\WooCommerce\Blocks\BlockTypes\AbstractBlock;
+use Automattic\WooCommerce\Blocks\BlockTypes\EnableBlockJsonAssetsTrait;
/**
* ProductReviewsTitle class.
*/
class ProductReviewsTitle extends AbstractBlock {
+ use EnableBlockJsonAssetsTrait;
+
/**
* Block name.
*
@@ -108,15 +111,4 @@ class ProductReviewsTitle extends AbstractBlock {
$reviews_title
);
}
-
- /**
- * Get the frontend script handle for this block type.
- *
- * @see $this->register_block_type()
- * @param string $key Data to get, or default to everything.
- * @return array|string|null
- */
- protected function get_block_type_script( $key = null ) {
- return null;
- }
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php b/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
index 8ac11940a55..239df61caf6 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypesLazyController.php
@@ -90,6 +90,7 @@ final class BlockTypesLazyController {
$this->get_product_display_element_blocks(),
$this->get_product_grid_blocks(),
$this->get_product_listing_blocks(),
+ $this->get_product_reviews_blocks(),
);
foreach ( $block_groups as $blocks_group ) {
foreach ( $blocks_group as $block_name => $block_class ) {
@@ -382,4 +383,27 @@ final class BlockTypesLazyController {
return $list;
}
+
+ /**
+ * Side effect free and stateless product review blocks.
+ *
+ * @return array<string,string>
+ */
+ private function get_product_reviews_blocks(): array {
+ // AllReviews, ReviewsByCategory, ReviewsByProduct: excluded — override get_block_type_script() with a shared frontend handle.
+ return array(
+ 'product-reviews' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviews::class,
+ 'product-review-rating' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewRating::class,
+ 'product-reviews-title' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewsTitle::class,
+ 'product-review-form' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewForm::class,
+ 'product-review-date' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewDate::class,
+ 'product-review-content' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewContent::class,
+ 'product-review-author-name' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewAuthorName::class,
+ 'product-reviews-pagination' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewsPagination::class,
+ 'product-reviews-pagination-next' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewsPaginationNext::class,
+ 'product-reviews-pagination-previous' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewsPaginationPrevious::class,
+ 'product-reviews-pagination-numbers' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewsPaginationNumbers::class,
+ 'product-review-template' => \Automattic\WooCommerce\Blocks\BlockTypes\Reviews\ProductReviewTemplate::class,
+ );
+ }
}