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 d1e853acbe9..5d7e1ab020f 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 @@ -1,6 +1,7 @@ /** * External dependencies */ +import { isNumber } from '@woocommerce/types'; import { BlockAttributes, BlockConfiguration, @@ -16,8 +17,10 @@ import { subscribe, select } from '@wordpress/data'; // Creating a local cache to prevent multiple registration tries. const blocksRegistered = new Set(); -function parseTemplateId( templateId: string | undefined ) { - return templateId?.split( '//' )[ 1 ]; +function parseTemplateId( templateId: string | number | undefined ) { + // With GB 16.3.0 the return type can be a number: https://github.com/WordPress/gutenberg/issues/53230 + const parsedTemplateId = isNumber( templateId ) ? undefined : templateId; + return parsedTemplateId?.split( '//' )[ 1 ]; } export const registerBlockSingleProductTemplate = ( { @@ -40,7 +43,11 @@ export const registerBlockSingleProductTemplate = ( { subscribe( () => { const previousTemplateId = currentTemplateId; const store = select( 'core/edit-site' ); - currentTemplateId = parseTemplateId( store?.getEditedPostId() ); + + // With GB 16.3.0 the return type can be a number: https://github.com/WordPress/gutenberg/issues/53230 + currentTemplateId = parseTemplateId( + store?.getEditedPostId() as string | number | undefined + ); const hasChangedTemplate = previousTemplateId !== currentTemplateId; const hasTemplateId = Boolean( currentTemplateId ); diff --git a/plugins/woocommerce-blocks/assets/js/blocks/classic-template/index.tsx b/plugins/woocommerce-blocks/assets/js/blocks/classic-template/index.tsx index 9d69c00c2b3..7f89427e0a0 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/classic-template/index.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/classic-template/index.tsx @@ -31,6 +31,7 @@ import { store as noticesStore } from '@wordpress/notices'; import { useEntityRecord } from '@wordpress/core-data'; import { debounce } from '@woocommerce/base-utils'; import { woo } from '@woocommerce/icons'; +import { isNumber } from '@woocommerce/types'; /** * Internal dependencies @@ -417,7 +418,14 @@ let currentTemplateId: string | undefined; subscribe( () => { const previousTemplateId = currentTemplateId; const store = select( 'core/edit-site' ); - currentTemplateId = store?.getEditedPostId() as string | undefined; + // With GB 16.3.0 the return type can be a number: https://github.com/WordPress/gutenberg/issues/53230 + const editedPostId = store?.getEditedPostId() as + | string + | number + | undefined; + + currentTemplateId = isNumber( editedPostId ) ? undefined : editedPostId; + const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ]; if ( parsedTemplate === null || parsedTemplate === undefined ) {