Skip to content

bug(MatDialog): Providing ViewContainerRef to MatDialog and removing the providing component leaves the backdrop indefinite with no way to close it #25163

@JonWallsten

Description

@JonWallsten

Description

There seems to be a side effect to this "issue": #25073
When providing viewContainerRef to the dialog the dialog/overlay cannot be closed/removed if the owning component is removed before the dialog is closed.
If I'm replacing the owning component instead of removing it, for example with a *ngFor the dialog is not closed. But after closing it the overlay is still there. (See second repro below)

I tried to close the dialog right before the owning component get removed, but the animation of the dialog causes it to be removed after the owning component and the issue persists.

Reproduction

https://stackblitz.com/edit/angular-14-provider-bug-close-dialog

Steps to reproduce:

  1. Open application
  2. Wait for dialog to close

https://stackblitz.com/edit/angular-14-mat-dialog-issue-2
Steps to reproduce:

  1. Open application
  2. Close dialog with close button

Expected Behavior

I expect the dialog to either still be open and that it can be closed later without being left with a empty dialog and a backdrop that can't be closed or that the backdrop is also removed if it's the last or only dialog.

Actual Behavior

In Angular 14.x the dialog is automatically closed when the owning component is removed, but I'm left with the overlay/backdrop and no way to close it.

In Angular 13.x, which I can't reproduce with a simple repro, I'm left with a super tiny dialog and the backdrop not being able to remove any of them.

Environment

Angular CLI: 14.0.1
Node: 16.14.0
Package Manager: npm 8.3.1
OS: win32 x64

Angular: 14.0.1
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, platform-browser, platform-browser-dynamic
... router

Package Version

@angular-devkit/architect 0.1400.1
@angular-devkit/build-optimizer 0.1302.1
@angular-devkit/core 14.0.1
@angular-devkit/schematics 14.0.1
@ngtools/webpack 14.0.1
@schematics/angular 14.0.1
ng-packagr 14.0.2
rxjs 7.5.5
typescript 4.7.3
webpack 5.73.0

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/overlay

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions