fix: race condition in decorateIcons #256
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #217
When the same icon is requested several times (like a logo in the header and the footer) there is a race condition in the decorateIcons function that will cause only the first request to get the actual svg while the other requests will get empty icon tags.
This PR fixes this by replacing the current logic that is based on just putting a boolean in the cache while the icon gets loaded with a promise that is put into the cache (similar to what happens in fetchPlaceholders). Subsequently, that promise is returned from the cache for all requesters - hence, they all get the result.
We used this patch in our project and haven't had any issues since then.
Test URLs: