next-best-practices
vercel-labs/openreview
Next.js best practices reference for file conventions, RSC boundaries, data patterns, and optimization.
What is next-best-practices?
A comprehensive guide to Next.js development patterns covering file structure, React Server Components, async APIs, error handling, and performance optimization. Use this when writing or reviewing Next.js code to ensure compliance with framework conventions and best practices.
- Enforces file conventions and route segment patterns including dynamic, catch-all, and parallel routes
- Detects invalid React Server Component patterns and non-serializable props
- Guides async API usage for params, searchParams, cookies, and headers in Next.js 15+
- Provides error handling strategies with error.tsx, not-found.tsx, and redirect functions
- Optimizes images and fonts using next/image and next/font with responsive sizing and preloading
- Covers data fetching patterns, route handlers, metadata generation, and bundling best practices
How to install next-best-practices
npx skills add https://github.com/vercel-labs/openreview --skill next-best-practicesHow to use next-best-practices
- 1.Reference the appropriate guide (file-conventions.md, rsc-boundaries.md, etc.) based on the code pattern you're reviewing
- 2.Check file structure against file-conventions.md for correct naming and organization
- 3.Validate React Server Component usage and async patterns against rsc-boundaries.md and async-patterns.md
- 4.Apply error handling patterns from error-handling.md for custom error pages and redirects
- 5.Implement image and font optimization using guidelines from image.md and font.md
- 6.Use the MCP endpoint or debug-build-paths flag for AI-assisted debugging when needed
Use cases
- Reviewing Next.js code to catch RSC boundary violations and async pattern misuse
- Setting up project structure with correct file conventions and route organization
- Optimizing Core Web Vitals through image priority, font preloading, and script loading strategies
- Implementing error boundaries and custom error pages for production applications
- Migrating to Next.js 15+ async APIs and updating deprecated patterns
- Next.js developers building full-stack applications
- Code reviewers ensuring Next.js best practices compliance
- Teams migrating to Next.js 15+ async patterns
- Developers optimizing performance and Core Web Vitals
- AI coding agents assisting with Next.js code generation and review
next-best-practices FAQ
Use Server Actions for mutations and client-to-server communication from components; use Route Handlers for building APIs, webhooks, or when you need full HTTP method control.
Hydration errors occur when server and client render different content, commonly from browser APIs, date/time differences, or invalid HTML. The error overlay provides specific fixes for each cause.
Always use next/image instead of img tags, configure remote image domains, set responsive sizes attributes, add blur placeholders, and mark LCP images with priority={true}.
'use client' marks a component boundary for client-side rendering; 'use server' marks individual functions as Server Actions callable from clients. 'use cache' is a Next.js directive for caching.
In Next.js 15+, params and searchParams are async and must be awaited. Use the migration codemod to update existing code, and always await these values before accessing their properties.
Full instructions (SKILL.md)
Source of truth, from vercel-labs/openreview.
name: next-best-practices description: Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling user-invocable: false
Next.js Best Practices
Apply these rules when writing or reviewing Next.js code.
File Conventions
See file-conventions.md for:
- Project structure and special files
- Route segments (dynamic, catch-all, groups)
- Parallel and intercepting routes
- Middleware rename in v16 (middleware → proxy)
RSC Boundaries
Detect invalid React Server Component patterns.
See rsc-boundaries.md for:
- Async client component detection (invalid)
- Non-serializable props detection
- Server Action exceptions
Async Patterns
Next.js 15+ async API changes.
See async-patterns.md for:
- Async
paramsandsearchParams - Async
cookies()andheaders() - Migration codemod
Runtime Selection
See runtime-selection.md for:
- Default to Node.js runtime
- When Edge runtime is appropriate
Directives
See directives.md for:
'use client','use server'(React)'use cache'(Next.js)
Functions
See functions.md for:
- Navigation hooks:
useRouter,usePathname,useSearchParams,useParams - Server functions:
cookies,headers,draftMode,after - Generate functions:
generateStaticParams,generateMetadata
Error Handling
See error-handling.md for:
error.tsx,global-error.tsx,not-found.tsxredirect,permanentRedirect,notFoundforbidden,unauthorized(auth errors)unstable_rethrowfor catch blocks
Data Patterns
See data-patterns.md for:
- Server Components vs Server Actions vs Route Handlers
- Avoiding data waterfalls (
Promise.all, Suspense, preload) - Client component data fetching
Route Handlers
See route-handlers.md for:
route.tsbasics- GET handler conflicts with
page.tsx - Environment behavior (no React DOM)
- When to use vs Server Actions
Metadata & OG Images
See metadata.md for:
- Static and dynamic metadata
generateMetadatafunction- OG image generation with
next/og - File-based metadata conventions
Image Optimization
See image.md for:
- Always use
next/imageover<img> - Remote images configuration
- Responsive
sizesattribute - Blur placeholders
- Priority loading for LCP
Font Optimization
See font.md for:
next/fontsetup- Google Fonts, local fonts
- Tailwind CSS integration
- Preloading subsets
Bundling
See bundling.md for:
- Server-incompatible packages
- CSS imports (not link tags)
- Polyfills (already included)
- ESM/CommonJS issues
- Bundle analysis
Scripts
See scripts.md for:
next/scriptvs native script tags- Inline scripts need
id - Loading strategies
- Google Analytics with
@next/third-parties
Hydration Errors
See hydration-error.md for:
- Common causes (browser APIs, dates, invalid HTML)
- Debugging with error overlay
- Fixes for each cause
Suspense Boundaries
See suspense-boundaries.md for:
- CSR bailout with
useSearchParamsandusePathname - Which hooks require Suspense boundaries
Parallel & Intercepting Routes
See parallel-routes.md for:
- Modal patterns with
@slotand(.)interceptors default.tsxfor fallbacks- Closing modals correctly with
router.back()
Self-Hosting
See self-hosting.md for:
output: 'standalone'for Docker- Cache handlers for multi-instance ISR
- What works vs needs extra setup
Debug Tricks
See debug-tricks.md for:
- MCP endpoint for AI-assisted debugging
- Rebuild specific routes with
--debug-build-paths
Related skills
More from vercel-labs/openreview and the wider catalog.

next-cache-components
Enable Partial Prerendering in Next.js 16 with static, cached, and dynamic content mixing.

opensrc
Fetch dependency source code to give AI agents deeper implementation context.

oauth
Configure OAuth providers to work with portless local dev URLs, fixing redirect URI mismatches.

portless
Replace port numbers with stable, named .localhost URLs for local development.

find-skills
Discover and install agent skills from the open ecosystem when users ask for specialized capabilities.

nextjs
Expert guidance for building, debugging, and architecting Next.js applications with App Router.