next-best-practices

Enforce Next.js development standards for file conventions, RSC boundaries, and data fetching.

Updated Jun 12, 2025
One-click install
npx skills add https://github.com/alirezamohammadpoor/zone2run --skill next-best-practices-alirezamohammadpoor
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: next-best-practices
Source: https://github.com/alirezamohammadpoor/zone2run/tree/main/.agents/skills/next-best-practices
Command: npx skills add https://github.com/alirezamohammadpoor/zone2run --skill next-best-practices-alirezamohammadpoor

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance to ensure your Next.js applications adhere to best practices, improving performance, maintainability, and developer experience.

Core Features & Use Cases

  • File Conventions: Understand project structure, route segments, and special files.
  • RSC Boundaries: Detect and prevent invalid React Server Component patterns.
  • Data Patterns: Choose the right pattern for fetching data (Server Components, Server Actions, Route Handlers).
  • Error Handling: Implement robust error handling with error.tsx, global-error.tsx, and navigation APIs.
  • Optimization: Optimize images, fonts, and bundling for faster load times.
  • Use Case: A developer is unsure about the correct way to fetch data in a new Next.js 15 project. They can consult this Skill to understand the differences between Server Components, Server Actions, and Route Handlers, and choose the most appropriate pattern.

Quick Start

Review the best practices for handling data fetching in Next.js Server Components.

Frequently Asked Questions about next-best-practices

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

FAQPage Schema
What is the best way to fetch data in Next.js Server Components?

Fetching data directly in Next.js Server Components is the default approach, but you can also use Server Actions or Route Handlers depending on whether you need to mutate data or expose API endpoints. This pattern improves performance by moving logic to the server.

How do I handle errors in Next.js using error.tsx?

Error handling in Next.js involves using error.tsx for route-level errors and global-error.tsx for root layout errors. These special files catch unexpected runtime errors and let you display fallback UI to recover the application gracefully.

How do React Server Component boundaries affect my Next.js project structure?

React Server Component boundaries dictate where your code executes and what can be imported. You must detect and prevent invalid patterns by keeping server-only logic out of client components to maintain strict boundaries.

How do I optimize images and fonts in a Next.js application?

Optimizing images and fonts in Next.js involves using built-in optimization techniques for faster load times. You should implement bundling strategies and leverage Next.js features to automatically serve appropriately sized assets.

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

Use Route Handlers in Next.js when you need to expose a specific API endpoint, and use Server Actions for direct data mutations triggered by client interactions. Choosing correctly ensures robust application development.