-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(icon): prevent parsing the same icon set multiple times #9635
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
Conversation
This fixes an issue where requests for icons in a particular set made while that set is being fetched result in the set being parsed into an SVGElement multiple times. It occured because, while the same pending http request was used for each icon, each icon added their own `map` onto that request, will every `map` resulting in a (potentially expensive) parse. This change sets the cached icon earlier and checks it later.
652d501
to
c02f878
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, left a couple of nits.
// Normally we avoid spying on private methods like this, but the parsing is a private | ||
// implementation detail that should not be exposed to the public API. This test, though, | ||
// is important enough to warrant the brittle-ness that results. | ||
spyOn(iconRegistry, '_svgElementFromString' as any).and.callThrough(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than spying on a private method, you should be able to assert the same by reproviding the DOCUMENT
token and spying on createElement
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think long-term the "right" thing to do is to break SVG parsing into its own utility and then use a mock for MatIconRegistry
, which would make sense to do as part of #5188
// It is possible that the icon set was parsed and cached by an earlier request, so parsing | ||
// only needs to occur if the cache is yet unset. | ||
if (!config.svgElement) { | ||
config.svgElement = this._svgElementFromString(svgText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one could be shortened to config.svgElement = config.svgElement || this._svgElementFromString(svgText)
.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This fixes an issue where requests for icons in a particular set made while that set is being fetched result in the set being parsed into an SVGElement multiple times. It occured because, while the same pending http request was used for each icon, each icon added their own
map
onto that request, will everymap
resulting in a (potentially expensive) parse. This change sets the cached icon earlier and checks it later.