Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling
Add this skill
npx mdskills install vercel-labs/next-best-practicesComprehensive Next.js reference covering 15+ critical topics with organized modular structure
1---2name: next-best-practices3description: Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling4user-invocable: false5---67# Next.js Best Practices89Apply these rules when writing or reviewing Next.js code.1011## File Conventions1213See [file-conventions.md](./file-conventions.md) for:14- Project structure and special files15- Route segments (dynamic, catch-all, groups)16- Parallel and intercepting routes17- Middleware rename in v16 (middleware → proxy)1819## RSC Boundaries2021Detect invalid React Server Component patterns.2223See [rsc-boundaries.md](./rsc-boundaries.md) for:24- Async client component detection (invalid)25- Non-serializable props detection26- Server Action exceptions2728## Async Patterns2930Next.js 15+ async API changes.3132See [async-patterns.md](./async-patterns.md) for:33- Async `params` and `searchParams`34- Async `cookies()` and `headers()`35- Migration codemod3637## Runtime Selection3839See [runtime-selection.md](./runtime-selection.md) for:40- Default to Node.js runtime41- When Edge runtime is appropriate4243## Directives4445See [directives.md](./directives.md) for:46- `'use client'`, `'use server'` (React)47- `'use cache'` (Next.js)4849## Functions5051See [functions.md](./functions.md) for:52- Navigation hooks: `useRouter`, `usePathname`, `useSearchParams`, `useParams`53- Server functions: `cookies`, `headers`, `draftMode`, `after`54- Generate functions: `generateStaticParams`, `generateMetadata`5556## Error Handling5758See [error-handling.md](./error-handling.md) for:59- `error.tsx`, `global-error.tsx`, `not-found.tsx`60- `redirect`, `permanentRedirect`, `notFound`61- `forbidden`, `unauthorized` (auth errors)62- `unstable_rethrow` for catch blocks6364## Data Patterns6566See [data-patterns.md](./data-patterns.md) for:67- Server Components vs Server Actions vs Route Handlers68- Avoiding data waterfalls (`Promise.all`, Suspense, preload)69- Client component data fetching7071## Route Handlers7273See [route-handlers.md](./route-handlers.md) for:74- `route.ts` basics75- GET handler conflicts with `page.tsx`76- Environment behavior (no React DOM)77- When to use vs Server Actions7879## Metadata & OG Images8081See [metadata.md](./metadata.md) for:82- Static and dynamic metadata83- `generateMetadata` function84- OG image generation with `next/og`85- File-based metadata conventions8687## Image Optimization8889See [image.md](./image.md) for:90- Always use `next/image` over `<img>`91- Remote images configuration92- Responsive `sizes` attribute93- Blur placeholders94- Priority loading for LCP9596## Font Optimization9798See [font.md](./font.md) for:99- `next/font` setup100- Google Fonts, local fonts101- Tailwind CSS integration102- Preloading subsets103104## Bundling105106See [bundling.md](./bundling.md) for:107- Server-incompatible packages108- CSS imports (not link tags)109- Polyfills (already included)110- ESM/CommonJS issues111- Bundle analysis112113## Scripts114115See [scripts.md](./scripts.md) for:116- `next/script` vs native script tags117- Inline scripts need `id`118- Loading strategies119- Google Analytics with `@next/third-parties`120121## Hydration Errors122123See [hydration-error.md](./hydration-error.md) for:124- Common causes (browser APIs, dates, invalid HTML)125- Debugging with error overlay126- Fixes for each cause127128## Suspense Boundaries129130See [suspense-boundaries.md](./suspense-boundaries.md) for:131- CSR bailout with `useSearchParams` and `usePathname`132- Which hooks require Suspense boundaries133134## Parallel & Intercepting Routes135136See [parallel-routes.md](./parallel-routes.md) for:137- Modal patterns with `@slot` and `(.)` interceptors138- `default.tsx` for fallbacks139- Closing modals correctly with `router.back()`140141## Self-Hosting142143See [self-hosting.md](./self-hosting.md) for:144- `output: 'standalone'` for Docker145- Cache handlers for multi-instance ISR146- What works vs needs extra setup147148## Debug Tricks149150See [debug-tricks.md](./debug-tricks.md) for:151- MCP endpoint for AI-assisted debugging152- Rebuild specific routes with `--debug-build-paths`153154
Full transparency — inspect the skill content before installing.