Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 2024-03-02 - Iconify Bundle Bloat
**Learning:** Found that `@iconify-json/*` datasets are being fully imported into `client/src/components/base/IconifyIcon.tsx` and used via `getIconData`. Since these are large JSON files and imported statically, this prevents tree-shaking and bloats the bundle with thousands of unused icons. This is contrary to best practices for Iconify.
**Action:** The user prompt states: "To prevent bundle bloat in client, use @iconify/react with icon strings for on-demand fetching instead of statically importing @iconify-json datasets." I should modify `IconifyIcon.tsx` to just pass the `icon` string directly to the `@iconify/react` `Icon` component, which fetches on demand, instead of statically loading the JSON.

## 2024-03-02 - Next.js Build Requirements
**Learning:** Found that `next build` fails in `client` because the `src/api/generated` directory is missing. This requires running `pnpm --filter client openapi` to generate API files before building.
**Action:** Always ensure the API generated files exist before running build commands in `client`.
48 changes: 6 additions & 42 deletions client/src/components/base/IconifyIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
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 {
Expand All @@ -19,34 +7,10 @@ interface IconifyProps extends IconProps {
icon: string;
}

const iconSets: Record<string, IconifyJSON> = {
"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;
}
};

// ⚑ Bolt Performance Optimization
// Removed static imports of @iconify-json/* datasets to prevent massive bundle bloat.
// Passing the icon string directly to the Icon component allows @iconify/react
// to fetch SVG data on-demand and cache it, significantly reducing the initial JS payload size.
const IconifyIcon = ({
icon,
flipOnRTL = false,
Expand All @@ -56,7 +20,7 @@ const IconifyIcon = ({
return (
<Box
component={icon ? Icon : "span"}
{...(icon ? { icon: iconData(icon), ssr: true } : ({} as any))}
{...(icon ? { icon: icon } : ({} as any))}
className='iconify'
sx={[
flipOnRTL && {
Expand Down