-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix randomly failed icon layer render test #4079
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
const imageData = await loadImage(icon.url); | ||
|
||
const data = resizeImage(ctx, imageData, width, height); | ||
if (i === icons.length - 1) { |
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 marks loaded when the last image is loaded, not when all images are loaded.
- What happens when the icon set changes?
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.
- What happens when the icon set changes?
reset loaded
to false when there are more icons required to be loaded.
5d3d8e1
to
09d58d7
Compare
9137728
to
fbf3290
Compare
let loaded = 0; | ||
for (const icon of icons) { | ||
loadImage(icon.url).then(imageData => { | ||
loaded++; |
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.
More scenarios to consider:
loaded
will never be set if one of the images fails to load, e.g. url is not found. Is that intended?- This logic breaks if data is changed and a new batch of icons start loading. How do you handle that?
7cca557
to
6b6aa21
Compare
|
||
get loaded() { | ||
const requestedIcons = Object.keys(this._mapping).length; | ||
return this._autoPacking && requestedIcons && this._loadedIcons === requestedIcons; |
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'd recommend tracking the number of pending requests rather than the number of fulfilled requests:
this._pendingCount++;
loadSomething(...).finally(() => this._pendingCount--);
That way you don't need to know how to calculate the total number of requests here with _autoPacking
and _mapping
. The auto packing logic may change in the future and maintainers may forget to update this function, given that there are no tests. If requests are tracked where they start, it will be much more robust.
For #4039
Background
Change List
IconManager
: add aloaded
field indicating if the icons are fully loaded.