Skip to content

Commit f63b5c9

Browse files
committed
chore: Bump package version to 1.1.5 and optimize icon loading mechanism
1 parent 2c8e9f2 commit f63b5c9

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@programmer_network/yail",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "Programmer Network's official UI library for React",
55
"author": "Aleksandar Grbic - (https://programmer.network)",
66
"publishConfig": {

src/Components/Icon/index.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {
1010

1111
import { IIconProps } from "./types";
1212

13+
const iconModules = import.meta.glob<{
14+
default: ComponentType<SVGProps<SVGElement>>;
15+
}>("../Icons/*.tsx");
16+
1317
const iconCache: Record<
1418
string,
1519
React.LazyExoticComponent<ComponentType<SVGProps<SVGElement>>>
@@ -24,18 +28,18 @@ const Icon: FC<IIconProps> = props => {
2428
return iconCache[iconName];
2529
}
2630

27-
const Component = lazy(() =>
28-
import(`../Icons/${iconName}.tsx`).catch(() => {
29-
setError(true);
30-
return { default: () => null };
31-
})
32-
);
31+
const importer = iconModules[`../Icons/${iconName}.tsx`];
32+
if (!importer) {
33+
setError(true);
34+
return null;
35+
}
3336

37+
const Component = lazy(importer);
3438
iconCache[iconName] = Component;
3539
return Component;
3640
}, [iconName]);
3741

38-
if (error) {
42+
if (error || !IconComponent) {
3943
return null;
4044
}
4145

0 commit comments

Comments
 (0)