Skip to content

Commit c95edd9

Browse files
committed
fix(modal): release cached parent when it's removed from DOM to prevent a leak
1 parent 7376bb3 commit c95edd9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

core/src/components/modal/modal.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
404404
this.triggerController.removeClickListener();
405405
this.cleanupViewTransitionListener();
406406
this.cleanupParentRemovalObserver();
407+
this.cachedOriginalParent = undefined;
407408
}
408409

409410
componentWillLoad() {
@@ -1200,6 +1201,9 @@ export class Modal implements ComponentInterface, OverlayInterface {
12001201

12011202
if (cachedParentWasRemoved || cachedParentDisconnected) {
12021203
this.dismiss(undefined, 'parent-removed');
1204+
// Release the reference to the cached original parent
1205+
// so we don't have a memory leak
1206+
this.cachedOriginalParent = undefined;
12031207
}
12041208
}
12051209
});
@@ -1213,10 +1217,8 @@ export class Modal implements ComponentInterface, OverlayInterface {
12131217
}
12141218

12151219
private cleanupParentRemovalObserver() {
1216-
if (this.parentRemovalObserver) {
1217-
this.parentRemovalObserver.disconnect();
1218-
this.parentRemovalObserver = undefined;
1219-
}
1220+
this.parentRemovalObserver?.disconnect();
1221+
this.parentRemovalObserver = undefined;
12201222
}
12211223

12221224
render() {

0 commit comments

Comments
 (0)