fix(icon): add better warning when loading icons #1297
Merged
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.
In ionic-team/ionic-framework#28445 we received feedback that accidentally referring to an icon by name without first registering it is confusing because devs get a cryptic "invalid URL" error. This PR attempts to improve that experience by providing a more helpful message and giving developers steps they can take to fix the issue.
main
One note: This warning will be logged every time the icons tries to load. We currently load the icon in
connectedCallback
andcomponentDidLoad
, so this warning can be logged twice on page load. In Angular, one more warning may be logged if the icon is in a router outlet (since the elements are moved intoion-router-outlet
on load which means they are first removed from the DOM, so connectedCallback fires twice.). We could add a cache that tracks if we already warned about each icon per element instance if reviewers prefer (though that will slightly increase the complexity of this fix).