Skip to content

Commit ed19c14

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

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

core/src/components/modal/modal.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,9 @@ export class Modal implements ComponentInterface, OverlayInterface {
12001200

12011201
if (cachedParentWasRemoved || cachedParentDisconnected) {
12021202
this.dismiss(undefined, 'parent-removed');
1203+
// Release the reference to the cached original parent
1204+
// so we don't have a memory leak
1205+
this.cachedOriginalParent = undefined;
12031206
}
12041207
}
12051208
});
@@ -1213,10 +1216,8 @@ export class Modal implements ComponentInterface, OverlayInterface {
12131216
}
12141217

12151218
private cleanupParentRemovalObserver() {
1216-
if (this.parentRemovalObserver) {
1217-
this.parentRemovalObserver.disconnect();
1218-
this.parentRemovalObserver = undefined;
1219-
}
1219+
this.parentRemovalObserver?.disconnect();
1220+
this.parentRemovalObserver = undefined;
12201221
}
12211222

12221223
render() {

0 commit comments

Comments
 (0)