Saltar al contenido
Marketplace

nextjs-best-practices

de sickn33

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

Resumen

SKILL.mdLeída en 1e53ce2

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.

Archivos 1 archivo

Instálala a mano

Deska ejecuta esto por ti, para cada agente que elijas. Para ejecutarlo tú en una terminal:

npx skills add sickn33/agentic-awesome-skills --skill nextjs-best-practices

Más de sickn33

  • nodejs-best-practicessickn33Node.js development principles and decision-making. Framework selection, async patterns, security, and architecture. Teaches thinking, not copying.13.7 k instalaciones en skills.sh0
  • typescript-expertsickn33TypeScript and JavaScript expert with deep knowledge of type-level programming, performance optimization, monorepo management, migration strategies, and modern tooling.12.3 k instalaciones en skills.sh0
  • clean-codesickn33This skill embodies the principles of \"Clean Code\" by Robert C. Martin (Uncle Bob). Use it to transform \"code that works\" into \"code that is clean.\"12 k instalaciones en skills.sh0
  • api-security-best-practicessickn33Implement secure API design patterns including authentication, authorization, input validation, rate limiting, and protection against common API vulnerabilities8,700 instalaciones en skills.sh0
  • browser-automationsickn33Build reliable browser checks using observed UI state, semantic locators, bounded waits, isolated test data and explicit outcome verification.6,700 instalaciones en skills.sh0
Todas las skills de sickn33