Skip to main content
rule CX Codex

bundle-dynamic-imports — Claude Code rule: usage and setup

bundle-dynamic-imports guides Claude Code to lazy-load heavy components using next/dynamic with SSR disabled. Keeps your initial client bundle lean to protect TTI and LCP metrics.

no license ★ 1,064 updated 2026-01-21

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/bundle-dynamic-imports.md
Open on GitHub

What bundle-dynamic-imports does

This rule instructs the agent to avoid static imports for bulky components not needed on initial render. Claude Code switches to next/dynamic so the app splits those heavy modules into separate chunks. This keeps main bundles compact.

The guidance demonstrates on-demand loading via import() alongside { ssr: false }. Client-only tools like code editors stay out of the server bundle. The requirement directly targets TTI and LCP degradation. Because it relies on Next.js conventions, using it in other bundlers will fail.

What it helps with

  • split oversized components into separate chunks using next/dynamic
  • prevent editor or chart code from bloating the initial JavaScript payload
  • protect TTI and LCP metrics during frontend refactoring
  • turn off server-side rendering for browser-only UI widgets

Example prompts for the agent

  • Refactor monaco-panel.tsx to load the code editor dynamically
  • Add our analytics chart component to the dashboard without bundling it upfront
  • Lazy-load the heavy markdown preview using next/dynamic with ssr turned off

How to install bundle-dynamic-imports

Manually: put the files in place

.claude/rules/bundle-dynamic-imports.md

The paths frontmatter field limits the files

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about bundle-dynamic-imports

How to install bundle-dynamic-imports in Claude Code?

Save the instruction file to .claude/rules/bundle-dynamic-imports.md inside your repository. Claude Code will read it automatically during coding sessions.

What does bundle-dynamic-imports do?

It forces the model to use next/dynamic instead of standard imports for large components. This delays loading until the component is actually needed in the browser.

Why does the rule specify ssr: false?

It prevents Next.js from rendering the component during server prerendering. This avoids hydration errors for modules that depend on browser APIs.

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set20

The whole set →
_template _template — a rule-file scaffold with fields for its title and impact, plus sections for contrasting incorrect and correct code. CX Codex +1 ★ 1,064repo stars async-parallel async-parallel — a Claude rule that sends independent async calls through Promise.all() instead of awaiting them one by one. Useful when a handler piles up sequential awaits. CX Codex +1 ★ 1,064repo stars rerender-derived-state The rerender-derived-state rule favors derived boolean state over continuously changing values, reducing React re-renders. It fits responsive UI logic. CX Codex +1 ★ 1,064repo stars js-combine-iterations js-combine-iterations tells the Claude agent to replace several filter or map passes over the same array with one loop that fills the results as it goes. CX Codex +1 ★ 1,064repo stars rendering-content-visibility The rendering-content-visibility rule applies content-visibility: auto to long lists so off-screen items can wait before rendering. It fits message feeds and other scrollable collections. CX Codex +1 ★ 1,064repo stars rerender-dependencies rerender-dependencies — a Claude rule that keeps useEffect dependency arrays on primitives like user.id rather than whole objects, so an effect stops firing on every field change. CX Codex +1 ★ 1,064repo stars testing The testing rule sets conventions for TypeScript test files and the __tests__ directory. Use it to guide checks for success cases, failures, and edge conditions. CX Codex +1 ★ 1,064repo stars forge The forge rule configures Foundry workflows for Abstract and tells Claude Code to use the ZKsync mode for Solidity projects. CX Codex +1 ★ 1,064repo stars

Project sponsors

Companies that keep this analytics open