diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..10bf102 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2025-02-12 - IconifyIcon Lookups Uncached +**Learning:** `client/src/components/base/IconifyIcon.tsx` resolves icons statically from multiple imported `@iconify-json` bundles but performs a linear lookup with `getIconData()` on every render without caching. +**Action:** Add a simple `Map` cache inside `IconifyIcon.tsx` to memoize the result of `getIconData()` across renders. diff --git a/client/src/components/base/IconifyIcon.tsx b/client/src/components/base/IconifyIcon.tsx index b48f0dc..dc7976f 100644 --- a/client/src/components/base/IconifyIcon.tsx +++ b/client/src/components/base/IconifyIcon.tsx @@ -33,18 +33,33 @@ const iconSets: Record = { "mdi-light": mdiLightIcons, }; +import { IconifyIcon as IconifyIconType } from "@iconify/react"; + +const iconCache = new Map(); + const iconData = (icon: string) => { + if (iconCache.has(icon)) return iconCache.get(icon); + const [prefix, name] = icon.includes(":") ? icon.split(":") : ["", icon]; if (prefix && iconSets[prefix]) { const data = getIconData(iconSets[prefix], name); - if (data) return data; + if (data) { + iconCache.set(icon, data); + return data; + } } for (const [_, icons] of Object.entries(iconSets)) { const data = getIconData(icons, name); - if (data) return data; + if (data) { + iconCache.set(icon, data); + return data; + } } + + iconCache.set(icon, undefined); + return undefined; }; const IconifyIcon = ({