agentleFS
RevealUIStudioRevealUIStudio/revskills/skills/next-best-practices/SKILL.md

next-best-practices

Skill2 starsChanged 52 days agoMITView on GitHub

Next.js 15+ App Router best practices for pages, layouts, routes, server components, server actions, caching, API routes, and streaming. Use when building or reviewing Next.js code, implementing RSC patterns, PPR, metadata, error boundaries, or proxy.ts. Covers React 19 conventions, data fetching, ISR, and common mistakes.

50 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use next-cache-components, next-upgrade and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • VercelSkill

    next-cache-components

    Next.js 16 Cache Components - PPR, use cache directive, cacheLife, cacheTag, updateTag

    Also in 17 projects that use this

  • VercelSkill

    next-upgrade

    Upgrade Next.js to the latest version following official migration guides and codemods

    Also in 12 projects that use this

  • pedronauckSkill

    app-renderer-systems

    Create, extend, or debug frontend domain modules organized under systems/. Covers adapters, Query hooks, local state, and public exports; excludes generic components and backend implementation.

    Also in 3 projects that use this

  • pedronauckSkill

    refactoring-analysis

    Audit code quality and architectural health or plan refactoring using Fowler code smells and techniques; write prioritized findings to docs/_refacs/. Excludes formatting, performance, and security audits.

    Also in 3 projects that use this

  • jander99Skill

    typescript-advanced

    Design, implement, refactor, and debug advanced TypeScript patterns including generics, utility types, mapped types, conditional types, type guards, discriminated unions, and strict mode configuration. Use when writing type-safe code, fixing type errors, or improving type inference.

    Also in 3 projects that use this

  • midudevSkill

    tailwind-css-patterns

    Provides comprehensive Tailwind CSS utility-first styling patterns including responsive design, layout utilities, flexbox, grid, spacing, typography, colors, and modern CSS best practices. Use when styling React/Vue/Svelte components, building responsive layouts, implementing design systems, or optimizing CSS workflow.

    Also in 5 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

16 rules. 0 are common, 6 are distinctive, and 10 are very specific to this project.

  • 0

    Common

    Most of the 49 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 10

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All components are Server Components by default — no 'use client' needed

    line 16
  2. Very specific:

    Only add 'use client' when you need: hooks, event handlers, browser APIs, or Context

    line 17
  3. Distinctive:

    Prefer server components for data fetching — no useEffect, no loading states

    line 18
  4. Very specific:

    Use fetch() with Next.js caching extensions

    line 34
  5. Very specific:

    Use <Suspense> boundaries to mark dynamic regions

    line 58
  6. Distinctive:

    No code changes needed — just wrap dynamic content in Suspense

    line 59
  7. Distinctive:

    Always validate input (use Zod)

    line 89
  8. Distinctive:

    Always revalidate affected paths after mutations

    line 90
  9. Very specific:

    Don't use 'use client' on pages that don't need interactivity

    line 110
  10. Distinctive:

    Don't fetch data in client components when server components work

    line 111
  11. Very specific:

    Don't use useEffect for data fetching — use server components or server actions

    line 112
  12. Very specific:

    Don't put middleware.ts at the root — use proxy.ts in Next.js 16+

    line 113
  13. Very specific:

    Don't use router.push() for mutations — use server actions + revalidatePath()

    line 114
  14. Distinctive:

    Don't wrap entire pages in Suspense — wrap individual dynamic sections

    line 115
  15. Very specific:

    Use use() instead of useContext() for reading context

    line 120
  16. Very specific:

    Use ternary {condition ? <A/> : null} instead of {condition && <A/>}

    line 121

“Common” is measured: kept by at least 6 in 10 of the 49 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Next.js Best Practices (App Router, v15+)

Server Components (default)

  • All components are Server Components by default — no 'use client' needed
  • Only add 'use client' when you need: hooks, event handlers, browser APIs, or Context
  • Prefer server components for data fetching — no useEffect, no loading states
  • Pass server data to client components as props (serializable only)

Route Conventions

  • page.tsx — route page
  • layout.tsx — shared layout (wraps children, persists across navigations)
  • loading.tsx — streaming fallback (instant loading UI)
  • error.tsx — error boundary ('use client' required)
  • not-found.tsx — 404 page
  • proxy.ts — request proxy/middleware (NOT middleware.ts in v16+)
  • route.ts — API route handler

Data Fetching

  • Fetch in server components directly (no getServerSideProps)
  • Use fetch() with Next.js caching extensions
  • Deduplicate requests — React auto-deduplicates identical fetches per render
  • For mutations: server actions ('use server')

Caching Strategy

// Static (build time)
export const dynamic = 'force-static';

// Dynamic (every request)
export const dynamic = 'force-dynamic';

// ISR (revalidate every N seconds)
export const revalidate = 3600;

// On-demand revalidation
import { revalidatePath, revalidateTag } from 'next/cache';

Partial Prerendering (PPR)

  • Enable in next.config.ts: experimental: { ppr: true }
  • Static shell renders instantly, dynamic parts stream in
  • Use <Suspense> boundaries to mark dynamic regions
  • No code changes needed — just wrap dynamic content in Suspense

Metadata

// Static
export const metadata: Metadata = {
  title: 'Page Title',
  description: 'Page description',
};

// Dynamic
export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const data = await fetchData(params.id);
  return { title: data.title };
}

Server Actions

'use server';

export async function createItem(formData: FormData) {
  const name = formData.get('name') as string;
  // Validate, write to DB, revalidate
  revalidatePath('/items');
}
  • Always validate input (use Zod)
  • Always revalidate affected paths after mutations
  • Return errors as values, not thrown exceptions

Image Optimization

import Image from 'next/image';

<Image
  src="/hero.jpg"
  alt="Description"
  width={1200}
  height={630}
  priority // above the fold
  placeholder="blur"
/>

Common Mistakes to Avoid

  1. Don't use 'use client' on pages that don't need interactivity
  2. Don't fetch data in client components when server components work
  3. Don't use useEffect for data fetching — use server components or server actions
  4. Don't put middleware.ts at the root — use proxy.ts in Next.js 16+
  5. Don't use router.push() for mutations — use server actions + revalidatePath()
  6. Don't wrap entire pages in Suspense — wrap individual dynamic sections

React 19 Conventions

  • No useCallback, useMemo, or React.memo — React Compiler handles memoization
  • Use use() instead of useContext() for reading context
  • Use ternary {condition ? <A/> : null} instead of {condition && <A/>}
  • ref is a regular prop now — no forwardRef needed

Skill by RevealUI Studio — the agentic business runtime.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.