Skip to content

Commit 985ffd0

Browse files
authored
Merge pull request #201 from rupato-deriv/Rupato/Check-removechildError
Rupato/check remove child error
2 parents 1acbfea + a8609f3 commit 985ffd0

File tree

7 files changed

+41
-9
lines changed

7 files changed

+41
-9
lines changed

src/components/shared_ui/modal/modal.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ const ModalElement = ({
117117
onMount?.();
118118

119119
return () => {
120-
local_modal_root_ref?.current?.removeChild?.(local_el_ref.current);
120+
const parent_element = local_modal_root_ref?.current;
121+
const child_element = local_el_ref?.current;
122+
123+
if (parent_element && child_element && parent_element?.contains(child_element)) {
124+
parent_element?.removeChild(child_element);
125+
}
121126
onUnmount?.();
122127
};
123128
// eslint-disable-next-line react-hooks/exhaustive-deps

src/constants/load-modal.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export const tabs_title = Object.freeze({
55
});
66

77
export const clearInjectionDiv = (el_ref?: HTMLElement) => {
8-
if (el_ref && el_ref.getElementsByClassName('injectionDiv').length > 1) {
9-
el_ref.removeChild(el_ref.getElementsByClassName('injectionDiv')[0]);
8+
const parent_element = el_ref;
9+
const child_element = el_ref?.getElementsByClassName('injectionDiv');
10+
if (parent_element && child_element && child_element?.length > 1) {
11+
parent_element?.removeChild(child_element[0]);
1012
}
1113
};

src/external/bot-skeleton/scratch/backward-compatibility.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ export default class BlockConversion {
4848

4949
value_input.connection.connect(value_block.outputConnection);
5050
});
51+
const parent_element = child_node.parentNode;
52+
const child_element = child_node;
5153

52-
child_node.parentNode.removeChild(child_node);
54+
if (parent_element && child_element && parent_element?.contains(child_element)) {
55+
parent_element?.removeChild(child_element);
56+
}
5357
});
5458
}
5559
}
@@ -135,8 +139,12 @@ export default class BlockConversion {
135139

136140
value_input.connection.connect(converted_block.outputConnection);
137141
});
142+
const parent_element = el_value?.parentNode;
143+
const child_element = el_value;
138144

139-
el_value.parentNode.removeChild(el_value);
145+
if (parent_element && child_element && parent_element?.contains(child_element)) {
146+
el_value?.parentNode?.removeChild(el_value);
147+
}
140148
}
141149
});
142150
}

src/external/bot-skeleton/scratch/goog.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ goog.isNumber = function (e) {
3131
goog.dom = {};
3232

3333
goog.dom.removeNode = function (node) {
34-
if (node && node.parentNode) {
35-
node.parentNode.removeChild(node);
34+
const parent_element = node.parentNode;
35+
const child_element = node;
36+
37+
if (child_element && parent_element && parent_element?.contains(child_element)) {
38+
parent_element?.removeChild(child_element);
3639
}
3740
};
3841

src/pages/tutorials/tutorials-tab-mobile.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ const TutorialsTabMobile = observer(({ tutorial_tabs, prev_active_tutorials }: T
6868
const selectElement = document.getElementById('dt_components_select-native_select-tag') as HTMLSelectElement;
6969

7070
if (selectElement) {
71-
selectElement.removeChild(selectElement?.options[3]);
71+
const parent_element = selectElement;
72+
const child_element = selectElement?.options?.[3];
73+
74+
if (parent_element && child_element && parent_element?.contains(child_element)) {
75+
parent_element?.removeChild(child_element);
76+
}
7277
}
7378
}, []);
7479

src/stores/google-drive-store.ts

+5
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ export default class GoogleDriveStore {
188188
if ((err as TErrorWithStatus)?.status === 401) {
189189
await this.signOut();
190190
const picker = document.getElementsByClassName('picker-dialog-content')[0] as HTMLElement;
191+
const parent_element = picker?.parentNode;
192+
const child_element = picker;
193+
if (child_element && parent_element && parent_element?.contains(child_element)) {
194+
parent_element?.removeChild(child_element);
195+
}
191196
picker?.parentNode?.removeChild(picker);
192197
const pickerBackground = document.getElementsByClassName(
193198
'picker-dialog-bg'

src/utils/download.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,9 @@ export const downloadFile = (file_name: string, content: string) => {
9292
link.setAttribute('download', `${file_name} ${getCurrentDateTimeLocale()}.csv`);
9393
document.body.appendChild(link);
9494
link.click();
95-
link.parentNode?.removeChild(link);
95+
const parent_element = link.parentNode;
96+
const child_element = link;
97+
if (parent_element && child_element && parent_element?.contains(child_element)) {
98+
parent_element?.removeChild(child_element);
99+
}
96100
};

0 commit comments

Comments
 (0)