nextjs
Assists with building production-grade React applications using Next.js. Use when working with the App Router, Server Components, Server Actions, Middleware, or deploying to Vercel or self-hosted environments. Trigger words: nextjs, next.js, app router, server components, server actions, react framework, ssr, isr.
What this skill does
# 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 `app/` directory with `page.tsx` for pages, `layout.tsx` for persistent layouts, `loading.tsx` for streaming, and `error.tsx` for error boundaries.
- When building components, default to Server Components (no directive needed) for zero client-side JavaScript, and add `"use client"` only for components needing event handlers, hooks, or browser APIs.
- When fetching data, query databases directly in Server Components with `async/await`, use `fetch()` with caching options (`revalidate`, `force-cache`), and co-locate data fetching with the component that needs it.
- When handling mutations, use Server Actions with `"use server"` directive and `<form action={...}>` for progressive enhancement, then call `revalidatePath()` or `revalidateTag()` after mutations.
- When choosing rendering, default to ISR with `revalidate` for most pages, use `generateStaticParams()` for fully static pages, and `dynamic = "force-dynamic"` only when fresh data is required on every request.
- When adding middleware, use `middleware.ts` at the project root for auth redirects, geolocation, and A/B testing with matcher config to scope it to specific routes.
- When optimizing, use `next/image` for all images (WebP/AVIF, lazy loading), `next/font` for zero layout shift fonts, and `generateMetadata()` for dynamic SEO.
## Examples
### Example 1: Build a dashboard with Server Components
**User request:** "Create a Next.js dashboard with server-side data fetching and streaming"
**Actions:**
1. Create dashboard layout with `layout.tsx` and parallel routes for widgets
2. Fetch data directly in async Server Components with database queries
3. Add `loading.tsx` for Suspense-based streaming of slow components
4. Use `revalidate` for ISR to balance freshness and performance
**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:**
1. Create login form with `<form action={loginAction}>` using Server Actions
2. Implement session management with encrypted cookies
3. Add middleware to redirect unauthenticated users from `/dashboard/*`
4. Use `useOptimistic()` for instant form feedback
**Output:** A progressively enhanced auth system with server-side validation and route protection.
## Guidelines
- Default to Server Components; add `"use client"` only for interactivity (event handlers, hooks, browser APIs).
- 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 `loading.tsx` at route boundaries for streaming; do not block the entire page on a slow query.
- Use `generateMetadata()` for dynamic pages; static `metadata` export for fixed pages.
- Set `revalidate` on fetch calls or at page level: ISR is almost always better than full SSR.
- Use `next/image` for all images; the optimization is significant (WebP/AVIF, lazy loading, responsive).
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.