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": {
|
"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",
|
||||||
|
|
|
||||||
|
|
@ -194,11 +194,18 @@ export class LionIcon extends LitElement {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const iconIdBeforeResolve = this.iconId;
|
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
|
// Wrap in try-catch so error is non-fatal.
|
||||||
if (this.iconId === iconIdBeforeResolve) {
|
// Failure to load an icon (asset) should not crash the entire app.
|
||||||
this.svg = svg;
|
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