components: bug(MatDialog): When opening multiple dialogs in a short amount of time, some of them do not open

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

12.2.0

Description

When opening multiple dialogs in a short amount of time, some of them do not open

Reproduction

The bug can be noticed with the example below, when clicking the “Open Fast” button.

import { Component, TemplateRef, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';

@Component({
  selector: 'app-root',
  template: `
  <button (click)="openFast()">Open Fast</button>
  <button (click)="openSlow()">Open Slow</button>
  <ng-template let-data #template>
    {{data.message}}
    <button mat-dialog-close>close</button>
  </ng-template>
  `
})
export class AppComponent {
  @ViewChild("template") template?: TemplateRef<any>;
  constructor(private matDialog: MatDialog){}
  openFast(){
    this.open('1');
    setTimeout(() => this.open('2'), 1);
    setTimeout(() => this.open('3'), 50);
    setTimeout(() => this.open('4'), 100);
    setTimeout(() => this.open('5'), 150);
    setTimeout(() => this.open('6'), 200);
  }
  openSlow(){
    this.open('1');
    setTimeout(() => this.open('2'), 300);
    setTimeout(() => this.open('3'), 600);
    setTimeout(() => this.open('4'), 900);
    setTimeout(() => this.open('5'), 1200);
    setTimeout(() => this.open('6'), 1500);
  }

  private open(message: string){
    this.matDialog.open(this.template!, { 
      disableClose: true,
      data: { message } 
    });
  }
}

Expected Behavior

“Open fast” button should open 6 dialogs, just like the “Open slow” button.

Actual Behavior

The “Open fast” button opens only 2 dialogs. On most attempts it opens (1) and (5), but in some cases (1) and (6) are open.

Environment

  • Angular: 13.0.0
  • CDK/Material: 13.0.0
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 37 (16 by maintainers)

Commits related to this issue

Most upvoted comments

PR https://github.com/angular/components/pull/24121 has been tested and reviewed. It should land shortly and fix this.

This fix is included in 13.2.6 and 14.0.0-next.6.

FYI, StackBlitz now supports Angular 13. You can go ahead and make your repro if still needed.

Great news! Support for Angular 13 has finally rolled out. … For the next day or two (until 12 December 2021), there is a possibility of an initial slow down in starting up the dev server or running NGCC (or potentially even timeouts) as the packages repopulate into the cache as they are used, but it should come right after a refresh or two if you do have any issues. Anything else should be reported as a new issue.

Related StackBlitz issue comment: https://github.com/stackblitz/core/issues/1657#issuecomment-989779722

The fix will be in @angular/material, but we haven’t made a release with the new code yet. It should be out later today/tomorrow.

I reworked the fix for this on Friday to make it easier to merge and got it passing all the internal checks. It’ll be merged in on Monday and should be out in the next patch release.

Would like to know too when this PR is getting merged. We’re having a lot of problems with this issue at the moment 😢

@aikrez okay, I do have an update. There have been some undesirable side effects of this change in the presubmit tests. They are being investigated and potential solutions and workarounds are being evaluated.

Any updates?

@aikrez okay, I do have an update. There have been some undesirable side effects of this change in the presubmit tests. They are being investigated and potential solutions and workarounds are being evaluated.

@marsc can you please share your use case and a reproduction?

Sure: https://stackblitz.com/edit/angular13-mat-dialog?file=src/app/app.component.ts https://stackblitz.com/edit/angular12-mat-dialog?file=src/app/app.component.ts

As you will notice “Open Dialog Async” doesn’t work in version 13 but in version 12. Opening a dialog directly after another one closes is a very common use case in our app since we started using Angular years ago.

I’ve could make a stackblitz example, it can be forked.

Thank you for the example code. It would be great if you could provide a runnable StackBlitz to help us investigate this more efficiently.

@Splaktar I tried but couldn’t. I think StackBlitz has some issue with Angular 13: https://github.com/stackblitz/core/issues/1657