Skip to content

Commit

Permalink
Merge pull request #201 from rupato-deriv/Rupato/Check-removechildError
Browse files Browse the repository at this point in the history
Rupato/check remove child error
  • Loading branch information
farabi-deriv authored Dec 13, 2024
2 parents 1acbfea + a8609f3 commit 985ffd0
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/components/shared_ui/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/constants/load-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
};
12 changes: 10 additions & 2 deletions src/external/bot-skeleton/scratch/backward-compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
}
Expand Down Expand Up @@ -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);
}
}
});
}
Expand Down
7 changes: 5 additions & 2 deletions src/external/bot-skeleton/scratch/goog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
7 changes: 6 additions & 1 deletion src/pages/tutorials/tutorials-tab-mobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}, []);

Expand Down
5 changes: 5 additions & 0 deletions src/stores/google-drive-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 5 additions & 1 deletion src/utils/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

0 comments on commit 985ffd0

Please sign in to comment.