@angular/cdk 14.1.0 → 14.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -570,6 +570,24 @@ class OverlayRef {
570
570
  this._locationChanges = this._location.subscribe(() => this.dispose());
571
571
  }
572
572
  this._outsideClickDispatcher.add(this);
573
+ // TODO(crisbeto): the null check is here, because the portal outlet returns `any`.
574
+ // We should be guaranteed for the result to be `ComponentRef | EmbeddedViewRef`, but
575
+ // `instanceof EmbeddedViewRef` doesn't appear to work at the moment.
576
+ if (typeof (attachResult === null || attachResult === void 0 ? void 0 : attachResult.onDestroy) === 'function') {
577
+ // In most cases we control the portal and we know when it is being detached so that
578
+ // we can finish the disposal process. The exception is if the user passes in a custom
579
+ // `ViewContainerRef` that isn't destroyed through the overlay API. Note that we use
580
+ // `detach` here instead of `dispose`, because we don't know if the user intends to
581
+ // reattach the overlay at a later point. It also has the advantage of waiting for animations.
582
+ attachResult.onDestroy(() => {
583
+ if (this.hasAttached()) {
584
+ // We have to delay the `detach` call, because detaching immediately prevents
585
+ // other destroy hooks from running. This is likely a framework bug similar to
586
+ // https://github.com/angular/angular/issues/46119
587
+ this._ngZone.runOutsideAngular(() => Promise.resolve().then(() => this.detach()));
588
+ }
589
+ });
590
+ }
573
591
  return attachResult;
574
592
  }
575
593
  /**