Skip to content

Commit def96ab

Browse files
committed
fix(modal): prevent browser hang when using ModalController in Angular
1 parent 1c89cf0 commit def96ab

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

core/src/components/modal/modal.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,20 @@ export class Modal implements ComponentInterface, OverlayInterface {
11831183
return;
11841184
}
11851185

1186+
/**
1187+
* Don't observe for controller-based modals or when the parent is the
1188+
* app root (document.body or ion-app). These parents won't be removed,
1189+
* and observing document.body with subtree: true causes performance
1190+
* issues with frameworks like Angular during change detection.
1191+
*/
1192+
if (
1193+
this.hasController ||
1194+
this.cachedOriginalParent === document.body ||
1195+
this.cachedOriginalParent.tagName === 'ION-APP'
1196+
) {
1197+
return;
1198+
}
1199+
11861200
this.parentRemovalObserver = new MutationObserver((mutations) => {
11871201
mutations.forEach((mutation) => {
11881202
if (mutation.type === 'childList' && mutation.removedNodes.length > 0) {

0 commit comments

Comments
 (0)