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-icon): Race-condition when using svgIcon #19259

Closed
OhadC opened this issue May 5, 2020 · 2 comments · Fixed by #19303
Closed

bug(mat-icon): Race-condition when using svgIcon #19259

OhadC opened this issue May 5, 2020 · 2 comments · Fixed by #19303
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@OhadC
Copy link

OhadC commented May 5, 2020

Reproduction

https://stackblitz.com/edit/components-issue-o5txc8?file=src%2Fapp%2Fexample-component.ts

Steps to reproduce:

  1. press the button

Expected Behavior

mat-icon should display "thumbs-up" icon

Actual Behavior

mat-icon is displaying "thumbs-down" icon

Environment

(doesn't really maters..)

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

Explanation

There is a race-condition when svgIcon is getting a icon that is not already fetched.

Relevant code: https://github.com/angular/components/blob/master/src/material/icon/icon.ts#L229

Possible solutions

Option 1: Save this.svgIcon to fetchedSvgIcon before executing getNamedSvgIcon, and check if this.svgIcon === fetchedSvgIcon after getting the result
Option 2: Make this.svgIcon$ (observable of this.svgIcon) and use switchMap

@OhadC OhadC added the needs triage This issue needs to be triaged by the team label May 5, 2020
@crisbeto crisbeto self-assigned this May 10, 2020
@crisbeto crisbeto added 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 May 10, 2020
crisbeto added a commit to crisbeto/material2 that referenced this issue May 10, 2020
Currently we can stack up in-flight quests if the icon name changes quickly. These changes will cancel any in-flight requests if that happens or if the icon is destroyed.

Fixes angular#19259.
@OhadC
Copy link
Author

OhadC commented May 11, 2020

@crisbeto Looks great! Thanks!

@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 Jun 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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