Next.js Server Components

Explain React Server Components and Client Components in Next.js App Router.

51|6|Updated Mar 28, 2019
One-click install
npx skills add https://github.com/Mte90/dotfiles --skill next-js-server-components
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Next.js Server Components
Source: https://github.com/Mte90/dotfiles/tree/main/.config/opencode/skills/nextjs/server-components
Command: npx skills add https://github.com/Mte90/dotfiles --skill next-js-server-components

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill clarifies the fundamental differences and best practices for using Server Components and Client Components in Next.js, preventing common anti-patterns and ensuring optimal performance.

Core Features & Use Cases

  • Understand RSC Defaults: Learn how Next.js renders components on the server by default.
  • Implement Client Components: Know when and how to use the 'use client' directive for interactivity.
  • Composition Patterns: Discover how to correctly pass Server Components to Client Components.
  • Avoid Anti-Patterns: Prevent data poisoning and over-fetching issues.

Quick Start

Explain the difference between Server Components and Client Components in Next.js.

Frequently Asked Questions about Next.js Server Components

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

FAQPage Schema
What is the difference between Server and Client Components in Next.js?

Next.js Server Components render on the server by default for static content, while Client Components require the 'use client' directive to handle interactivity, state management, and browser APIs.

How do I use the 'use client' directive in Next.js App Router?

To use the 'use client' directive in the Next.js App Router, add it to the top of your component file to opt into client-side rendering for features like interactivity, state management, and browser APIs.

Can I pass Server Components as children to Client Components in Next.js?

Yes, you can pass Server Components as children to Client Components in Next.js using composition patterns, which preserves server-side benefits without turning the parent into a Server Component.

Why does my Next.js Server Component leak server-only secrets to the client?

Server Components leak server-only secrets when anti-patterns are used, such as passing sensitive server data directly to Client Components instead of fetching only what is needed on the client.

When should I avoid using Client Components in Next.js?

You should avoid using Client Components in Next.js for static content or data-fetching tasks to prevent data over-fetching issues and maintain optimal server-side rendering performance.

Does Next.js App Router render components on the server by default?

Yes, the Next.js App Router renders components on the server by default using React Server Components, requiring the 'use client' directive only when you need client-side interactivity.