Next.js App Router Skill
This skill enforces strict adherence to Next.js App Router and React Server Components (RSC) best practices.
Core Directives
- •Default to Server Components: Every component is a Server Component by default. Only add
"use client"when necessary for interactivity (hooks likeuseState,useEffect, event listeners, or browser APIs). - •Data Fetching: Fetch data on the server in Server Components. Avoid
useEffectfor data fetching. UsefetchAPI for automatic caching and revalidation where possible. - •Boundary Placement: Push
"use client"down the component tree as far as possible. Do not wrap entire pages or large sections in Client Components unnecessarily. - •Server Actions: Use Server Actions for data mutations instead of API routes when appropriate. Place server actions in separate files (e.g.,
actions.ts) with"use server"at the top, or inline in Server Components. - •UI Library: Use Tailwind CSS for styling and
shadcn/uicomponents for consistent, accessible UI elements. Ensureshadcn/uicomponents (often Client Components) are imported correctly. - •Routing: Follow App Router conventions strictly (
page.tsx,layout.tsx,loading.tsx,error.tsx,not-found.tsx). Use route handlers (route.ts) for external API endpoints or webhooks.