The best way to control Claude Code, Codex and more from any computer or phone
perf(web): load project icons as one chunk instead of ~1,700 (#20147)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 15, 2026 at 21:36 UTC
b47746bb9c1edd5a9a0769426d311f184a02b08c
6 files changed
+72
-23
apps/web/src/components/ProjectFavicon.test.tsx
-4
@@ -53,10 +53,6 @@ vi.mock("react", async (importOriginal) => {
53
});
54
55
vi.mock("react/compiler-runtime", () => ({ c: hooks.useMemoCache }));
56
-vi.mock("lucide-react/dynamic", () => ({
57
- DynamicIcon: "dynamic-icon",
58
- iconNames: ["alarm-clock", "folder-code"],
59
-}));
56
vi.mock("@effect/atom-react", () => ({
57
useAtomValue: () => testState.faviconUrl,
58
}));
apps/web/src/components/ProjectFavicon.tsx
+12
-7
@@ -4,9 +4,8 @@ import {
4
isProjectFaviconFallbackUrl,
5
} from "@t3tools/shared/projectFavicon";
6
import { FolderCodeIcon } from "lucide-react";
7
-import type { IconName } from "lucide-react/dynamic";
7
import type { ComponentType } from "react";
9
-import { lazy, Suspense, useState } from "react";
8
+import { createElement, lazy, Suspense, useState } from "react";
9
import { useAtomValue } from "@effect/atom-react";
10
import { projectFaviconUrlAtom } from "../state/assets";
11
import { deriveProjectIdentity } from "../projectIdentity";
@@ -14,8 +13,15 @@ import { projectIconColorClassName } from "../projectIconColors";
13
import { ProjectMonogram } from "./ProjectMonogram";
14
import { cn } from "~/lib/utils";
15
17
-const DynamicIcon = lazy(() =>
18
- import("lucide-react/dynamic").then((module) => ({ default: module.DynamicIcon })),
16
+// All lucide icons load as one chunk, only once a project uses a lucide override.
17
+const LucideProjectIcon = lazy(() =>
18
+ import("../lib/lucideIconByName").then(({ lucideIconByName }) => ({
19
+ default: function LucideProjectIcon(props: { name: string; className: string }) {
20
+ return createElement(lucideIconByName(props.name) ?? FolderCodeIcon, {
21
+ className: props.className,
22
+ });
23
+ },
24
+ })),
25
);
26
27
function DynamicProjectIconFallback() {
@@ -71,10 +77,9 @@ export function ProjectFavicon(input: {
77
return (
78
<span aria-hidden="true" className={iconClassName}>
79
<Suspense fallback={<DynamicProjectIconFallback />}>
74
- <DynamicIcon
75
- name={project.projectIcon.name as IconName}
80
+ <LucideProjectIcon
81
+ name={project.projectIcon.name}
82
className={cn("size-full", colorClassName)}
77
- fallback={DynamicProjectIconFallback}
83
/>
84
</Suspense>
85
</span>
apps/web/src/components/settings/ProjectIconPickerDialog.tsx
+12
-7
@@ -6,8 +6,7 @@ import {
6
type ProjectIconColor,
7
type ProjectIconOverride,
8
} from "@t3tools/contracts";
9
-import { DynamicIcon, type IconName } from "lucide-react/dynamic";
10
-import { useEffect, useMemo, useRef, useState } from "react";
9
+import { createElement, useEffect, useMemo, useRef, useState } from "react";
10
import {
11
filterProjectIconNames,
12
firstEmoji,
@@ -16,6 +15,7 @@ import {
15
projectIconColorClassName,
16
} from "../../projectIconOptions";
17
import { cn } from "~/lib/utils";
18
+import { lucideIconByName } from "../../lib/lucideIconByName";
19
import { Button } from "../ui/button";
20
import {
21
Dialog,
@@ -30,9 +30,14 @@ import { Input } from "../ui/input";
30
import { ScrollArea } from "../ui/scroll-area";
31
import { Toggle, ToggleGroup } from "../ui/toggle-group";
32
33
-const DEFAULT_ICON: IconName = "folder-code";
33
+const DEFAULT_ICON = "folder-code";
34
const isMonogramText = Schema.is(ProjectMonogramText);
35
36
+function PickerIcon({ name }: { name: string }) {
37
+ const icon = lucideIconByName(name);
38
+ return icon ? createElement(icon, { className: "size-5" }) : null;
39
+}
40
+
41
function iconLabel(name: string): string {
42
return name
43
.split("-")
@@ -55,8 +60,8 @@ export function ProjectIconPickerDialog({
60
}) {
61
const automatic = deriveProjectIdentity(projectName);
62
const [mode, setMode] = useState<ProjectIconOverride["kind"]>(current?.kind ?? "lucide");
58
- const [iconName, setIconName] = useState<IconName>(
59
- current?.kind === "lucide" ? (current.name as IconName) : DEFAULT_ICON,
63
+ const [iconName, setIconName] = useState<string>(
64
+ current?.kind === "lucide" ? current.name : DEFAULT_ICON,
65
);
66
const [color, setColor] = useState<ProjectIconColor>(
67
current && current.kind !== "emoji" ? current.color : automatic.color,
@@ -72,7 +77,7 @@ export function ProjectIconPickerDialog({
77
useEffect(() => {
78
if (open && !previousOpenRef.current) {
79
setMode(current?.kind ?? "lucide");
75
- setIconName(current?.kind === "lucide" ? (current.name as IconName) : DEFAULT_ICON);
80
+ setIconName(current?.kind === "lucide" ? current.name : DEFAULT_ICON);
81
setColor(current && current.kind !== "emoji" ? current.color : automatic.color);
82
setLetters(current?.kind === "monogram" ? current.text : automatic.monogram);
83
setEmoji(current?.kind === "emoji" ? current.emoji : "💻");
@@ -167,7 +172,7 @@ export function ProjectIconPickerDialog({
172
)}
173
onClick={() => setIconName(name)}
174
>
170
- <DynamicIcon name={name} className="size-5" />
175
+ <PickerIcon name={name} />
176
</button>
177
))}
178
</div>
apps/web/src/lib/lucideIconByName.ts
new
+32
@@ -0,0 +1,32 @@
1
+/* oxlint-disable eslint/no-restricted-imports -- Resolves saved project icons by name, so it needs the whole set. */
2
+// Project icon overrides save lucide icons by kebab-case name. Import this module
3
+// lazily: it holds every lucide icon as one chunk, where `lucide-react/dynamic`
4
+// emits a separate chunk per icon (~1,900), which dominated build output.
5
+import * as Lucide from "lucide-react";
6
+import type { LucideIcon } from "lucide-react";
7
+
8
+const iconComponents = new Set<unknown>(Object.values(Lucide.icons));
9
+const lucideExports: Record<string, unknown> = Lucide;
10
+
11
+// Lucide derives export names this way, so it also resolves its deprecated
12
+// aliases ("alarm-check" -> AlarmCheck) that older overrides may have saved.
13
+function toPascalName(name: string): string {
14
+ return name
15
+ .split("-")
16
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
17
+ .join("");
18
+}
19
+
20
+// Inverse of toPascalName for canonical exports: "ArrowDown01" -> "arrow-down-01".
21
+// Lucide spells a handful of digit names differently ("arrow-down-0-1"); both
22
+// forms resolve to the same icon through toPascalName.
23
+function toKebabName(pascalName: string): string {
24
+ return (pascalName.match(/[A-Z][a-z]*|[0-9]+[a-z]*/g) ?? []).join("-").toLowerCase();
25
+}
26
+
27
+export const lucideIconNames: ReadonlyArray<string> = Object.keys(Lucide.icons).map(toKebabName);
28
+
29
+export function lucideIconByName(name: string): LucideIcon | undefined {
30
+ const icon = lucideExports[toPascalName(name)];
31
+ return iconComponents.has(icon) ? (icon as LucideIcon) : undefined;
32
+}
apps/web/src/projectIconOptions.test.ts
+11
@@ -1,4 +1,6 @@
1
+import { AlarmClockCheck, ArrowDown01, Layers3 } from "lucide-react";
2
import { describe, expect, it } from "vite-plus/test";
3
+import { lucideIconByName } from "./lib/lucideIconByName";
4
import {
5
filterProjectIconNames,
6
firstEmoji,
@@ -11,6 +13,15 @@ describe("projectIconOptions", () => {
13
expect(filterProjectIconNames("alarm \tclock")).toContain("alarm-clock");
14
});
15
16
+ it("resolves every offered icon name, including saved legacy spellings", () => {
17
+ for (const name of filterProjectIconNames("")) expect(lucideIconByName(name)).toBeDefined();
18
+ expect(lucideIconByName("layers-3")).toBe(Layers3);
19
+ expect(lucideIconByName("arrow-down-01")).toBe(ArrowDown01);
20
+ expect(lucideIconByName("arrow-down-0-1")).toBe(ArrowDown01);
21
+ expect(lucideIconByName("alarm-check")).toBe(AlarmClockCheck);
22
+ expect(lucideIconByName("create-lucide-icon")).toBeUndefined();
23
+ });
24
+
25
it("extracts one complete emoji grapheme", () => {
26
expect(firstEmoji(" 👩🏽💻 hello")).toBe("👩🏽💻");
27
expect(firstEmoji("🇺🇸 project")).toBe("🇺🇸");
apps/web/src/projectIconOptions.ts
+5
-5
@@ -1,7 +1,7 @@
1
-import { iconNames, type IconName } from "lucide-react/dynamic";
1
+import { lucideIconNames } from "./lib/lucideIconByName";
2
export { PROJECT_ICON_COLORS, projectIconColorClassName } from "./projectIconColors";
3
4
-const POPULAR_PROJECT_ICONS = [
4
+const POPULAR_PROJECT_ICONS: ReadonlyArray<string> = [
5
"folder-code",
6
"code-2",
7
"terminal",
@@ -26,7 +26,7 @@ const POPULAR_PROJECT_ICONS = [
26
"workflow",
27
"wrench",
28
"layers-3",
29
-] as const satisfies ReadonlyArray<IconName>;
29
+];
30
31
export const PROJECT_EMOJIS: ReadonlyArray<{ readonly emoji: string; readonly label: string }> = [
32
{ emoji: "💻", label: "Computer" },
@@ -61,10 +61,10 @@ export const PROJECT_EMOJIS: ReadonlyArray<{ readonly emoji: string; readonly la
61
{ emoji: "🌱", label: "Seedling" },
62
];
63
64
-export function filterProjectIconNames(query: string): ReadonlyArray<IconName> {
64
+export function filterProjectIconNames(query: string): ReadonlyArray<string> {
65
const normalized = query.trim().toLowerCase().replaceAll(/\s+/g, "-");
66
if (!normalized) return POPULAR_PROJECT_ICONS;
67
- return iconNames.filter((name) => name.includes(normalized)).slice(0, 60);
67
+ return lucideIconNames.filter((name) => name.includes(normalized)).slice(0, 60);
68
}
69
70
export function firstEmoji(value: string): string | null {