From 6e449d481e7ec7568103289eb4494999843b68ce Mon Sep 17 00:00:00 2001 From: Braden Godley <70014062+braden-godley@users.noreply.github.com> Date: Tue, 30 Apr 2024 22:01:35 -0700 Subject: [PATCH] Warn about incorrect icon name and handle gracefully (#1241) * warn about incorrect icon name and handle gracefully * add changeset --- .changeset/tough-balloons-breathe.md | 5 +++++ src/replace.js | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/tough-balloons-breathe.md diff --git a/.changeset/tough-balloons-breathe.md b/.changeset/tough-balloons-breathe.md new file mode 100644 index 00000000..e47e604c --- /dev/null +++ b/.changeset/tough-balloons-breathe.md @@ -0,0 +1,5 @@ +--- +'feather-icons': patch +--- + +Feather no longer breaks when trying to replace an icon using an invalid name diff --git a/src/replace.js b/src/replace.js index 61475da4..7c48e5dc 100644 --- a/src/replace.js +++ b/src/replace.js @@ -31,6 +31,11 @@ function replaceElement(element, attrs = {}) { const name = elementAttrs['data-feather']; delete elementAttrs['data-feather']; + if (icons[name] === undefined) { + console.warn(`feather: '${name}' is not a valid icon`); + return; + } + const svgString = icons[name].toSvg({ ...attrs, ...elementAttrs,