nextjs-best-practices — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited nextjs-best-practices (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Comprehensive reference for building Next.js applications with the App Router. Apply these standards whenever writing or reviewing Next.js code. Security-specific patterns are in the nextjs-security skill; testing in nextjs-testing; debugging in nextjs-troubleshooting.
Server First: Default every component to a React Server Component. Only opt into 'use client' at leaf components that strictly require state, effects, or browser APIs. This minimizes the JavaScript shipped to the browser.app/
layout.tsx # Root layout (replaces _app and _document)
page.tsx # Home route
error.tsx # Error boundary for this segment
not-found.tsx # 404 handling
(marketing)/ # Route Group — no URL impact
about/page.tsx
(shop)/
products/page.tsx
api/ # Route Handlers
lib/
dal.ts # Data Access Layer (server-only)
auth.ts # Authentication utilities
components/
ui/ # Client Components (interactive leaf nodes)
server/ # Server Components (data-fetching wrappers)(name) to organize routes without affecting URLs. Effective for separate layouts or logical grouping (e.g., (auth), (dashboard)).lib/dal.ts) marked with import 'server-only'.Server Components (default) — execute on the server, ship zero JS to the browser. Use for data fetching, backend logic, and static UI.
Client Components ('use client') — required only for useState, useEffect, event handlers, or browser APIs (localStorage, window).
A Server Component cannot be imported into a Client Component. Instead, pass it as a children prop from a parent Server Component. React resolves the server code first, then passes the serialized RSC Payload to the client. See references/server-client-patterns.md for complete code examples.
import 'server-only' — build fails if accidentally imported client-side.Date, Map, Set, or functions).'use client' to the deepest leaf possible to minimize the client bundle.Fetch data directly with async/await in Server Components — no useEffect or client-side libraries needed. See references/server-client-patterns.md for complete data fetching and streaming examples.
Promise.all() or Promise.allSettled() for independent requests. Sequential await statements create waterfalls.React.cache() so multiple components requesting the same data in one render only trigger one query.<Suspense fallback={<Skeleton />}> to stream content progressively.Server Actions are public POST endpoints — always treat input as hostile:
safeParse().revalidatePath() or revalidateTag() after successful mutations.<form action={serverAction}> works even before client JS loads.See references/server-client-patterns.md for complete Server Action patterns with form submission and streaming examples.
await calls that don't depend on each other — use Promise.all() instead.cookies(), headers(), or searchParams outside a <Suspense> boundary — doing so forces the entire route dynamic.fetch requests, GET Route Handlers, and the Client Router Cache are uncached by default. Opt into caching explicitly.
revalidatePath('/path') or revalidateTag('tag') inside Server Actions.use() inside a <Suspense> boundary.See references/performance-checklist.md for the complete CWV optimization reference.
Key rules:
priority prop on above-the-fold next/image. Never lazy-load the LCP image.width/height on images. Use transform for animations, not top/margin.scheduler.yield(). Move logic to Server Components.next/image for all images, next/font for self-hosted fonts, next/script with lazyOnload, next/dynamic for heavy below-fold components.<Suspense> to serve static shell instantly while streaming dynamic content.layout.tsx shares UI across sibling routes and preserves state on navigation (does not re-render)._app and _document — customize <html> and <body> here.page.tsx or the DAL.error.tsx creates an isolated React Error Boundary for its child segment.error.tsx does not catch errors in its sibling layout.tsx — only in the layout's children.not-found.tsx for graceful 404 handling.Use for edge-level routing: redirects, header injection (CSP, HSTS), A/B testing, geo-routing. Never rely on middleware as the sole security boundary — always re-verify auth in Route Handlers and Server Actions.
npm run build && npm run start locally before deploying.@next/bundle-analyzer.next/image, fonts use next/font, scripts use next/script.nextjs-security skill).instrumentation.ts (OpenTelemetry, Sentry, Datadog).The Rust-based Turbopack compiler is stable in Next.js 15+ for dev and production. Delivers up to 10x faster HMR and 2-5x faster builds.
For detailed patterns and code examples, consult:
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.