agentleFS
laguagulaguagu/claude-code-nextjs-skills/skills/next-best-practices/SKILL.md

next-best-practices

Skill72 starsChanged 18 days agoMITView on GitHub

Next.js App Router best practices covering file conventions, RSC boundaries, async APIs, data patterns, hydration errors, metadata, route handlers, image/font optimization, and bundling. Use when writing or reviewing Next.js code to prevent hydration errors, RSC violations, data waterfalls, and configuration 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

We split this skill into the rules it gives an agent

5 rules. 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 50 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

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

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

    Read the installed next version and relevant node_modules/next/dist/docs/ pages before changing framework behavior.

    line 8
  2. Very specific:

    Before other work, compare the installed version with Next.js security advisories and tell the user when it is affected.

    line 21
  3. Very specific:

    Every parallel-route slot needs default.tsx, or the build fails.

    line 45
  4. Distinctive:

    Keep the project's router, caching mode, runtime and package manager unless migration is requested.

    line 91
  5. Very specific:

    Use cache-components when that mode is enabled and relevant to the task.

    line 109

“Common” is measured: kept by at least 6 in 10 of the 50 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 review and implementation

Read the installed next version and relevant node_modules/next/dist/docs/ pages before changing framework behavior. Those docs and project configuration take precedence; use a matching online version/source tag when local docs are unavailable. Next.js publishes workflow skills in vercel/next.js skills/.

Docs are bundled from 16.2; in a monorepo, read the app's own next package. The nextjs.org links in these files have local equivalents with numbered folders, so search by file name (find node_modules/next/dist/docs -name proxy.md). 01-app/02-guides/upgrading/version-16.md lists the breaking changes. Per-error pages (/docs/messages/*) are only online; the dev/build output carries the error's fix options. Exact exports are also in node_modules/next/{server,navigation,headers,cache}.d.ts.

Before other work, compare the installed version with Next.js security advisories and tell the user when it is affected. As of 2026-10-22, 16.0.0–16.4.0 (fixed in 16.4.1) and 15.x up to 15.5.27 (fixed in 15.5.28) have critical RCEs: use cache functions returning typed arrays (GHSA-673q-mjm6-r5xr, 16.x only, no workaround) and self-hosted image optimization of SVGs on glibc Linux (GHSA-2464-fhr4-w9xw; interim fix: sharp 0.35.5+). They also have a Server Actions DoS (GHSA-p3m5-59mp-jv5r). From 16.4, experimental.agentUpgrade (default 'security') reminds during next dev/next build; 16.3.x and older get no reminder.

Next.js 16 changes older examples miss

  • Sync request access is removed: cookies(), headers(), draftMode(), params (including image-metadata routes), searchParams and sitemap id are promises. next typegen generates global PageProps<'/route'>, LayoutProps and RouteContext types.
  • middleware.ts is deprecated: proxy.ts exporting proxy (or default) runs on Node.js only and rejects a runtime option; code that needs Edge stays in middleware.ts. Codemod: npx @next/codemod@latest middleware-to-proxy ..
  • Turbopack is the default for dev and build; a custom webpack config fails the build unless --webpack keeps it or explicit --turbopack ignores it. next lint is removed and next build no longer lints. serverRuntimeConfig/publicRuntimeConfig are removed.
  • Every parallel-route slot needs default.tsx, or the build fails.
  • next/image: priority is deprecated for preload; qualities defaults to [75] (other quality values are coerced); local src with a query string needs images.localPatterns; images.domains is deprecated for remotePatterns.
  • revalidateTag(tag) is deprecated; pass a profile such as 'max' or { expire: 0 } for immediate expiry. updateTag and refresh are Server Action-only. Caching details: cache-components.

The params and proxy shapes, checked against next 16.3.8 (next typegen, tsc --noEmit, next build):

// app/blog/[slug]/page.tsx; PageProps is global after `next typegen` (or dev/build)
export async function generateStaticParams() {
  return [{ slug: 'hello' }] // cacheComponents: needed for this top-level await; never []
}

export default async function Page({ params }: PageProps<'/blog/[slug]'>) {
  const { slug } = await params // a Promise; sync access was removed in 16
  return <h1>{slug}</h1>
}

// proxy.ts, replacing middleware.ts: Node.js runtime, no `runtime` export
import { NextResponse, type NextRequest } from 'next/server'

export function proxy(request: NextRequest) {
  // Optimistic check only: authorize again where the data is read.
  if (request.cookies.has('session')) return NextResponse.next()
  return NextResponse.redirect(new URL('/login', request.url))
}

export const config = { matcher: ['/dashboard/:path*'] }

The upgrade codemod does not migrate synchronous request-API access; run next-async-request-api separately when migrating that code. Use the project's package runner and review the resulting types and runtime behavior.

For an authorized upgrade, npx next@canary upgrade [app-dir] --agent=security (or =latest; experimental, documented from 16.4 in the installed 02-guides/upgrading/agent-upgrade.md) selects the target and prints its guides, codemods and checks for the current agent; plain next upgrade runs the interactive codemods.

Review the actual failure or feature, rather than applying every optimization. Keep the project's router, caching mode, runtime and package manager unless migration is requested.

Read for the affected area

AreaLocal reference
Route files, groups, proxyFile conventions
Server/client imports and propsRSC boundaries, directives
Params and request APIsAsync APIs, functions
Reads, mutations and APIsData patterns, Route Handlers
Rendering and failuresSuspense, hydration, errors
Metadata and public discoveryMetadata; nextjs-seo for an SEO audit
Assets and loadingImages, fonts, scripts
Package/runtime behaviorBundling, runtime
Navigation slots/modalsParallel routes
Deployment/debuggingSelf-hosting, diagnostics

Use cache-components when that mode is enabled and relevant to the task. Tag invalidation can also operate on fetch caches outside that mode.

Validate with the project's lint/typecheck scripts and a production build, then exercise the changed route under next start. A dev render can hide prerender/Suspense issues; a build cannot prove authorization, hydration, freshness or cross-instance behavior. Report what was actually exercised.

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.