diff --git a/plugins/woocommerce-admin/client/wp-admin-scripts/product-tour/use-product-step-change.ts b/plugins/woocommerce-admin/client/wp-admin-scripts/product-tour/use-product-step-change.ts index c4de0d33f83..c2d4800fb29 100644 --- a/plugins/woocommerce-admin/client/wp-admin-scripts/product-tour/use-product-step-change.ts +++ b/plugins/woocommerce-admin/client/wp-admin-scripts/product-tour/use-product-step-change.ts @@ -22,14 +22,15 @@ const getInputValue = ( id: string ) => { }; const getTinyMceValue = ( id: string ) => { - const iframe = document.querySelector( id ) as HTMLIFrameElement; - return ( iframe?.contentWindow?.document.querySelector( + const iframe = document.querySelector< HTMLIFrameElement >( id ); + const tinymce = iframe?.contentWindow?.document.querySelector< HTMLElement >( '#tinymce' - ) as HTMLElement ).innerHTML; + ); + return tinymce?.innerHTML || ''; }; const getTextareaValue = ( id: string ) => { - return ( document.querySelector( id ) as HTMLTextAreaElement ).value; + return document.querySelector< HTMLTextAreaElement >( id )?.value || ''; }; const getProductDescriptionValue = ( isContentEditorTmceActive: boolean ) => { @@ -48,29 +49,28 @@ const getProductShortDescriptionValue = ( const getProductImageValue = () => { return ( - ( document.querySelector( - '#set-post-thumbnail img' - ) as HTMLImageElement )?.src || '' + document.querySelector< HTMLImageElement >( '#set-post-thumbnail img' ) + ?.src || '' ); }; // Parses categories into a string of true/false. Should be enough to catch any change. const getProductCategoriesValue = () => { return Array.from( - document.querySelectorAll( + document.querySelectorAll< HTMLInputElement >( '#product_cat-all #product_catchecklist input' ) ) - .map( ( x ) => ( x as HTMLInputElement ).checked ) + .map( ( x ) => x.checked ) .join( ',' ); }; // Parses all tags as string of tags separated by comma. const getProductTagsValue = () => { - return Array.from( document.querySelectorAll( '#product_tag li' ) ) - .map( - ( x ) => ( ( x as HTMLLIElement ).lastChild as Text ).textContent - ) + return Array.from( + document.querySelectorAll< HTMLLIElement >( '#product_tag li' ) + ) + .map( ( x ) => ( x.lastChild as Text ).textContent ) .join( ',' ); }; @@ -87,7 +87,6 @@ export const useProductStepChange = () => { const { isTmce: isExcerptEditorTmceActive } = useActiveEditorType( { editorWrapSelector: '#wp-excerpt-wrap', } ); - const [ initialValues, setInitialValues ] = useState< Partial< Record< ProductTourStepName, string > > >( {} ); diff --git a/plugins/woocommerce/changelog/fix-tour-kit-undefined-error b/plugins/woocommerce/changelog/fix-tour-kit-undefined-error new file mode 100644 index 00000000000..265b94bc045 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-tour-kit-undefined-error @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix product tour TypeError when reading innerHTML