Skip to content

MatDialog: returning the last opened dialog instead of opening a new one #24525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task
tonyfarney opened this issue Mar 4, 2022 · 2 comments
Closed
1 task
Labels
needs triage This issue needs to be triaged by the team

Comments

@tonyfarney
Copy link

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;
}

Selection_666

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:

  1. Call MatDialog.open(SomeComponent);
  2. 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)
@tonyfarney tonyfarney added the needs triage This issue needs to be triaged by the team label Mar 4, 2022
@crisbeto
Copy link
Member

crisbeto commented Mar 5, 2022

Duplicate of #24037.

@crisbeto crisbeto closed this as completed Mar 5, 2022
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue needs to be triaged by the team
Projects
None yet
Development

No branches or pull requests

2 participants