nextjs-best-practices — optimizing nextjs with server components AI-Coding-Summit-2026, community, optimizing nextjs with server components, ide skills, Claude Code, Cursor, Windsurf

v1.0.0
GitHub

About this Skill

Ideal for Full Stack Agents seeking to optimize Next.js applications with Server and Client Components. nextjs-best-practices is a set of guidelines for optimizing Next.js applications, focusing on Server and Client Component architecture and data fetching strategies.

Features

Defaulting to Server Components with optional 'use client' directive
Minimizing client-side JavaScript by pushing 'use client' deep in the component tree
Fetching data and accessing server resources exclusively in Server Components
Composing Server Components with Client Components for seamless data passing
Using async functions for server-side data fetching, such as in ProductPage components

# Core Topics

mikemikula mikemikula
[2]
[2]
Updated: 2/27/2026

Agent Capability Analysis

The nextjs-best-practices skill by mikemikula is an open-source community AI agent skill for Claude Code and other IDE workflows, helping agents execute tasks with better context, repeatability, and domain-specific guidance. Optimized for optimizing nextjs with server components.

Ideal Agent Persona

Ideal for Full Stack Agents seeking to optimize Next.js applications with Server and Client Components.

Core Value

Empowers agents to leverage Server Components for data fetching and Client Components for interactive leaf nodes, minimizing client-side JavaScript and enhancing application performance with 'use client' directive, while ensuring scalable architecture through composed data-passing.

Capabilities Granted for nextjs-best-practices

Optimizing Next.js application performance by leveraging Server Components
Minimizing client-side JavaScript with strategic 'use client' placement
Composing scalable architectures with Server Component data-passing

! Prerequisites & Limits

  • Requires understanding of Next.js Server and Client Components
  • Adherence to best practices for 'use client' directive placement
Labs Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

nextjs-best-practices

Install nextjs-best-practices, an AI agent skill for AI agent workflows and automation. Works with Claude Code, Cursor, and Windsurf with one-command setup.

SKILL.md
Readonly

Next.js 16 Best Practices

Architecture: Server vs Client Components

  • Default to Server Components; add 'use client' only at interactive leaf nodes
  • Push 'use client' as deep in the tree as possible to minimize client JS
  • Never fetch data or access server resources in Client Components
  • Compose: wrap Client Components with Server Component data-passing, not the reverse
tsx
1// ✅ Server Component fetches, Client Component is interactive leaf 2async function ProductPage({ id }: { id: string }) { 3 const product = await fetchProduct(id); 4 return <AddToCartButton product={product} />; 5} 6 7// ✅ Client leaf 8'use client'; 9export function AddToCartButton({ product }: { product: Product }) { ... }

Caching: Opt-In with "use cache"

Caching is opt-in in Next.js 16 — all code executes dynamically by default.

ts
1// next.config.ts 2const nextConfig = { cacheComponents: true }; 3export default nextConfig;
tsx
1// Cache a page, component, or function 2'use cache'; 3import { cacheLife } from 'next/cache'; 4 5export async function getProducts() { 6 cacheLife('hours'); 7 return await db.products.findAll(); 8}

Cache Invalidation APIs

ScenarioAPI
Static content, eventual consistencyrevalidateTag('tag', 'max')
User action, read-your-writesupdateTag('tag') in Server Action
Uncached dynamic data refreshrefresh() in Server Action
ts
1'use server'; 2import { updateTag } from 'next/cache'; 3 4export async function saveProfile(userId: string, data: Profile) { 5 await db.users.update(userId, data); 6 updateTag(`user-${userId}`); // User sees changes immediately 7}

Routing & Navigation

File Conventions

app/
├── layout.tsx          # Root layout (required)
├── page.tsx            # Route segment
├── loading.tsx         # Suspense fallback
├── error.tsx           # Error boundary ('use client' required)
├── not-found.tsx       # 404 handler
└── (group)/            # Route group (no URL segment)
    └── page.tsx

Async Params (Breaking Change in v16)

tsx
1// ✅ v16 — params and searchParams are async 2export default async function Page({ 3 params, 4 searchParams, 5}: { 6 params: Promise<{ slug: string }>; 7 searchParams: Promise<{ q?: string }>; 8}) { 9 const { slug } = await params; 10 const { q } = await searchParams; 11}

Parallel Routes

All parallel route slots require an explicit default.tsx:

tsx
1// app/@modal/default.tsx 2export default function Default() { return null; }

Async APIs (Breaking Change in v16)

ts
1// ✅ All must be awaited 2import { cookies, headers, draftMode } from 'next/headers'; 3 4const cookieStore = await cookies(); 5const headersList = await headers(); 6const { isEnabled } = await draftMode();

proxy.ts (replaces middleware.ts)

ts
1// proxy.ts (root of project) 2import { NextRequest, NextResponse } from 'next/server'; 3 4export default function proxy(request: NextRequest) { 5 if (!request.cookies.get('token')) { 6 return NextResponse.redirect(new URL('/login', request.url)); 7 } 8} 9 10export const config = { matcher: ['/dashboard/:path*'] };

middleware.ts is deprecated — rename to proxy.ts and rename the export to proxy.

Performance

Streaming with Suspense

Data must be fetched inside the Suspense boundary for streaming to work. Create an async loader component — never fetch above Suspense and pass data down:

tsx
1// ✅ Async loader fetches INSIDE Suspense — skeleton streams while data loads 2async function DataLoader() { 3 const items = await getItems() 4 return <ItemList items={items} /> 5} 6 7export default function Page() { 8 return ( 9 <> 10 <StaticHeader /> 11 <Suspense fallback={<Skeleton />}> 12 <DataLoader /> 13 </Suspense> 14 </> 15 ) 16} 17 18// ❌ BAD — fetching ABOVE Suspense defeats streaming 19export default async function Page() { 20 const items = await getItems() // blocks entire page 21 return ( 22 <Suspense fallback={<Skeleton />}> 23 <ItemList items={items} /> {/* skeleton never shows */} 24 </Suspense> 25 ) 26}

Query Layer (lib/queries/)

Separate read queries into lib/queries/ — never call the ORM directly in page components:

ts
1// lib/queries/todos.ts 2import { prisma } from '@/lib/prisma' 3import type { Priority, Todo } from '@/lib/types' 4 5export async function getTodos(priorityFilter?: Priority): Promise<Todo[]> { 6 return prisma.todo.findMany({ 7 where: priorityFilter ? { priority: priorityFilter } : undefined, 8 orderBy: { createdAt: 'desc' }, 9 }) 10}

Pages import from query functions; Server Actions handle mutations in actions/.

Constants-First

Never hardcode enum values — derive from shared constants:

ts
1// ✅ Derive from single source of truth 2import { PRIORITY_OPTIONS } from '@/lib/constants/priorities' 3const VALID_PRIORITIES = new Set(PRIORITY_OPTIONS.map((o) => o.value)) 4 5// ❌ BAD — hardcoded, will drift from schema 6const VALID_PRIORITIES = new Set(['LOW', 'MEDIUM', 'HIGH'])

React Compiler (Stable)

Enables automatic memoization — eliminates manual useMemo/useCallback:

ts
1// next.config.ts 2const nextConfig = { reactCompiler: true };
bash
1pnpm add babel-plugin-react-compiler@latest

Turbopack (Default)

Turbopack is now the default bundler. Remove conflicting Webpack configs or opt out:

bash
1next dev --webpack # Opt out of Turbopack

Enable filesystem caching for large projects:

ts
1experimental: { turbopackFileSystemCacheForDev: true }

TypeScript

  • Target TypeScript 5.1+, Node.js 20.9+
  • Define explicit return types on all async functions
  • Use Promise<PageProps> types for params/searchParams
  • Use next.config.ts (TypeScript native config)
ts
1// ✅ Typed route handler 2export async function GET( 3 request: Request, 4 { params }: { params: Promise<{ id: string }> } 5): Promise<Response> { 6 const { id } = await params; 7 const data = await fetchById(id); 8 return Response.json(data); 9}

Image Optimization

tsx
1import Image from 'next/image'; 2 3// Remote images require remotePatterns (not deprecated domains) 4// next.config.ts 5images: { 6 remotePatterns: [{ protocol: 'https', hostname: 'example.com' }], 7}

Server Actions

ts
1'use server'; 2 3export async function createPost(formData: FormData): Promise<void> { 4 const title = formData.get('title') as string; 5 await db.posts.create({ title }); 6 updateTag('posts'); 7}
  • Colocate with the component or in a dedicated actions/ directory
  • Always validate and sanitize inputs
  • Use updateTag for read-your-writes after mutations

Environment & Config

ts
1// next.config.ts — use env vars, not deprecated serverRuntimeConfig/publicRuntimeConfig 2const nextConfig = { 3 cacheComponents: true, 4 reactCompiler: true, 5 images: { 6 remotePatterns: [{ protocol: 'https', hostname: 'cdn.example.com' }], 7 }, 8}; 9 10export default nextConfig;

FOR SSR BEST PRACTICES LOOK HERE: /.cursor/skills/nextjs-best-practices/ssr-best-practices

Breaking Changes Checklist (v15 → v16)

  • params / searchParamsawait params / await searchParams
  • cookies() / headers() / draftMode() → add await
  • middleware.ts → rename to proxy.ts, export proxy function
  • revalidateTag('tag')revalidateTag('tag', 'max')
  • experimental.dynamicIOcacheComponents: true
  • experimental.ppr → removed; use Cache Components
  • images.domainsimages.remotePatterns
  • Parallel routes missing default.tsx → add for all slots
  • serverRuntimeConfig / publicRuntimeConfig → use .env files
  • Remove next lint from CI → use eslint or biome directly

Additional Resources

FAQ & Installation Steps

These questions and steps mirror the structured data on this page for better search understanding.

? Frequently Asked Questions

What is nextjs-best-practices?

Ideal for Full Stack Agents seeking to optimize Next.js applications with Server and Client Components. nextjs-best-practices is a set of guidelines for optimizing Next.js applications, focusing on Server and Client Component architecture and data fetching strategies.

How do I install nextjs-best-practices?

Run the command: npx killer-skills add mikemikula/AI-Coding-Summit-2026/nextjs-best-practices. It works with Cursor, Windsurf, VS Code, Claude Code, and 19+ other IDEs.

What are the use cases for nextjs-best-practices?

Key use cases include: Optimizing Next.js application performance by leveraging Server Components, Minimizing client-side JavaScript with strategic 'use client' placement, Composing scalable architectures with Server Component data-passing.

Which IDEs are compatible with nextjs-best-practices?

This skill is compatible with Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer. Use the Killer-Skills CLI for universal one-command installation.

Are there any limitations for nextjs-best-practices?

Requires understanding of Next.js Server and Client Components. Adherence to best practices for 'use client' directive placement.

How To Install

  1. 1. Open your terminal

    Open the terminal or command line in your project directory.

  2. 2. Run the install command

    Run: npx killer-skills add mikemikula/AI-Coding-Summit-2026/nextjs-best-practices. The CLI will automatically detect your IDE or AI agent and configure the skill.

  3. 3. Start using the skill

    The skill is now active. Your AI agent can use nextjs-best-practices immediately in the current project.

Related Skills

Looking for an alternative to nextjs-best-practices or another community skill for your workflow? Explore these related open-source skills.

View All

widget-generator

Logo of f
f

f.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy.

149.6k
0
AI

flags

Logo of vercel
vercel

flags is a Next.js feature management skill that enables developers to efficiently add or modify framework feature flags, streamlining React application development.

138.4k
0
Browser

zustand

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
AI

data-fetching

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
AI