Skip to content
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

bug(mat-menu): Clicking a [matMenuTriggerFor] inside its own mat-menu crashes JS #19941

Closed
tomasdev opened this issue Jul 10, 2020 · 1 comment · Fixed by #19943
Closed

bug(mat-menu): Clicking a [matMenuTriggerFor] inside its own mat-menu crashes JS #19941

tomasdev opened this issue Jul 10, 2020 · 1 comment · Fixed by #19943
Assignees
Labels
area: material/menu P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@tomasdev
Copy link

Note: This might be an invalid use case, as it's wrongly using a directive. Still, it wouldn't hurt to have a safety check to prevent this.

Reproduction

Use StackBlitz to reproduce your issue: https://stackblitz.com/edit/angular-japg2m?file=src%2Fapp%2Fmenu-overview-example.html

Steps to reproduce:

<button [matMenuTriggerFor]="menu">Open</button>
<mat-menu #menu="matMenu">
  <button [matMenuTriggerFor]="menu">Close</button>
</mat-menu>
  1. Click "Open"
  2. Click Close
  3. Open console and observe fatal error:
ERROR Error: Maximum call stack size exceeded
ERROR Error: Failed to execute 'insertBefore' on 'Node': The new child element contains the parent.

Expected Behavior

Page (main JS thread) shouldn't crash when having a closing button inside the menu.

Actual Behavior

Page (main JS thread) crashes.

Environment

  • Angular: 10.x
  • CDK/Material: 10.x
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS
@tomasdev tomasdev added the needs triage This issue needs to be triaged by the team label Jul 10, 2020
@tomasdev tomasdev changed the title bug(mat-menu): Having a [matMenuTriggerFor] inside its own mat-menu crashes JS bug(mat-menu): Clicking a [matMenuTriggerFor] inside its own mat-menu crashes JS Jul 10, 2020
@crisbeto crisbeto self-assigned this Jul 10, 2020
@crisbeto crisbeto added area: material/menu has pr P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels Jul 10, 2020
crisbeto added a commit to crisbeto/material2 that referenced this issue Jul 10, 2020
If the consumer puts a trigger inside a menu and passes the menu back to the trigger, we'll go into an infinite loop and throw a cryptic error message. These changes detect such a case and throw a better error. Example of a case that will be flagged:

```
<mat-menu #menu="matMenu">
  <button [matMenuTriggerFor]="menu"></button>
</mat-menu>
```

Fixes angular#19941.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jul 12, 2020
If the consumer puts a trigger inside a menu and passes the menu back to the trigger, we'll go into an infinite loop and throw a cryptic error message. These changes detect such a case and throw a better error. Example of a case that will be flagged:

```
<mat-menu #menu="matMenu">
  <button [matMenuTriggerFor]="menu"></button>
</mat-menu>
```

Fixes angular#19941.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jul 12, 2020
If the consumer puts a trigger inside a menu and passes the menu back to the trigger, we'll go into an infinite loop and throw a cryptic error message. These changes detect such a case and throw a better error. Example of a case that will be flagged:

```
<mat-menu #menu="matMenu">
  <button [matMenuTriggerFor]="menu"></button>
</mat-menu>
```

Fixes angular#19941.
wagnermaciel pushed a commit that referenced this issue Jul 24, 2020
If the consumer puts a trigger inside a menu and passes the menu back to the trigger, we'll go into an infinite loop and throw a cryptic error message. These changes detect such a case and throw a better error. Example of a case that will be flagged:

```
<mat-menu #menu="matMenu">
  <button [matMenuTriggerFor]="menu"></button>
</mat-menu>
```

Fixes #19941.
wagnermaciel pushed a commit that referenced this issue Jul 24, 2020
If the consumer puts a trigger inside a menu and passes the menu back to the trigger, we'll go into an infinite loop and throw a cryptic error message. These changes detect such a case and throw a better error. Example of a case that will be flagged:

```
<mat-menu #menu="matMenu">
  <button [matMenuTriggerFor]="menu"></button>
</mat-menu>
```

Fixes #19941.

(cherry picked from commit 1b7ba0b)
@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 Aug 24, 2020
wagnermaciel pushed a commit to wagnermaciel/components that referenced this issue Jan 14, 2021
If the consumer puts a trigger inside a menu and passes the menu back to the trigger, we'll go into an infinite loop and throw a cryptic error message. These changes detect such a case and throw a better error. Example of a case that will be flagged:

```
<mat-menu #menu="matMenu">
  <button [matMenuTriggerFor]="menu"></button>
</mat-menu>
```

Fixes angular#19941.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/menu P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants