next-best-practices

Applies Next.js best practices for file conventions, RSC boundaries, data patterns, and optimization.

2|1|Updated Apr 17, 2025
One-click install
npx skills add https://github.com/abraham-yusuf/pernikahan-web --skill next-best-practices-abraham-yusuf
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: next-best-practices
Source: https://github.com/abraham-yusuf/pernikahan-web/tree/main/.agents/skills/next-best-practices
Command: npx skills add https://github.com/abraham-yusuf/pernikahan-web --skill next-best-practices-abraham-yusuf

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Next.js developers frequently encounter subtle bugs and anti-patterns: invalid async client components, non-serializable props crossing RSC boundaries, hydration mismatches, data waterfalls, and misconfigured images or fonts. This Skill provides a structured rulebook to write and review Next.js code correctly the first time. ## Core Features & Use Cases - RSC Boundary Validation: Detects invalid patterns like async client components, non-serializable props (Date, Map, class instances), and correct Server Action usage. - Modern API Guidance: Covers Next.js 15+ async APIs (params, searchParams, cookies, headers), the v16 middleware-to-proxy rename, and cache directives. - Performance & SEO Rules: Enforces next/image and next/font usage, metadata and OG image generation, Suspense boundaries, and waterfall-free data fetching. - Use Case: When reviewing a pull request that fetches data sequentially in a page component, apply the data-patterns rules to refactor it into parallel fetches with Promise.all or Suspense streaming. ## Quick Start Review my Next.js page component for best practice violations and suggest fixes based on the next-best-practices rules.

Frequently Asked Questions about next-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix async client component errors in Next.js?

Client components cannot be async functions. Remove the async keyword, fetch the data in a parent Server Component, and pass the result down as props. Alternatively, fetch inside the client component using useEffect.

When should I use Server Actions vs Route Handlers in Next.js?

Use Server Actions for mutations triggered from your UI, such as form submissions, since they offer type safety and progressive enhancement. Use Route Handlers for webhooks, external API access, and public REST endpoints.

Why does my Next.js page become client-side rendered when using useSearchParams?

useSearchParams triggers a client-side rendering bailout in static routes unless wrapped in a Suspense boundary. Wrap the component using the hook in a Suspense fallback to keep the rest of the page statically rendered.

Can I pass Date objects or functions as props to client components?

No, props crossing the server-client boundary must be JSON-serializable. Convert Dates with toISOString(), Maps to objects, and define event handlers inside the client component or use Server Actions marked with 'use server'.

How do I handle ISR caching with multiple Next.js instances?

The default filesystem cache breaks across multiple instances. Configure a custom cacheHandler in next.config.js backed by shared storage like Redis or S3, and disable the in-memory cache with cacheMaxMemorySize set to 0.

What changed with middleware in Next.js 16?

Middleware was renamed to proxy in Next.js 16. The file becomes proxy.ts, the exported function becomes proxy(), and the config export becomes proxyConfig. Run the official upgrade codemod to rename automatically.