fix(icon): non-fatal console error for missing icons (#1884)
* fix(icon): non-fatal console error for missing icons
This commit is contained in:
parent
d204195c16
commit
a5330c922c
3 changed files with 17 additions and 5 deletions
5
.changeset/cuddly-hats-beg.md
Normal file
5
.changeset/cuddly-hats-beg.md
Normal 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
2
package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue