diff --git a/plugins/woocommerce-blocks/assets/js/blocks/product-collection/tracks-utils.ts b/plugins/woocommerce-blocks/assets/js/blocks/product-collection/tracks-utils.ts index 1cbaa2a2cd9..b5d1aa9a65f 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/product-collection/tracks-utils.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks/product-collection/tracks-utils.ts @@ -29,7 +29,7 @@ const templateSlugToTemplateMap: { 'page-checkout': Locations.CHECKOUT, }; -export const useTracksLocation = ( templateSlug: string ) => { +export const useTracksLocation = ( templateSlug: string | undefined ) => { const postType = useSelect( ( select ) => { // @ts-expect-error Type definitions are missing // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/wordpress__blocks/store/selectors.d.ts @@ -40,6 +40,10 @@ export const useTracksLocation = ( templateSlug: string ) => { return postType; } + if ( ! templateSlug ) { + return Locations.OTHER; + } + const template = templateSlugToTemplateMap[ templateSlug ]; if ( template ) { diff --git a/plugins/woocommerce/changelog/47504-47502-issue-error-when-editing-a-synced-pattern-with-product-collection-block b/plugins/woocommerce/changelog/47504-47502-issue-error-when-editing-a-synced-pattern-with-product-collection-block new file mode 100644 index 00000000000..37be3dae2c6 --- /dev/null +++ b/plugins/woocommerce/changelog/47504-47502-issue-error-when-editing-a-synced-pattern-with-product-collection-block @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix: handle undefined templateSlug in Product Collection tracking utils \ No newline at end of file