diff --git a/src/components/shared_ui/modal/modal.tsx b/src/components/shared_ui/modal/modal.tsx index bcd8e902..691b01d5 100644 --- a/src/components/shared_ui/modal/modal.tsx +++ b/src/components/shared_ui/modal/modal.tsx @@ -117,7 +117,12 @@ const ModalElement = ({ onMount?.(); return () => { - local_modal_root_ref?.current?.removeChild?.(local_el_ref.current); + const parent_element = local_modal_root_ref?.current; + const child_element = local_el_ref?.current; + + if (parent_element && child_element && parent_element?.contains(child_element)) { + parent_element?.removeChild(child_element); + } onUnmount?.(); }; // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/src/constants/load-modal.ts b/src/constants/load-modal.ts index f0ca5ca3..ebdfd31d 100644 --- a/src/constants/load-modal.ts +++ b/src/constants/load-modal.ts @@ -5,7 +5,9 @@ export const tabs_title = Object.freeze({ }); export const clearInjectionDiv = (el_ref?: HTMLElement) => { - if (el_ref && el_ref.getElementsByClassName('injectionDiv').length > 1) { - el_ref.removeChild(el_ref.getElementsByClassName('injectionDiv')[0]); + const parent_element = el_ref; + const child_element = el_ref?.getElementsByClassName('injectionDiv'); + if (parent_element && child_element && child_element?.length > 1) { + parent_element?.removeChild(child_element[0]); } }; diff --git a/src/external/bot-skeleton/scratch/backward-compatibility.js b/src/external/bot-skeleton/scratch/backward-compatibility.js index a5a48219..985ce18d 100644 --- a/src/external/bot-skeleton/scratch/backward-compatibility.js +++ b/src/external/bot-skeleton/scratch/backward-compatibility.js @@ -48,8 +48,12 @@ export default class BlockConversion { value_input.connection.connect(value_block.outputConnection); }); + const parent_element = child_node.parentNode; + const child_element = child_node; - child_node.parentNode.removeChild(child_node); + if (parent_element && child_element && parent_element?.contains(child_element)) { + parent_element?.removeChild(child_element); + } }); } } @@ -135,8 +139,12 @@ export default class BlockConversion { value_input.connection.connect(converted_block.outputConnection); }); + const parent_element = el_value?.parentNode; + const child_element = el_value; - el_value.parentNode.removeChild(el_value); + if (parent_element && child_element && parent_element?.contains(child_element)) { + el_value?.parentNode?.removeChild(el_value); + } } }); } diff --git a/src/external/bot-skeleton/scratch/goog.js b/src/external/bot-skeleton/scratch/goog.js index 0a45cfe8..dabb64a9 100644 --- a/src/external/bot-skeleton/scratch/goog.js +++ b/src/external/bot-skeleton/scratch/goog.js @@ -31,8 +31,11 @@ goog.isNumber = function (e) { goog.dom = {}; goog.dom.removeNode = function (node) { - if (node && node.parentNode) { - node.parentNode.removeChild(node); + const parent_element = node.parentNode; + const child_element = node; + + if (child_element && parent_element && parent_element?.contains(child_element)) { + parent_element?.removeChild(child_element); } }; diff --git a/src/pages/tutorials/tutorials-tab-mobile.tsx b/src/pages/tutorials/tutorials-tab-mobile.tsx index 0ecc77c6..7dd23a08 100644 --- a/src/pages/tutorials/tutorials-tab-mobile.tsx +++ b/src/pages/tutorials/tutorials-tab-mobile.tsx @@ -68,7 +68,12 @@ const TutorialsTabMobile = observer(({ tutorial_tabs, prev_active_tutorials }: T const selectElement = document.getElementById('dt_components_select-native_select-tag') as HTMLSelectElement; if (selectElement) { - selectElement.removeChild(selectElement?.options[3]); + const parent_element = selectElement; + const child_element = selectElement?.options?.[3]; + + if (parent_element && child_element && parent_element?.contains(child_element)) { + parent_element?.removeChild(child_element); + } } }, []); diff --git a/src/stores/google-drive-store.ts b/src/stores/google-drive-store.ts index f5bf65bc..d14a7320 100644 --- a/src/stores/google-drive-store.ts +++ b/src/stores/google-drive-store.ts @@ -188,6 +188,11 @@ export default class GoogleDriveStore { if ((err as TErrorWithStatus)?.status === 401) { await this.signOut(); const picker = document.getElementsByClassName('picker-dialog-content')[0] as HTMLElement; + const parent_element = picker?.parentNode; + const child_element = picker; + if (child_element && parent_element && parent_element?.contains(child_element)) { + parent_element?.removeChild(child_element); + } picker?.parentNode?.removeChild(picker); const pickerBackground = document.getElementsByClassName( 'picker-dialog-bg' diff --git a/src/utils/download.ts b/src/utils/download.ts index 886a6a1b..a86e1192 100644 --- a/src/utils/download.ts +++ b/src/utils/download.ts @@ -92,5 +92,9 @@ export const downloadFile = (file_name: string, content: string) => { link.setAttribute('download', `${file_name} ${getCurrentDateTimeLocale()}.csv`); document.body.appendChild(link); link.click(); - link.parentNode?.removeChild(link); + const parent_element = link.parentNode; + const child_element = link; + if (parent_element && child_element && parent_element?.contains(child_element)) { + parent_element?.removeChild(child_element); + } };