Skills nextjs
install
source · Clone the upstream repo
git clone https://github.com/TerminalSkills/skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/TerminalSkills/skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/nextjs" ~/.claude/skills/terminalskills-skills-nextjs && rm -rf "$T"
manifest:
skills/nextjs/SKILL.mdsource content
Next.js
Overview
Next.js is a full-stack React framework featuring the App Router with Server Components, Server Actions for mutations, and multiple rendering strategies (SSG, SSR, ISR, PPR). It provides automatic code splitting, image optimization, and deployment options from Vercel to self-hosted Docker.
Instructions
- When creating routes, use file-based routing in the
directory withapp/
for pages,page.tsx
for persistent layouts,layout.tsx
for streaming, andloading.tsx
for error boundaries.error.tsx - When building components, default to Server Components (no directive needed) for zero client-side JavaScript, and add
only for components needing event handlers, hooks, or browser APIs."use client" - When fetching data, query databases directly in Server Components with
, useasync/await
with caching options (fetch()
,revalidate
), and co-locate data fetching with the component that needs it.force-cache - When handling mutations, use Server Actions with
directive and"use server"
for progressive enhancement, then call<form action={...}>
orrevalidatePath()
after mutations.revalidateTag() - When choosing rendering, default to ISR with
for most pages, userevalidate
for fully static pages, andgenerateStaticParams()
only when fresh data is required on every request.dynamic = "force-dynamic" - When adding middleware, use
at the project root for auth redirects, geolocation, and A/B testing with matcher config to scope it to specific routes.middleware.ts - When optimizing, use
for all images (WebP/AVIF, lazy loading),next/image
for zero layout shift fonts, andnext/font
for dynamic SEO.generateMetadata()
Examples
Example 1: Build a dashboard with Server Components
User request: "Create a Next.js dashboard with server-side data fetching and streaming"
Actions:
- Create dashboard layout with
and parallel routes for widgetslayout.tsx - Fetch data directly in async Server Components with database queries
- Add
for Suspense-based streaming of slow componentsloading.tsx - Use
for ISR to balance freshness and performancerevalidate
Output: A fast dashboard that streams data progressively with zero client-side JavaScript for data fetching.
Example 2: Add authentication with Server Actions
User request: "Implement login/signup with Server Actions and middleware protection"
Actions:
- Create login form with
using Server Actions<form action={loginAction}> - Implement session management with encrypted cookies
- Add middleware to redirect unauthenticated users from
/dashboard/* - Use
for instant form feedbackuseOptimistic()
Output: A progressively enhanced auth system with server-side validation and route protection.
Guidelines
- Default to Server Components; add
only for interactivity (event handlers, hooks, browser APIs)."use client" - Use Server Actions for mutations instead of API routes; they are simpler and support progressive enhancement.
- Co-locate data fetching with components: fetch in the Server Component that needs the data, not in a parent.
- Use
at route boundaries for streaming; do not block the entire page on a slow query.loading.tsx - Use
for dynamic pages; staticgenerateMetadata()
export for fixed pages.metadata - Set
on fetch calls or at page level: ISR is almost always better than full SSR.revalidate - Use
for all images; the optimization is significant (WebP/AVIF, lazy loading, responsive).next/image