PluginBench
Skill
Pass
Audit score 90

nextjs-best-practices

sickn33/agentic-awesome-skills

Next.js App Router principles: Server Components, data fetching, routing patterns.

What is nextjs-best-practices?

A reference guide for Next.js App Router development covering Server vs Client Components, data fetching strategies, routing conventions, and performance optimization. Use this when building or reviewing Next.js applications to follow best practices and avoid common anti-patterns.

  • Explains Server vs Client Component decision-making with clear decision trees
  • Provides data fetching patterns including static, ISR, and dynamic strategies
  • Documents file conventions and route organization for App Router structure
  • Covers API route handlers with HTTP methods and validation practices
  • Outlines performance optimization techniques for images and bundle size
  • Details caching strategies with request, data, and full-route layers

How to install nextjs-best-practices

npx skills add https://github.com/sickn33/agentic-awesome-skills --skill nextjs-best-practices
Claude Code
Cursor
Windsurf
Cline

How to use nextjs-best-practices

  1. 1.Review the Server vs Client Components decision tree to determine component type for your feature
  2. 2.Select appropriate data fetching pattern (static, ISR, or dynamic) based on your data source
  3. 3.Use file conventions (page.tsx, layout.tsx, loading.tsx, error.tsx) to structure your routes
  4. 4.Implement API routes using proper HTTP methods and input validation with Zod
  5. 5.Apply performance optimizations: use next/image, dynamic imports, and bundle analysis
  6. 6.Configure caching strategy using fetch options, revalidate tags, or no-store directives
  7. 7.Use Server Actions for form submissions and mutations with proper input validation
  8. 8.Check anti-patterns section to avoid common mistakes in your implementation

Use cases

Good for
  • Deciding whether to use Server or Client Components in a new feature
  • Implementing proper data fetching with appropriate caching strategies
  • Organizing routes using file conventions and route groups
  • Setting up API endpoints with proper validation and error handling
  • Optimizing image loading and bundle size in a Next.js application
Who it's for
  • Next.js developers building with App Router
  • Full-stack developers implementing server and client components
  • Frontend engineers optimizing performance and bundle size
  • Teams establishing Next.js coding standards and best practices

nextjs-best-practices FAQ

When should I use Server Components vs Client Components?

Use Server Components by default for data fetching, layouts, and static content. Only use Client Components ('use client') when you need useState, useEffect, event handlers, or interactivity. If you need both, split into a Server parent with Client children.

What's the difference between static, ISR, and dynamic data fetching?

Static caching builds data once at build time. ISR (Incremental Static Regeneration) refreshes data on a time interval using revalidate. Dynamic fetching with no-store fetches fresh data on every request.

How should I organize routes in my Next.js app?

Use the app/ directory with file conventions: page.tsx for route UI, layout.tsx for shared layouts, loading.tsx for loading states, and error.tsx for error boundaries. Use route groups (name) to organize without affecting URLs.

What are the main anti-patterns to avoid?

Avoid using 'use client' everywhere, fetching data in client components, skipping loading states, ignoring error boundaries, and creating large client bundles. Instead, use Server Components by default, fetch server-side, implement loading.tsx and error.tsx, and use dynamic imports.

How do I handle form submissions in Next.js?

Use Server Actions marked with 'use server' for form submissions and data mutations. Validate all inputs, return typed responses, and handle errors appropriately. Server Actions automatically revalidate data and can trigger revalidatePath or revalidateTag.

Full instructions (SKILL.md)

Source of truth, from sickn33/agentic-awesome-skills.


name: nextjs-best-practices description: "Next.js App Router principles. Server Components, data fetching, routing patterns." risk: critical source: community date_added: "2026-02-27"

Next.js Best Practices

Principles for Next.js App Router development.


1. Server vs Client Components

Decision Tree

Does it need...?
│
├── useState, useEffect, event handlers
│   └── Client Component ('use client')
│
├── Direct data fetching, no interactivity
│   └── Server Component (default)
│
└── Both? 
    └── Split: Server parent + Client child

By Default

TypeUse
ServerData fetching, layout, static content
ClientForms, buttons, interactive UI

2. Data Fetching Patterns

Fetch Strategy

PatternUse
DefaultStatic (cached at build)
RevalidateISR (time-based refresh)
No-storeDynamic (every request)

Data Flow

SourcePattern
DatabaseServer Component fetch
APIfetch with caching
User inputClient state + server action

3. Routing Principles

File Conventions

FilePurpose
page.tsxRoute UI
layout.tsxShared layout
loading.tsxLoading state
error.tsxError boundary
not-found.tsx404 page

Route Organization

PatternUse
Route groups (name)Organize without URL
Parallel routes @slotMultiple same-level pages
Intercepting (.)Modal overlays

4. API Routes

Route Handlers

MethodUse
GETRead data
POSTCreate data
PUT/PATCHUpdate data
DELETERemove data

Best Practices

  • Validate input with Zod
  • Return proper status codes
  • Handle errors gracefully
  • Use Edge runtime when possible

5. Performance Principles

Image Optimization

  • Use next/image component
  • Set priority for above-fold
  • Provide blur placeholder
  • Use responsive sizes

Bundle Optimization

  • Dynamic imports for heavy components
  • Route-based code splitting (automatic)
  • Analyze with bundle analyzer

6. Metadata

Static vs Dynamic

TypeUse
Static exportFixed metadata
generateMetadataDynamic per-route

Essential Tags

  • title (50-60 chars)
  • description (150-160 chars)
  • Open Graph images
  • Canonical URL

7. Caching Strategy

Cache Layers

LayerControl
Requestfetch options
Datarevalidate/tags
Full routeroute config

Revalidation

MethodUse
Time-basedrevalidate: 60
On-demandrevalidatePath/Tag
No cacheno-store

8. Server Actions

Use Cases

  • Form submissions
  • Data mutations
  • Revalidation triggers

Best Practices

  • Mark with 'use server'
  • Validate all inputs
  • Return typed responses
  • Handle errors

9. Anti-Patterns

❌ Don't✅ Do
'use client' everywhereServer by default
Fetch in client componentsFetch in server
Skip loading statesUse loading.tsx
Ignore error boundariesUse error.tsx
Large client bundlesDynamic imports

10. Project Structure

app/
├── (marketing)/     # Route group
│   └── page.tsx
├── (dashboard)/
│   ├── layout.tsx   # Dashboard layout
│   └── page.tsx
├── api/
│   └── [resource]/
│       └── route.ts
└── components/
    └── ui/

Remember: Server Components are the default for a reason. Start there, add client only when needed.

When to Use

This skill is applicable to execute the workflow or actions described in the overview.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.