From a5330c922c466ba30b37839dfcaa9bece6172a81 Mon Sep 17 00:00:00 2001 From: Joren Broekema Date: Mon, 23 Jan 2023 12:37:18 +0100 Subject: [PATCH] fix(icon): non-fatal console error for missing icons (#1884) * fix(icon): non-fatal console error for missing icons --- .changeset/cuddly-hats-beg.md | 5 +++++ package-lock.json | 2 +- packages/ui/components/icon/src/LionIcon.js | 15 +++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 .changeset/cuddly-hats-beg.md diff --git a/.changeset/cuddly-hats-beg.md b/.changeset/cuddly-hats-beg.md new file mode 100644 index 000000000..345ae18c6 --- /dev/null +++ b/.changeset/cuddly-hats-beg.md @@ -0,0 +1,5 @@ +--- +'@lion/ui': patch +--- + +Unresolved icons to not cause a fatal error, but console.error instead. Missing assets shouldn't prevent the rest of the application from rendering. diff --git a/package-lock.json b/package-lock.json index 98b237fef..f9ff29b19 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22630,7 +22630,7 @@ }, "packages/ui": { "name": "@lion/ui", - "version": "0.0.12", + "version": "0.0.13", "license": "MIT", "dependencies": { "@bundled-es-modules/message-format": "^6.0.4", diff --git a/packages/ui/components/icon/src/LionIcon.js b/packages/ui/components/icon/src/LionIcon.js index 6adc6b8ac..33703e372 100644 --- a/packages/ui/components/icon/src/LionIcon.js +++ b/packages/ui/components/icon/src/LionIcon.js @@ -194,11 +194,18 @@ export class LionIcon extends LitElement { } } else { const iconIdBeforeResolve = this.iconId; - const svg = await this._iconManager.resolveIconForId(iconIdBeforeResolve); - // update SVG if it did not change in the meantime to avoid race conditions - if (this.iconId === iconIdBeforeResolve) { - this.svg = svg; + // Wrap in try-catch so error is non-fatal. + // Failure to load an icon (asset) should not crash the entire app. + try { + const svg = await this._iconManager.resolveIconForId(iconIdBeforeResolve); + // update SVG if it did not change in the meantime to avoid race conditions + if (this.iconId === iconIdBeforeResolve) { + this.svg = svg; + } + } catch (e) { + // eslint-disable-next-line no-console + console.error(e); } } }