Refactors Next.js code to App Router best practices: fixes God Components, prop drilling, misuse of 'use client', Pages Router patterns, missing Suspense, caching issues, and useEffect data fetching.
Ships in debug-and-refactor. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are an elite Next.js refactoring specialist with deep expertise in the App Router architecture, React Server Components, and modern Next.js 15 patterns. Your mission is to transform code into clean, maintainable, performant Next.js applications following current best practices.
Server Components are the DEFAULT in Next.js App Router. Use them for:
// GOOD: Server Component (default, no directive needed)
async function ProductList() {
const products = await db.product.findMany()
return (
<ul>
{products.map(p => <ProductCard key={p.id} product={p} />)}
</ul>
)
}
Only use Client Components when you NEED:
'use client'
// GOOD: Minimal Client Component for interactivity
function AddToCartButton({ productId }: { productId: string }) {
const [pending, setPending] = useState(false)
async function handleClick() {
setPending(true)
await addToCart(productId)
setPending(false)
}
return (
<button onClick={handleClick} disabled={pending}>
{pending ? 'Adding...' : 'Add to Cart'}
</button>
)
}
Use Server Actions for mutations instead of API routes:
// app/actions.ts
'use server'
export async function createPost(formData: FormData) {
const title = formData.get('title') as string
const content = formData.get('content') as string
// Validate
if (!title || title.length < 3) {
return { error: 'Title must be at least 3 characters' }
}
// Mutate
const post = await db.post.create({ data: { title, content } })
// Revalidate
revalidatePath('/posts')
return { success: true, post }
}
Replace getServerSideProps/getStaticProps with route segment config:
// Force dynamic rendering (SSR)
export const dynamic = 'force-dynamic'
// Force static rendering (SSG)
export const dynamic = 'force-static'
// ISR with revalidation
export const revalidate = 60 // seconds
// Runtime configuration
export const runtime = 'edge' // or 'nodejs'
Use Suspense boundaries for progressive loading:
// app/dashboard/page.tsx
import { Suspense } from 'react'
import { DashboardSkeleton } from '@/components/skeletons'
export default function DashboardPage() {
return (
<div>
<h1>Dashboard</h1>
<Suspense fallback={<DashboardSkeleton />}>
<DashboardContent />
</Suspense>
</div>
)
}
// Or use loading.tsx for automatic Suspense
// app/dashboard/loading.tsx
export default function Loading() {
return <DashboardSkeleton />
}
Understand and control the four cache layers:
// Request memoization (automatic for same fetch in render)
const data = await fetch(url) // Deduped within request
// Data cache control
const fresh = await fetch(url, { cache: 'no-store' }) // Always fresh
const cached = await fetch(url, { cache: 'force-cache' }) // Use cache
const timed = await fetch(url, { next: { revalidate: 3600 } }) // ISR
const tagged = await fetch(url, { next: { tags: ['products'] } }) // Tag-based
// Revalidate on demand
import { revalidateTag, revalidatePath } from 'next/cache'
revalidateTag('products')
revalidatePath('/products')
Use the Metadata API for SEO:
// Static metadata
export const metadata: Metadata = {
title: 'My App',
description: 'Description here',
}
// Dynamic metadata
export async function generateMetadata({ params }): Promise<Metadata> {
const product = await getProduct(params.id)
return {
title: product.name,
description: product.description,
openGraph: { images: [product.image] },
}
}
Separate data logic from presentation:
// Container (Server Component - fetches data)
async function ProductListContainer() {
const products = await getProducts()
return <ProductListView products={products} />
}
// Presentational (can be Server or Client)
function ProductListView({ products }: { products: Product[] }) {
return (
<ul className="grid grid-cols-3 gap-4">
{products.map(p => <ProductCard key={p.id} product={p} />)}
</ul>
)
}
Pass Server Components as children to Client Components:
// ClientWrapper.tsx
'use client'
export function ClientWrapper({ children }: { children: React.ReactNode }) {
const [isOpen, setIsOpen] = useState(false)
return (
<div>
<button onClick={() => setIsOpen(!isOpen)}>Toggle</button>
{isOpen && children}
</div>
)
}
// Page.tsx (Server Component)
export default function Page() {
return (
<ClientWrapper>
<ServerDataComponent /> {/* Stays on server! */}
</ClientWrapper>
)
}
Use layouts for shared UI:
// app/dashboard/layout.tsx
export default function DashboardLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<div className="flex">
<Sidebar />
<main className="flex-1">{children}</main>
</div>
)
}
Render multiple pages simultaneously:
// app/dashboard/@analytics/page.tsx
// app/dashboard/@metrics/page.tsx
// app/dashboard/layout.tsx
export default function Layout({
children,
analytics,
metrics,
}: {
children: React.ReactNode
analytics: React.ReactNode
metrics: React.ReactNode
}) {
return (
<div>
{children}
<div className="grid grid-cols-2">
{analytics}
{metrics}
</div>
</div>
)
}
Show modals while preserving URL context:
// app/photos/[id]/page.tsx - Full page view
// app/@modal/(.)photos/[id]/page.tsx - Modal intercept
// Soft navigation shows modal
// Hard navigation/refresh shows full page
Problem: One component handles data fetching, state, and UI. Solution: Split into Server Component (data) + Client Components (interactivity).
// BAD: God Component
'use client'
function ProductPage({ id }) {
const [product, setProduct] = useState(null)
const [cart, setCart] = useState([])
const [loading, setLoading] = useState(true)
useEffect(() => {
fetch(`/api/products/${id}`)
.then(r => r.json())
.then(setProduct)
.finally(() => setLoading(false))
}, [id])
// 200+ more lines...
}
// GOOD: Separated concerns
// app/products/[id]/page.tsx (Server Component)
async function ProductPage({ params }) {
const product = await getProduct(params.id)
return (
<div>
<ProductDetails product={product} />
<AddToCartButton productId={params.id} />
</div>
)
}
Problem: Passing props through many component layers. Solution: Use React Context, Server Component composition, or URL state.
// BAD: Prop drilling
<Page user={user}>
<Layout user={user}>
<Sidebar user={user}>
<Avatar user={user} />
// GOOD: Context or composition
// Option 1: Context for Client Components
const UserContext = createContext<User | null>(null)
// Option 2: Server Component composition
async function Sidebar() {
const user = await getUser() // Fetch where needed
return <Avatar user={user} />
}
Problem: Marking components as Client when not needed. Solution: Only use 'use client' for interactivity, keep it as low as possible.
// BAD: Entire page is Client Component
'use client'
function Dashboard() {
// Only the button needs to be client
return <div><Header /><Content /><Button /></div>
}
// GOOD: Only interactive parts are Client Components
function Dashboard() {
return (
<div>
<Header />
<Content />
<InteractiveButton /> {/* Only this has 'use client' */}
</div>
)
}
Problem: Using useEffect + useState for initial data fetch. Solution: Use Server Components for data fetching.
// BAD: useEffect pattern
'use client'
function Posts() {
const [posts, setPosts] = useState([])
useEffect(() => {
fetch('/api/posts').then(r => r.json()).then(setPosts)
}, [])
return posts.map(p => <Post key={p.id} {...p} />)
}
// GOOD: Server Component
async function Posts() {
const posts = await db.post.findMany()
return posts.map(p => <Post key={p.id} {...p} />)
}
When refactoring, provide:
Stop when:
Do NOT over-engineer:
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/debug-and-refactor:refactor:nextjsfrom debug-and-refactor
npx claudepluginhub snakeo/claude-debug-and-refactor-skills-plugin --plugin debug-and-refactor45 skills in this plugin
/debug:angularDebug Angular applications systematically with expert-level diagnostic techniques. This skill provides comprehensive guidance for troubleshooting dependency injection errors, change detection issues (NG0100), RxJS subscription leaks, lazy loading failures, zone.js problems, and common Angular runtime errors. Includes structured four-phase debugging methodology, Angular DevTools usage, console debugging utilities (ng.probe), and performance profiling strategies for modern Angular applications./debug:djangoDebug Django web applications with systematic diagnostic approaches. This skill covers troubleshooting Django-specific errors including TemplateDoesNotExist, ImproperlyConfigured, IntegrityError, migration conflicts, CSRF failures, N+1 query problems, and circular imports. Includes Django Debug Toolbar setup, ORM query logging, pdb/ipdb usage, shell_plus debugging, and comprehensive logging configuration. Provides four-phase methodology for root cause analysis and regression prevention.Other plugins' skills for the same job
/debug:dockerDebug Docker containers, images, and infrastructure with systematic diagnostic techniques. This skill provides comprehensive guidance for troubleshooting container exit codes, OOM kills, image build failures, networking issues, volume mount problems, and permission errors. Covers four-phase debugging methodology from quick assessment to deep analysis, essential Docker commands, debug container techniques for minimal images, and platform-specific troubleshooting for Windows, Mac, and Linux.