/install nextjs-patterns
Next.js 15 Best Practices
Core Principles
- Default to Server Components — only add
"use client"when you need interactivity or browser APIs - Colocate by feature — keep components, hooks, and utils near the routes that use them
- Type everything — leverage TypeScript with strict mode enabled
- Cache deliberately — understand the four caching layers and opt in/out explicitly
Project Structure
app/
(marketing)/ # route group: no URL segment
page.tsx
(dashboard)/
layout.tsx
[id]/
page.tsx
api/
route.ts
components/
ui/ # shared, "dumb" UI components
features/ # feature-specific components
lib/
db.ts # database client (singleton)
auth.ts # auth helpers
utils.ts
Server vs. Client Components
// ✅ Server Component (default) — runs on server, no JS sent to client
export default async function ProductList() {
const products = await db.product.findMany()
return \x3Cul>{products.map(p => \x3Cli key={p.id}>{p.name}\x3C/li>)}\x3C/ul>
}
// ✅ Client Component — only when needed
"use client"
import { useState } from "react"
export function Counter() {
const [n, setN] = useState(0)
return \x3Cbutton onClick={() => setN(n + 1)}>{n}\x3C/button>
}
Data Fetching Patterns
// Parallel fetching (avoid sequential waterfalls)
export default async function Dashboard() {
const [user, stats] = await Promise.all([
fetchUser(),
fetchStats(),
])
return \x3CView user={user} stats={stats} />
}
// fetch with cache control
const data = await fetch("https://api.example.com/data", {
next: { revalidate: 60 }, // ISR: revalidate every 60s
// cache: "no-store" // always fresh
// cache: "force-cache" // static, until manual revalidation
})
Server Actions
// app/actions.ts
"use server"
import { revalidatePath } from "next/cache"
export async function createPost(formData: FormData) {
const title = formData.get("title") as string
await db.post.create({ data: { title } })
revalidatePath("/posts")
}
// app/posts/new/page.tsx
import { createPost } from "../actions"
export default function NewPost() {
return (
\x3Cform action={createPost}>
\x3Cinput name="title" />
\x3Cbutton type="submit">Create\x3C/button>
\x3C/form>
)
}
Metadata & SEO
// Static metadata
export const metadata = {
title: "My App",
description: "...",
}
// Dynamic metadata
export async function generateMetadata({ params }) {
const post = await fetchPost(params.slug)
return { title: post.title, description: post.excerpt }
}
Error & Loading States
// app/posts/loading.tsx — automatic Suspense boundary
export default function Loading() {
return \x3CSkeleton />
}
// app/posts/error.tsx — automatic error boundary
"use client"
export default function Error({ error, reset }) {
return \x3Cbutton onClick={reset}>Retry: {error.message}\x3C/button>
}
Performance Checklist
- Images use
next/imagewith explicitwidth/height - Fonts use
next/font(zero layout shift) - Dynamic imports for heavy client components:
dynamic(() => import(...)) -
generateStaticParamsfor known dynamic routes - Bundle analyzer run:
ANALYZE=true next build - Partial Prerendering (PPR) considered for mixed static/dynamic pages
References
See references/ folder for routing patterns, caching deep-dive, and migration guide.
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install nextjs-patterns - After installation, invoke the skill by name or use
/nextjs-patterns - Provide required inputs per the skill's parameter spec and get structured output
What is Next.js 15 Best Practices?
Apply Next.js 15 best practices and modern patterns including App Router, Server Components, Server Actions, caching strategies, and performance optimization... It is an AI Agent Skill for Claude Code / OpenClaw, with 134 downloads so far.
How do I install Next.js 15 Best Practices?
Run "/install nextjs-patterns" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Next.js 15 Best Practices free?
Yes, Next.js 15 Best Practices is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Next.js 15 Best Practices support?
Next.js 15 Best Practices is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Next.js 15 Best Practices?
It is built and maintained by Hjs102468 (@goldath); the current version is v1.0.0.