.agents/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md
Nicholai 75168f7678 init: agent event bus + state
structure:
  state/CURRENT.md — 2-4 line session state (rewritten each session)
  events/ — json event bus (pull-based, optional context)
  persistent/ — important decisions (one doc per decision)
  emit — helper script for emitting events
2026-01-24 03:27:11 -07:00

36 lines
791 B
Markdown

---
title: Dynamic Imports for Heavy Components
impact: CRITICAL
impactDescription: directly affects TTI and LCP
tags: bundle, dynamic-import, code-splitting, next-dynamic
---
## Dynamic Imports for Heavy Components
Use `next/dynamic` to lazy-load large components not needed on initial render.
**Incorrect (Monaco bundles with main chunk ~300KB):**
```tsx
import { MonacoEditor } from './monaco-editor'
function CodePanel({ code }: { code: string }) {
return <MonacoEditor value={code} />
}
```
**Correct (Monaco loads on demand):**
```tsx
import dynamic from 'next/dynamic'
const MonacoEditor = dynamic(
() => import('./monaco-editor').then(m => m.MonacoEditor),
{ ssr: false }
)
function CodePanel({ code }: { code: string }) {
return <MonacoEditor value={code} />
}
```