Commit 57dc8789b74 for woocommerce
commit 57dc8789b74db3417682febba5d8f447d3d703f3
Author: Raluca Stan <ralucastn@gmail.com>
Date: Wed Apr 22 17:24:43 2026 +0200
Store get_block_type_style() result in AbstractBlock::register_block_type (#64256)
* Cache get_block_type_style() result in AbstractBlock::register_block_type
register_block_type() called get_block_type_style() and
get_block_type_editor_style() twice each (once in the if, once for the
assignment). get_block_type_style() re-registers the block style handle
on every call, so legacy-path blocks paid that cost twice. Cache each
result in a local variable so the methods are called once each.
* Add changefile(s) from automation for the following project(s): woocommerce
* Remove duplicate auto-generated changelog entry
Keep the manually added plugins/woocommerce/changelog/fix-abstract-block-duplicate-style-call entry (Type: performance) and drop the auto-generated one added by the changelog automation bot.
* Add changefile(s) from automation for the following project(s): woocommerce
* Remove duplicate auto-generated changelog entry
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/fix-abstract-block-duplicate-style-call b/plugins/woocommerce/changelog/fix-abstract-block-duplicate-style-call
new file mode 100644
index 00000000000..1a23a076443
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-abstract-block-duplicate-style-call
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Avoid duplicate `get_block_type_style()` call in `AbstractBlock::register_block_type()` by caching the result in a local variable.
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php b/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php
index 85242acfc03..ba72dfff60c 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php
@@ -226,12 +226,14 @@ abstract class AbstractBlock {
];
// Conditionally override these, otherwise rely on block.json metadata.
- if ( $this->get_block_type_style() ) {
- $block_settings['style'] = $this->get_block_type_style();
+ $block_type_style = $this->get_block_type_style();
+ if ( $block_type_style ) {
+ $block_settings['style'] = $block_type_style;
}
- if ( $this->get_block_type_editor_style() ) {
- $block_settings['editor_style'] = $this->get_block_type_editor_style();
+ $block_type_editor_style = $this->get_block_type_editor_style();
+ if ( $block_type_editor_style ) {
+ $block_settings['editor_style'] = $block_type_editor_style;
}
if ( isset( $this->api_version ) ) {