Fix: handle undefined templateSlug in Product Collection tracking utils (#47504)
* fix: handle undefined templateSlug in Product Collection tracking utils The modification introduces a check for templateSlug before attempting to access its properties or use it in further logic. This change addresses a bug that manifested when users tried to edit a synchronized Product Collection block, resulting in a JavaScript error because templateSlug could be undefined. * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Update types to better reflect reality --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
This commit is contained in:
parent
a120b99d7d
commit
1233fb4745
|
@ -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 ) {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Fix: handle undefined templateSlug in Product Collection tracking utils
|
Loading…
Reference in New Issue