Skip to content

Commit

Permalink
fix(ComponentLoader): loader leaks memory in multiple places (#6625)
Browse files Browse the repository at this point in the history
* fix(ComponentLoader): loader leaks memory in multiple places

* Fix(component-loader): fixing lint

---------

Co-authored-by: Alexey Umanskiy <[email protected]>
  • Loading branch information
JoschuaSchneider and lexasq authored Jul 5, 2024
1 parent e6e374d commit 876f20d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/component-loader/component-loader.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export class ComponentLoader<T extends object> {
);
}
this._contentRef?.viewRef?.destroy();
this._componentRef?.destroy();

this._contentRef = void 0;
this._componentRef = void 0;
Expand Down Expand Up @@ -312,12 +313,16 @@ export class ComponentLoader<T extends object> {
if (!this._componentRef || !this._componentRef.location) {
return;
}

let unsubscribeOutsideClick = Function.prototype;
let unsubscribeEscClick = Function.prototype;

// why: should run after first event bubble
if (this._listenOpts.outsideClick) {
const target = this._componentRef.location.nativeElement;
setTimeout(() => {
if (this._renderer && this._elementRef) {
this._globalListener = registerOutsideClick(this._renderer, {
unsubscribeOutsideClick = registerOutsideClick(this._renderer, {
targets: [target, this._elementRef.nativeElement],
outsideClick: this._listenOpts.outsideClick,
hide: () => this._listenOpts.hide && this._listenOpts.hide()
Expand All @@ -327,12 +332,17 @@ export class ComponentLoader<T extends object> {
}
if (this._listenOpts.outsideEsc && this._renderer && this._elementRef) {
const target = this._componentRef.location.nativeElement;
this._globalListener = registerEscClick(this._renderer, {
unsubscribeEscClick = registerEscClick(this._renderer, {
targets: [target, this._elementRef.nativeElement],
outsideEsc: this._listenOpts.outsideEsc,
hide: () => this._listenOpts.hide && this._listenOpts.hide()
});
}

this._globalListener = () => {
unsubscribeOutsideClick();
unsubscribeEscClick();
};
}

getInnerComponent(): ComponentRef<T> | undefined {
Expand Down

0 comments on commit 876f20d

Please sign in to comment.