diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..2cc6e54 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-03-22 - [Static Icon Imports Anti-Pattern] +**Learning:** Statically importing entire icon sets (e.g. `import { icons as materialIcons } from "@iconify-json/material-symbols"`) bundles MEGABYTES of unused JSON data into the client bundle, causing massive performance degradation. +**Action:** Always verify icon usage in Next.js/React apps. Prefer `@iconify/react` with string-based icon names (e.g. "mdi:home") which fetches icons on demand, or use a bundler plugin to tree-shake. diff --git a/client/src/components/base/IconifyIcon.tsx b/client/src/components/base/IconifyIcon.tsx index b48f0dc..b3c0b75 100644 --- a/client/src/components/base/IconifyIcon.tsx +++ b/client/src/components/base/IconifyIcon.tsx @@ -1,52 +1,31 @@ -import { icons as entypoSocialIcons } from "@iconify-json/entypo-social"; -import { icons as evaIcons } from "@iconify-json/eva"; -import { icons as fa6Brands } from "@iconify-json/fa6-brands"; -import { icons as flagIcons } from "@iconify-json/flag"; -import { icons as icIcons } from "@iconify-json/ic"; -import { icons as materialIcons } from "@iconify-json/material-symbols"; -import { icons as materialLightIcons } from "@iconify-json/material-symbols-light"; -import { icons as mdiIcons } from "@iconify-json/mdi"; -import { icons as mdiLightIcons } from "@iconify-json/mdi-light"; -import { icons as riIcons } from "@iconify-json/ri"; -import { icons as twemojiIcons } from "@iconify-json/twemoji"; -import { Icon, IconifyJSON, IconProps } from "@iconify/react"; -import { getIconData } from "@iconify/utils"; +import { Icon, IconProps } from "@iconify/react"; import { Box, BoxProps } from "@mui/material"; -interface IconifyProps extends IconProps { - sx?: BoxProps["sx"]; +// Use BoxProps<'svg'> to ensure event handlers (onError, etc.) are compatible with SVG elements +// intersect with IconProps specific properties (rotate, flip, etc.) +type IconSpecificProps = Omit>; + +interface IconifyProps extends BoxProps<'svg'>, IconSpecificProps { + sx?: BoxProps['sx']; // Ensure sx is available (it is in BoxProps but good to be explicit if needed, though BoxProps<'svg'> has it) flipOnRTL?: boolean; icon: string; } -const iconSets: Record = { - "material-symbols": materialIcons, - "material-symbols-light": materialLightIcons, - twemoji: twemojiIcons, - eva: evaIcons, - ri: riIcons, - ic: icIcons, - flag: flagIcons, - "fa6-brands": fa6Brands, - "entypo-social": entypoSocialIcons, - mdi: mdiIcons, - "mdi-light": mdiLightIcons, -}; - -const iconData = (icon: string) => { - const [prefix, name] = icon.includes(":") ? icon.split(":") : ["", icon]; - - if (prefix && iconSets[prefix]) { - const data = getIconData(iconSets[prefix], name); - if (data) return data; - } - - for (const [_, icons] of Object.entries(iconSets)) { - const data = getIconData(icons, name); - if (data) return data; - } -}; - +/** + * Optimized IconifyIcon component. + * + * Performance Improvement: + * Previously, this component statically imported entire icon sets from @iconify-json/*, + * which caused massive bundle bloat (loading thousands of unused icons). + * + * This refactored version passes the icon string (e.g., "mdi:home") directly to the + * @iconify/react Icon component, allowing it to fetch icons on demand. + * + * Benefits: + * - Significantly reduced initial bundle size. + * - Faster application load time. + * - Eliminated unused icon data from the build. + */ const IconifyIcon = ({ icon, flipOnRTL = false, @@ -56,7 +35,7 @@ const IconifyIcon = ({ return (