Description
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
Sometimes when I call MatDialog.open, it returns the previous recently opened dialog instead of opening a new one. I reviewed the source code at https://github.com/angular/components/blob/master/src/material/dialog/dialog.ts and found the culprit:
// If there is a dialog that is currently animating open, return the MatDialogRef of that dialog
if (this._dialogAnimatingOpen) {
return this._lastDialogRef;
}
In my case, I use a "loading" component inside a dialog the opens in some situations (generally when a XHR is started) and closed when the response handling is finished. But that handling can involve opening a new dialog, and that is the buggy case I am getting on. In my specific case, there is not XHR, just a Promise that resolves very fast, so my app tries to open a new dialog while the opening animation for the "loading" is not yet finished.
I think that is not a expected behavior return the "opening" dialog ref in that situation. It can wait the animation finish ou simply interrupt it, but not return the previous one.
Reproduction
Steps to reproduce:
- Call MatDialog.open(SomeComponent);
- Call MatDialog.open(AnotherComponent); in the sequence
Expected Behavior
Returned MatDialogRef returned in the step 1 be different from the returned in the step 2 and, of course, MatDialogRef.componentInstance for the step 1 be different for the returned in the step 2.
Actual Behavior
MatDialogRef and MatDialogRef.componentInstance are the same for the step 1 and 2
Environment
My angular dependencies:
"@angular/animations": "~13.1.0",
"@angular/cdk": "^13.1.1",
"@angular/common": "~13.1.0",
"@angular/compiler": "~13.1.0",
"@angular/core": "~13.1.0",
"@angular/flex-layout": "^13.0.0-beta.37",
"@angular/forms": "~13.1.0",
"@angular/material": "^13.1.1",
"@angular/material-moment-adapter": "^13.2.0",
"@angular/platform-browser": "~13.1.0",
"@angular/platform-browser-dynamic": "~13.1.0",
"@angular/router": "~13.1.0",
- Browser(s): any (Chrome and FF tested)
- Operating System (e.g. Windows, macOS, Ubuntu): any (Linux Mint tested)