Skip to content

bug(MatSnackBar): Opening a second snackbar doesn't close the first one in Global Error handlerΒ #24386

@ErikNijland

Description

@ErikNijland

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.0.0

Description

Opening the SnackBar more than once from a global error handler (https://angular.io/api/core/ErrorHandler) does not close previously opened SnackBars.

Reproduction

Steps to reproduce:

  1. Go to https://stackblitz.com/edit/angular-ivy-1uxyez
  2. Two errors are triggered, and two snackbar elements are in the DOM. Running document.querySelectorAll('.mat-snack-bar-container') will return both of them.

If you trigger a single error instead. This can be done by uncommenting line #13 of app.component.ts. It does work.

Expected Behavior

  • The first snackbar is closed
  • The second snackbar is opened

Actual Behavior

  • Both snackbars are in the DOM
  • The text is not readable, probably because of the overlapping DOM elements.

Environment

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/snack-bar

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions