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 <github-actions@github.com>
This commit is contained in:
Alba Rincón 2024-08-14 10:43:32 +02:00 committed by GitHub
parent d04666e35c
commit 381c87da80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -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(

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Fix translation - Avoid registering blocks in the wrong context.