# React & Next.js Performance & Bundle Optimizer

> Pinpoint server/client boundary leaks, eliminate bloated barrel-file imports, and stop N+1 database queries in React Server Components. Audits bundle waterfalls, tree-shaking traps, and ORM query loops across Next.js App Router, Prisma, and Drizzle.

React & Next.js Performance & Bundle Optimizer is a paid AI agent skill on Agensi by Tushar, in Frontend & Web Apps. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $5.67 (one-time purchase)
- Creator: [Tushar](https://www.agensi.io/creators/tushar)
- Category: [Frontend & Web Apps](https://www.agensi.io/skills/frontend-web-apps)
- Version: 1.0
- Last updated: 2026-11-22
- Security: scan passed (2026-11-22); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/react-next-js-performance-bundle-optimizer
- Tags: llm-ops, nextjs, react, performance, prisma, typescript

## About this skill

### Stop Shipping Bloated Next.js Bundles and Latency Waterfalls

Full-stack React with the Next.js App Router promises zero-bundle server rendering and fast page loads. In practice, codebases degrade quickly:
- Developers slap `"use client"` at the top of `page.tsx` or `layout.tsx`, forcing entire page subtrees and dependencies into the client JavaScript bundle.
- Backend database packages like `@prisma/client`, `drizzle-orm`, or crypto libraries accidentally get imported into client-rendered components, inflating bundle sizes by hundreds of kilobytes.
- Icon and utility barrels (`lucide-react`, `lodash`, `@mui/material`) fail Webpack tree-shaking, packaging thousands of unused modules.
- Server Components execute ORM database queries inside loops or `.map()` callbacks, causing severe N+1 latency roundtrips and blocking page streaming.

**React & Next.js Performance & Bundle Optimizer** turns your AI coding agent (Claude Code, Cursor, Copilot, Antigravity, or local LLMs) into a Senior Performance Architect that detects and refactors these bottlenecks.

---

### The 4-Vector Optimization Architecture

1. **Client/Server Boundary Enforcement**: Pushes `"use client"` down from page roots to isolated interactive leaf components. Flags any server-only or database imports that leak into client bundles.
2. **Tree-Shaking & Barrel Optimization**: Deconstructs monolithic imports from `lucide-react`, `lodash`, `@mui/material`, and `date-fns`. Configures `experimental.optimizePackageImports` in `next.config.js` to eliminate dead code.
3. **N+1 ORM & Query Waterfall Elimination**: Detects Prisma, Drizzle, and SQL queries invoked inside loops. Rewrites them into batched queries (`where: { id: { in: ids } }`) and parallelizes independent awaits with `Promise.all`.
4. **Code Splitting & Dynamic Bundles**: Isolates heavy visualization libraries (Chart.js, Recharts, Monaco) using `next/dynamic` with `{ ssr: false }`, shedding hundreds of kilobytes from initial page loads.

---

### Included Tools & Examples
- **`scripts/bundle_perf_auditor.py`**: Offline CLI that scans code for boundary leaks, barrel traps, and N+1 query loops with exact line numbers and remediation snippets.
- **`examples/leaky_dashboard.tsx`**: Typical anti-pattern dashboard exhibiting root `"use client"`, Prisma client leak, monolithic barrel imports, and N+1 query loops.
- **`examples/optimized_dashboard.tsx`**: Fully refactored implementation demonstrating zero client bundle overhead, batched database queries, and parallel data loading.
- **`examples/next.config.mjs`**: Production Next.js configuration featuring `optimizePackageImports` and bundle analyzer setup.

## Requires

- Python 3.9+

Operates 100% locally on your machine. Inspects code ASTs offline without sending code or tokens to third-party servers. No credentials, environment keys, or network access required.

## Known limitations

Requires Next.js App Router for boundary optimizations. Static analysis might miss complex dynamic imports or non-standard ORM patterns.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the React & Next.js Performance & Bundle Optimizer skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### How does this skill differ from standard Next.js linting or Webpack analysis?

This skill identifies and resolves 'boundary leaks' where server-side logic or heavy dependencies accidentally end up in your client bundle, significantly reducing your Time-to-First-Byte (TTFB) and bundle size.

### Which versions of Next.js and ORMs are supported?

It is specifically tuned for Next.js 14 and 15 using the App Router, and it provides deep integration support for projects using Prisma or Drizzle ORM to resolve database N+1 issues.

### What assets are included in the download?

You receive the `bundle_perf_auditor.py` script for deep codebase analysis, a library of specific refactoring patterns for App Router boundaries, and optimized configuration templates for your build pipeline.

### Can I use this skill with my existing AI coding assistant?

Yes, this skill is designed to work within your existing IDE or AI agent workflow by providing structured reports and refactoring instructions that your AI can execute against your local file system.

### Are there any specific scenarios where the performance auditor might miss a dependency?

The skill excels at static analysis and pattern matching for App Router architecture; however, it may not detect dependencies loaded through complex dynamic runtime evaluations.

### How are updates handled when a new version of Next.js is released?

Updates are released to coincide with major Next.js and React releases, ensuring the optimization patterns remain compatible with the latest changes in Server Components and Turbopack.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
