diff --git a/assets/js/atomic/utils/register-block-single-product-template.ts b/assets/js/atomic/utils/register-block-single-product-template.ts index d1e853acbe9..5d7e1ab020f 100644 --- a/assets/js/atomic/utils/register-block-single-product-template.ts +++ b/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/assets/js/blocks/classic-template/index.tsx b/assets/js/blocks/classic-template/index.tsx index 9d69c00c2b3..7f89427e0a0 100644 --- a/assets/js/blocks/classic-template/index.tsx +++ b/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 ) { diff --git a/composer.json b/composer.json index 9dd27664ebb..6bd56abb82f 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "WooCommerce blocks for the Gutenberg editor.", "homepage": "https://woocommerce.com/", "type": "wordpress-plugin", - "version": "10.6.3", + "version": "10.6.4", "keywords": [ "gutenberg", "woocommerce", diff --git a/docs/internal-developers/testing/releases/1064.md b/docs/internal-developers/testing/releases/1064.md new file mode 100644 index 00000000000..eb126a39c54 --- /dev/null +++ b/docs/internal-developers/testing/releases/1064.md @@ -0,0 +1,23 @@ +# Testing notes and ZIP for release 10.6.4 + +Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/12262069/woocommerce-gutenberg-products-block.zip) + +## WooCommerce Core + +### Classic Template block registration: add defensive type handling [#10475](https://github.com/woocommerce/woocommerce-blocks/pull/10475) + +1. Ensure that you have installed Gutenberg 16.3.0. +2. Open the Site Editor. +3. Click on the navigation. +4. Click on the pencil (to edit button). +5. Ensure that the Site Editor doesn't crash + +| Before | After | +|--------|--------| +|