Skip to content

Commit

Permalink
fix(icon): add better warning when loading icons
Browse files Browse the repository at this point in the history
  • Loading branch information
liamdebeasi committed Nov 1, 2023
1 parent 625d54f commit 96aa17e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/icon/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ const getNamedUrl = (iconName: string) => {
if (url) {
return url;
}
return getAssetPath(`svg/${iconName}.svg`);
try {
return getAssetPath(`svg/${iconName}.svg`);
} catch(e) {
/**
* In the custom elements build version of ionicons, referencing an icon
* by name will throw an invalid URL error because the asset path is not defined.
* This catches that error and logs something that is more developer-friendly.
*/
console.warn(`[Ionicons Warning]: Could not load icon with name "${name}". Ensure that the icon is registered using addIcons or that the icon SVG data is passed directly to the icon component.`);
}
};


Expand Down

0 comments on commit 96aa17e

Please sign in to comment.