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
params and searchParams
- Async
cookies() and headers()
- 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.tsx
redirect, permanentRedirect, notFound
forbidden, unauthorized (auth errors)
unstable_rethrow for 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.ts basics
- 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
generateMetadata function
- OG image generation with
next/og
- File-based metadata conventions
Image Optimization
See image.md for:
- Always use
next/image over <img>
- Remote images configuration
- Responsive
sizes attribute
- Blur placeholders
- Priority loading for LCP
Font Optimization
See font.md for:
next/font setup
- 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/script vs 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
useSearchParams and usePathname
- Which hooks require Suspense boundaries
Parallel & Intercepting Routes
See parallel-routes.md for:
- Modal patterns with
@slot and (.) interceptors
default.tsx for 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
Source: modbender/skill-library-mcp — distributed by TomeVault.
1---2name: modbender-skill-library-mcp-next-best-practices3description: ---4---5---6name: next-best-practices7description: Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling8user-invocable: false9---1011# Next.js Best Practices1213Apply these rules when writing or reviewing Next.js code.1415## File Conventions1617See [file-conventions.md](./file-conventions.md) for:18- Project structure and special files19- Route segments (dynamic, catch-all, groups)20- Parallel and intercepting routes21- Middleware rename in v16 (middleware → proxy)2223## RSC Boundaries2425Detect invalid React Server Component patterns.2627See [rsc-boundaries.md](./rsc-boundaries.md) for:28- Async client component detection (invalid)29- Non-serializable props detection30- Server Action exceptions3132## Async Patterns3334Next.js 15+ async API changes.3536See [async-patterns.md](./async-patterns.md) for:37- Async `params` and `searchParams`38- Async `cookies()` and `headers()`39- Migration codemod4041## Runtime Selection4243See [runtime-selection.md](./runtime-selection.md) for:44- Default to Node.js runtime45- When Edge runtime is appropriate4647## Directives4849See [directives.md](./directives.md) for:50- `'use client'`, `'use server'` (React)51- `'use cache'` (Next.js)5253## Functions5455See [functions.md](./functions.md) for:56- Navigation hooks: `useRouter`, `usePathname`, `useSearchParams`, `useParams`57- Server functions: `cookies`, `headers`, `draftMode`, `after`58- Generate functions: `generateStaticParams`, `generateMetadata`5960## Error Handling6162See [error-handling.md](./error-handling.md) for:63- `error.tsx`, `global-error.tsx`, `not-found.tsx`64- `redirect`, `permanentRedirect`, `notFound`65- `forbidden`, `unauthorized` (auth errors)66- `unstable_rethrow` for catch blocks6768## Data Patterns6970See [data-patterns.md](./data-patterns.md) for:71- Server Components vs Server Actions vs Route Handlers72- Avoiding data waterfalls (`Promise.all`, Suspense, preload)73- Client component data fetching7475## Route Handlers7677See [route-handlers.md](./route-handlers.md) for:78- `route.ts` basics79- GET handler conflicts with `page.tsx`80- Environment behavior (no React DOM)81- When to use vs Server Actions8283## Metadata & OG Images8485See [metadata.md](./metadata.md) for:86- Static and dynamic metadata87- `generateMetadata` function88- OG image generation with `next/og`89- File-based metadata conventions9091## Image Optimization9293See [image.md](./image.md) for:94- Always use `next/image` over `<img>`95- Remote images configuration96- Responsive `sizes` attribute97- Blur placeholders98- Priority loading for LCP99100## Font Optimization101102See [font.md](./font.md) for:103- `next/font` setup104- Google Fonts, local fonts105- Tailwind CSS integration106- Preloading subsets107108## Bundling109110See [bundling.md](./bundling.md) for:111- Server-incompatible packages112- CSS imports (not link tags)113- Polyfills (already included)114- ESM/CommonJS issues115- Bundle analysis116117## Scripts118119See [scripts.md](./scripts.md) for:120- `next/script` vs native script tags121- Inline scripts need `id`122- Loading strategies123- Google Analytics with `@next/third-parties`124125## Hydration Errors126127See [hydration-error.md](./hydration-error.md) for:128- Common causes (browser APIs, dates, invalid HTML)129- Debugging with error overlay130- Fixes for each cause131132## Suspense Boundaries133134See [suspense-boundaries.md](./suspense-boundaries.md) for:135- CSR bailout with `useSearchParams` and `usePathname`136- Which hooks require Suspense boundaries137138## Parallel & Intercepting Routes139140See [parallel-routes.md](./parallel-routes.md) for:141- Modal patterns with `@slot` and `(.)` interceptors142- `default.tsx` for fallbacks143- Closing modals correctly with `router.back()`144145## Self-Hosting146147See [self-hosting.md](./self-hosting.md) for:148- `output: 'standalone'` for Docker149- Cache handlers for multi-instance ISR150- What works vs needs extra setup151152## Debug Tricks153154See [debug-tricks.md](./debug-tricks.md) for:155- MCP endpoint for AI-assisted debugging156- Rebuild specific routes with `--debug-build-paths`157158159---160> Source: [modbender/skill-library-mcp](https://github.com/modbender/skill-library-mcp) — distributed by [TomeVault](https://tomevault.io).161<!-- tomevault:4.0:skill_md:2026-06-15 -->