fix(icon): non-fatal console error for missing icons (#1884)

* fix(icon): non-fatal console error for missing icons
This commit is contained in:
Joren Broekema 2023-01-23 12:37:18 +01:00 committed by GitHub
parent d204195c16
commit a5330c922c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View file

@ -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.

2
package-lock.json generated
View file

@ -22630,7 +22630,7 @@
}, },
"packages/ui": { "packages/ui": {
"name": "@lion/ui", "name": "@lion/ui",
"version": "0.0.12", "version": "0.0.13",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@bundled-es-modules/message-format": "^6.0.4", "@bundled-es-modules/message-format": "^6.0.4",

View file

@ -194,12 +194,19 @@ export class LionIcon extends LitElement {
} }
} else { } else {
const iconIdBeforeResolve = this.iconId; const iconIdBeforeResolve = this.iconId;
const svg = await this._iconManager.resolveIconForId(iconIdBeforeResolve);
// 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 // update SVG if it did not change in the meantime to avoid race conditions
if (this.iconId === iconIdBeforeResolve) { if (this.iconId === iconIdBeforeResolve) {
this.svg = svg; this.svg = svg;
} }
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
} }
} }
} }