From 5a939e5fdf5339f845ad7bfa54e385ebb61938fd Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 29 Mar 2026 00:14:11 +0000 Subject: [PATCH] refactor(pdf-forge): optimize icon imports for tree-shaking Replaced the wildcard import `import * as Icons from 'lucide-react'` in the PDF Forge dashboard with explicit named imports in the `tools.ts` constants file. This allows Next.js and Webpack to correctly tree-shake unused icons, significantly reducing the client-side JavaScript bundle size for the `/pdf` route. Co-authored-by: Cukurikik <266119688+Cukurikik@users.noreply.github.com> --- .jules/bolt.md | 4 + .../components/PdfForgeDashboard.tsx | 3 +- src/modules/pdf-forge/constants/tools.ts | 95 +++++++++++++------ 3 files changed, 69 insertions(+), 33 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 15f31e28..444213e9 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -1,3 +1,7 @@ ## 2024-03-19 - React Icons Import Tree-Shaking Bottleneck **Learning:** Using `import * as Icons from "lucide-react"` combined with dynamic property lookups completely defeats Next.js and Webpack tree-shaking mechanisms. In this specific Next.js codebase, it pulled in the entire `lucide-react` library (~160 KB extra JavaScript) into the `/audio` route's client bundle, rather than just the ~30 icons actually needed. **Action:** Always import icons explicitly by name (e.g., `import { Scissors } from "lucide-react"`) and store the component reference itself when mapping configurations, rather than relying on string keys and wildcard imports. This drastically reduces First Load JS size. + +## 2024-03-29 - PDF Forge Icons Import Tree-Shaking Bottleneck +**Learning:** Found another instance where `import * as Icons from "lucide-react"` was used in `src/modules/pdf-forge/components/PdfForgeDashboard.tsx` to dynamically render icons based on string names from the `PDF_TOOLS` constants file. This causes the same tree-shaking failure, bloating the `/pdf` route bundle. +**Action:** Applied the explicit import pattern to `src/modules/pdf-forge/constants/tools.ts`, importing only the 30 necessary icons and assigning them to the `icon` property as component references, rather than string keys. This ensures only used icons are bundled. diff --git a/src/modules/pdf-forge/components/PdfForgeDashboard.tsx b/src/modules/pdf-forge/components/PdfForgeDashboard.tsx index 138a0825..6cc5e53a 100644 --- a/src/modules/pdf-forge/components/PdfForgeDashboard.tsx +++ b/src/modules/pdf-forge/components/PdfForgeDashboard.tsx @@ -2,14 +2,13 @@ import React from 'react'; import Link from 'next/link'; import { motion } from 'framer-motion'; -import * as Icons from 'lucide-react'; import { PDF_TOOLS } from '../constants/tools'; export default function PdfForgeDashboard() { return (
{PDF_TOOLS.map((tool, i) => { - const IconComponent = (Icons as unknown as Record>)[tool.icon] || Icons.FileText; + const IconComponent = tool.icon; return (