From 381c87da80a26049ab6d38bf71aa85c64d0d17c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Wed, 14 Aug 2024 10:43:32 +0200 Subject: [PATCH] Fix translations - Avoid registering blocks in the wrong context (#50615) * Avoid registering block in the wrong context * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Add changefile(s) from automation for the following project(s): woocommerce-blocks --------- Co-authored-by: github-actions --- .../utils/register-block-single-product-template.ts | 11 ++++++++--- .../changelog/50615-fix-product-rating-translations | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 plugins/woocommerce/changelog/50615-fix-product-rating-translations diff --git a/plugins/woocommerce-blocks/assets/js/atomic/utils/register-block-single-product-template.ts b/plugins/woocommerce-blocks/assets/js/atomic/utils/register-block-single-product-template.ts index 58f842c362d..88236a7ed4b 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/utils/register-block-single-product-template.ts +++ b/plugins/woocommerce-blocks/assets/js/atomic/utils/register-block-single-product-template.ts @@ -44,13 +44,14 @@ export const registerBlockSingleProductTemplate = ( { blockMetadata = blockName; } + const editSiteStore = select( 'core/edit-site' ); + subscribe( () => { const previousTemplateId = currentTemplateId; - const store = select( 'core/edit-site' ); // With GB 16.3.0 the return type can be a number: https://github.com/WordPress/gutenberg/issues/53230 currentTemplateId = parseTemplateId( - store?.getEditedPostId< string | number | undefined >() + editSiteStore?.getEditedPostId< string | number | undefined >() ); const hasChangedTemplate = previousTemplateId !== currentTemplateId; const hasTemplateId = Boolean( currentTemplateId ); @@ -108,7 +109,11 @@ export const registerBlockSingleProductTemplate = ( { // This subscribe callback could be invoked with the core/blocks store // which would cause infinite registration loops because of the `registerBlockType` call. // This local cache helps prevent that. - if ( ! isBlockRegistered && isAvailableOnPostEditor ) { + if ( + ! isBlockRegistered && + isAvailableOnPostEditor && + ! editSiteStore + ) { if ( isVariationBlock ) { blocksRegistered.add( variationName ); registerBlockVariation( diff --git a/plugins/woocommerce/changelog/50615-fix-product-rating-translations b/plugins/woocommerce/changelog/50615-fix-product-rating-translations new file mode 100644 index 00000000000..c2597b4ed26 --- /dev/null +++ b/plugins/woocommerce/changelog/50615-fix-product-rating-translations @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +Fix translation - Avoid registering blocks in the wrong context. \ No newline at end of file