All skills
wshobson avatar

/nextjs-app-router-patterns

@be57c0b
by Seth Hobsonwshobson/agents40k stars
4,281

Master Next.js 14+ App Router with Server Components, streaming, parallel routes, and advanced data fetching. Use when building Next.js applications, implementing SSR/SSG, or optimizing React Server Components.

Use this Skill: https://skilld.dev/gh/wshobson/agents/nextjs-app-router-patterns

This session only. Nothing lands on disk.

SKILL.md

β‰ˆ60 tokens always: the name and description. β‰ˆ862 when used: this file. β‰ˆ2.5k more on demand in 1 file.

Next.js App Router Patterns

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

When to Use This Skill

  • Building new Next.js applications with App Router
  • Migrating from Pages Router to App Router
  • Implementing Server Components and streaming
  • Setting up parallel and intercepting routes
  • Optimizing data fetching and caching
  • Building full-stack features with Server Actions

Core Concepts

1. Rendering Modes

Mode Where When to Use
Server Components Server only Data fetching, heavy computation, secrets
Client Components Browser Interactivity, hooks, browser APIs
Static Build time Content that rarely changes
Dynamic Request time Personalized or real-time data
Streaming Progressive Large pages, slow data sources

2. File Conventions

app/
β”œβ”€β”€ layout.tsx       # Shared UI wrapper
β”œβ”€β”€ page.tsx         # Route UI
β”œβ”€β”€ loading.tsx      # Loading UI (Suspense)
β”œβ”€β”€ error.tsx        # Error boundary
β”œβ”€β”€ not-found.tsx    # 404 UI
β”œβ”€β”€ route.ts         # API endpoint
β”œβ”€β”€ template.tsx     # Re-mounted layout
β”œβ”€β”€ default.tsx      # Parallel route fallback
└── opengraph-image.tsx  # OG image generation

Quick Start

// app/layout.tsx
import { Inter } from 'next/font/google'
import { Providers } from './providers'

const inter = Inter({ subsets: ['latin'] })

export const metadata = {
  title: { default: 'My App', template: '%s | My App' },
  description: 'Built with Next.js App Router',
}

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en" suppressHydrationWarning>
      <body className={inter.className}>
        <Providers>{children}</Providers>
      </body>
    </html>
  )
}

// app/page.tsx - Server Component by default
async function getProducts() {
  const res = await fetch('https://api.example.com/products', {
    next: { revalidate: 3600 }, // ISR: revalidate every hour
  })
  return res.json()
}

export default async function HomePage() {
  const products = await getProducts()

  return (
    <main>
      <h1>Products</h1>
      <ProductGrid products={products} />
    </main>
  )
}

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices

Do's

  • Start with Server Components - Add 'use client' only when needed
  • Colocate data fetching - Fetch data where it's used
  • Use Suspense boundaries - Enable streaming for slow data
  • Leverage parallel routes - Independent loading states
  • Use Server Actions - For mutations with progressive enhancement

Don'ts

  • Don't pass serializable data - Server β†’ Client boundary limitations
  • Don't use hooks in Server Components - No useState, useEffect
  • Don't fetch in Client Components - Use Server Components or React Query
  • Don't over-nest layouts - Each layout adds to the component tree
  • Don't ignore loading states - Always provide loading.tsx or Suspense

Source: SKILL.md on GitHub

No alerts16d5 checks Β· Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides safe technical reference documentation and code snippets for implementing common Next.js 14+ App Router architectural patterns.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW Β· No issues

  • Runlayer6mo

    1 file scanned Β· No issues

  • ZeroLeaks5mo

    Score: 93/100 Β· 2 sections analyzed

Signed by skilld at be57c0b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 4 months ago

README badge

README badge for wshobson/agents/nextjs-app-router-patterns

Provides patterns and best practices for Next.js 14+ App Router, covering Server Components, streaming, parallel routes, and data fetching strategies. Use when building or migrating to App Router architecture, implementing Server Components, or optimizing full-stack React applications.

Generated from the current SKILL.md.

Does this skill cover the Pages Router or only App Router?
This skill focuses on App Router (Next.js 14+). It includes patterns for migrating from Pages Router, but the core content targets App Router architecture.
Can I use this skill with TypeScript?
Yes. The examples throughout the skill are written in TypeScript (.tsx and .ts files).
Does this skill cover Server Actions?
Yes. Server Actions are listed as one of the core use cases and mentioned in the best practices for handling mutations.
What version of Next.js is required?
Next.js 14 or later. The skill is explicitly designed for Next.js 14+ App Router.
Does this include examples for parallel routes and intercepting routes?
Yes. Setting up parallel and intercepting routes is listed as a core use case, and the skill covers file conventions for parallel route patterns.

Generated from the current SKILL.md. These answers refresh after source changes.