nextjs-app-router-patterns

Implements Next.js App Router patterns for Server Components, streaming, and data fetching.

Updated Sep 5, 2023
One-click install
npx skills add https://github.com/eyenalxai/dotfiles --skill nextjs-app-router-patterns-eyenalxai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nextjs-app-router-patterns
Source: https://github.com/eyenalxai/dotfiles/tree/main/.agents/skills/nextjs-app-router-patterns
Command: npx skills add https://github.com/eyenalxai/dotfiles --skill nextjs-app-router-patterns-eyenalxai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building modern Next.js applications requires navigating complex App Router concepts like Server Components, streaming, parallel routes, and caching strategies, which often leads to architectural mistakes and performance issues. ## Core Features & Use Cases - Server Component Patterns: Implement data fetching, Suspense streaming, and proper Server/Client component boundaries with 'use client' directives. - Advanced Routing: Set up parallel routes, intercepting routes for modals, route handlers for APIs, and dynamic metadata generation for SEO. - Server Actions & Caching: Build mutations with Server Actions, revalidate data with tags and paths, and configure ISR caching strategies. - Use Case: When building an e-commerce product page, use this Skill to structure the page with a blocking product header, stream in reviews and recommendations via Suspense boundaries, and handle add-to-cart with a Server Action that revalidates the cart cache. ## Quick Start Ask the AI to scaffold a Next.js App Router product page with Server Components, streaming Suspense boundaries, and a Server Action for mutations.

Frequently Asked Questions about nextjs-app-router-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fetch data in Next.js App Router Server Components?

Fetch data directly inside async Server Components using the fetch API with caching options like next.revalidate for ISR or next.tags for tag-based invalidation. Colocate the fetch call in the component that uses the data, and wrap slow sections in Suspense boundaries for streaming.

When should I use 'use client' in Next.js App Router?

Add 'use client' only when a component needs interactivity such as useState, useEffect, event handlers, or browser APIs. Keep components as Server Components by default since they can fetch data directly and never ship their code to the browser.

How do Server Actions work in Next.js?

Server Actions are async functions marked with 'use server' that run on the server for mutations like form submissions. They support progressive enhancement, can call revalidateTag or revalidatePath to refresh cached data, and can redirect users after completion.

Can I use parallel routes and intercepting routes together in Next.js?

Yes, intercepting routes like (.)photos/[id] are typically placed inside a parallel route slot such as @modal to show modal overlays while preserving the full page for direct navigation. The layout receives both children and the modal slot as props.

Why is my Next.js page not streaming with Suspense?

Streaming fails when the awaited data fetch happens at the page level before rendering, blocking the entire response. Move slow fetches into child components wrapped in Suspense boundaries with skeleton fallbacks so the shell renders immediately.