fix(studio): pin lucide-react into its own chunk

Production runtime crashed with 'TypeError: e is not a function' at
folder-open-<hash>.js, blanking the page. Root cause is the same
chunk-level cycle pattern as the existing CVA workaround:
packages/ui re-exports Lucide icons, so the ui chunk transitively
pulls lucide-react; Rolldown then splits individual icons into
per-icon chunks that import createLucideIcon back from the ui chunk.
The cycle leaves the binding undefined at icon-chunk evaluation
time.

Pinning lucide-react into its own chunk breaks the cycle — the icon
chunks disappear and lucide-react only imports from rolldown-runtime.
CIRCULAR_IMPORTS.md gets a matching entry; the structural fix is the
same as for CVA and stays out of this PR.
This commit is contained in:
Alaister Young committed 2026-05-11 14:33:46 +08:00
1 parent 428b7b0764
commit b8b86d599e
1 file changed
+27 -12
+27 -12
View File
@@ -207,21 +207,36 @@ export default defineConfig(({ mode }) => {
...publicEnvDefines,
...sharedDefines,
},
// Circular-dep workaround: pin `class-variance-authority` to its own
// chunk. Without this, Rolldown splits `TreeView` into a separate
// chunk that imports `cva` from the `ui` chunk while the `ui` chunk
// imports `TreeView` back — a circular dep in the bundle output (not
// in source) that leaves `cva` undefined when TreeView's top-level
// `cva(...)` initializer runs at SSR prerender time. See
// CIRCULAR_IMPORTS.md (entry #1) — slated to be lifted into a
// separate PR.
// Circular-dep workaround: pin shared library code into dedicated
// chunks so per-component chunks don't import from a chunk that
// (transitively) imports them back.
//
// `class-variance-authority` — TreeView gets split into its own
// chunk that imports `cva` from the `ui` chunk while `ui` imports
// TreeView back. Leaves `cva` undefined at TreeView's top-level
// `cva(...)` call during SSR prerender.
//
// `lucide-react` — each icon (e.g. `FolderOpen`) gets a per-icon
// chunk that imports `createLucideIcon` from the `ui` chunk; the
// `ui` chunk in turn re-exports icons from `lucide-react`. The
// circular leaves `createLucideIcon` undefined when the icon
// chunk's top-level `createLucideIcon('FolderOpen', …)` runs —
// surfaces in the browser as "TypeError: e is not a function" at
// `folder-open-<hash>.js`.
//
// See CIRCULAR_IMPORTS.md — slated to be lifted into a separate PR.
build: {
rollupOptions: {
output: {
manualChunks: (id) =>
id.includes('node_modules/class-variance-authority/')
? 'class-variance-authority'
: undefined,
manualChunks: (id) => {
if (id.includes('node_modules/class-variance-authority/')) {
return 'class-variance-authority'
}
if (id.includes('node_modules/lucide-react/')) {
return 'lucide-react'
}
return undefined
},
},
},
},