next-best-practices

Guide Next.js development with file conventions, RSC boundaries, and data fetching patterns.

11|5|Updated Feb 3, 2025
One-click install
npx skills add https://github.com/masumi-network/sokosumi --skill next-best-practices-masumi-network
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: next-best-practices
Source: https://github.com/masumi-network/sokosumi/tree/main/apps/web/.agents/skills/next-best-practices
Command: npx skills add https://github.com/masumi-network/sokosumi --skill next-best-practices-masumi-network

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance and best practices for developing robust and efficient applications using the Next.js framework, ensuring optimal performance, maintainability, and adherence to modern web development standards.

Core Features & Use Cases

  • File Conventions: Understand project structure, route segments, and special file roles.
  • RSC Boundaries: Detect and prevent invalid patterns when crossing Server/Client component boundaries.
  • Data Patterns: Choose the right data fetching pattern (Server Components, Server Actions, Route Handlers).
  • Optimization: Learn best practices for image, font, and bundling optimization.
  • Error Handling: Implement robust error handling strategies with error.tsx and global-error.tsx.
  • Use Case: A developer is unsure about the correct way to fetch data in a new Next.js 15+ application, facing potential hydration errors and performance bottlenecks. This Skill guides them through choosing the appropriate data fetching strategy and implementing it correctly.

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?

Next.js data fetching best practices recommend using Server Components for direct data access, Server Actions for mutations, and Route Handlers for API endpoints. Selecting the correct pattern optimizes performance and prevents hydration errors.

How do I prevent invalid patterns when crossing React Server Component boundaries?

Prevent invalid patterns across React Server Component boundaries by correctly applying client directives and isolating client-side logic. Managing these boundaries properly ensures maintainable Next.js architecture and prevents serialization errors.

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

Handle errors in Next.js by implementing robust strategies with error.tsx for route segments and global-error.tsx for application-wide fallbacks. This structure ensures graceful error recovery and maintains application stability during runtime exceptions.

How do I optimize images and fonts in Next.js for better performance?

Optimize images and fonts in Next.js by leveraging built-in optimization techniques and proper bundling configurations. These practices automatically serve appropriately sized assets, significantly improving web performance and overall application loading speeds.

Does this Next.js best practices guide cover asynchronous API changes and runtime selection?

Yes, this Next.js best practices guide addresses asynchronous API changes and runtime selection. It provides comprehensive instructions on choosing the correct runtime and adapting to modern API behaviors for robust web development.