---
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
title: next-best-practices
canonical_url: https://skilld.dev/gh/robotostudio/turbo-start-sanity/next-best-practices
last_updated: 2026-10-09T17:15:43.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [async-patterns.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/async-patterns.md), [bundling.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/bundling.md), [data-patterns.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/data-patterns.md), [debug-tricks.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/debug-tricks.md), [directives.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/directives.md), [error-handling.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/error-handling.md), [file-conventions.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/file-conventions.md), [font.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/font.md), [functions.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/functions.md), [hydration-error.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/hydration-error.md), [image.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/image.md), [metadata.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/metadata.md), [parallel-routes.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/parallel-routes.md), [route-handlers.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/route-handlers.md), [rsc-boundaries.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/rsc-boundaries.md), [runtime-selection.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/runtime-selection.md), [scripts.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/scripts.md), [self-hosting.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/self-hosting.md), [suspense-boundaries.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/suspense-boundaries.md).
>
> If the user asked to install this Skill, run `npx skilld install robotostudio/turbo-start-sanity/next-best-practices`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/next-best-practices`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/robotostudio/turbo-start-sanity/next-best-practices) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/next-best-practices`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/next-best-practices --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/next-best-practices --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Next.js Best Practices

Apply these rules when writing or reviewing Next.js code.

## File Conventions

See [file-conventions.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/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](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/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](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/async-patterns.md) for:
- Async `params` and `searchParams`
- Async `cookies()` and `headers()`
- Migration codemod

## Runtime Selection

See [runtime-selection.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/runtime-selection.md) for:
- Default to Node.js runtime
- When Edge runtime is appropriate

## Directives

See [directives.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/directives.md) for:
- `'use client'`, `'use server'` (React)
- `'use cache'` (Next.js)

## Functions

See [functions.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/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](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/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](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/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](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/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](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/metadata.md) for:
- Static and dynamic metadata
- `generateMetadata` function
- OG image generation with `next/og`
- File-based metadata conventions

## Image Optimization

See [image.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/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](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/font.md) for:
- `next/font` setup
- Google Fonts, local fonts
- Tailwind CSS integration
- Preloading subsets

## Bundling

See [bundling.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/bundling.md) for:
- Server-incompatible packages
- CSS imports (not link tags)
- Polyfills (already included)
- ESM/CommonJS issues
- Bundle analysis

## Scripts

See [scripts.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/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](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/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](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/suspense-boundaries.md) for:
- CSR bailout with `useSearchParams` and `usePathname`
- Which hooks require Suspense boundaries

## Parallel & Intercepting Routes

See [parallel-routes.md](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/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](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/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](https://skilld.dev/api/skills-raw/robotostudio/turbo-start-sanity/next-best-practices/debug-tricks.md) for:
- MCP endpoint for AI-assisted debugging
- Rebuild specific routes with `--debug-build-paths`

