Skip to content

Commit e1a319a

Browse files
committed
use loadManifestPlainJs to load icon js
1 parent 3c943b0 commit e1a319a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/packages/core/icon-registry/icon.registry.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { UmbIconDefinition } from './types.js';
1+
import type { UmbIconDefinition, UmbIconModule } from './types.js';
2+
import { loadManifestPlainJs } from '@umbraco-cms/backoffice/extension-api';
23
import { type UUIIconHost, UUIIconRegistry } from '@umbraco-cms/backoffice/external/uui';
34

45
/**
@@ -59,15 +60,15 @@ export class UmbIconRegistry extends UUIIconRegistry {
5960
return false;
6061
}
6162

62-
const iconPath = iconManifest.path;
63+
try {
64+
const iconModule = await loadManifestPlainJs<UmbIconModule>(iconManifest.path);
65+
if (!iconModule) throw new Error(`Failed to load icon ${iconName}`);
66+
if (!iconModule.default) throw new Error(`Icon ${iconName} is missing a default export`);
67+
iconProvider.svg = iconModule.default;
68+
} catch (error: any) {
69+
console.error(`Failed to load icon ${iconName}`, error.message);
70+
}
6371

64-
import(/* @vite-ignore */ iconPath)
65-
.then((iconModule) => {
66-
iconProvider.svg = iconModule.default;
67-
})
68-
.catch((err) => {
69-
console.error(`Failed to load icon ${iconName} on path ${iconPath}`, err.message);
70-
});
7172
return true;
7273
}
7374
}

0 commit comments

Comments
 (0)