Communitygithub.com

ComeOnOliver/skillshub

Next.js App Routerの原則:サーバーコンポーネント、データフェッチ、ルーティングパターン。

skillshub とは?

このスキルは、Next.js App Routerのベストプラクティスを包括的に解説します。サーバーコンポーネントとクライアントコンポーネントの使い分け、効率的なデータフェッチパターン、直感的なルーティング設計、パフォーマンス最適化、キャッシュ戦略、サーバーアクションの活用方法など、実践的な知識を提供します。特に、デフォルトでサーバーコンポーネントを使用し、必要な場合のみクライアントコンポーネントを追加する「サーバーファースト」の原則に重点を置いています。このスキルは、Claude CodeやCursor、CodexなどのAIエージェントがNext.jsプロジェクトの開発を支援する際に役立ち、コードの品質とパフォーマンス向上に貢献します。主要なファイル規約やアンチパターンも網羅しており、開発者が迅速かつ正確にNext.jsアプリケーションを構築できるようサポートします。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/sickn33/nextjs-best-practices

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Next.js ベストプラクティス

Next.js App Router 開発のための原則


1. サーバーコンポーネント vs クライアントコンポーネント

決定木

必要とするものは...?
│
├── useState, useEffect, イベントハンドラ
│   └── クライアントコンポーネント ('use client')
│
├── 直接データフェッチ、インタラクティブではない
│   └── サーバーコンポーネント (デフォルト)
│
└── 両方?
    └── 分割:サーバー親 + クライアント子

デフォルトの使い分け

タイプ使用例
サーバーデータフェッチ、レイアウト、静的コンテンツ
クライアントフォーム、ボタン、インタラクティブUI

2. データフェッチパターン

フェッチ戦略

パターン使用例
デフォルト静的(ビルド時にキャッシュ)
RevalidateISR(時間ベースの更新)
No-store動的(リクエストごとに実行)

データフロー

ソースパターン
データベースサーバーコンポーネントでフェッチ
APIキャッシュ付きfetch
ユーザー入力クライアント状態 + サーバーアクション

3. ルーティングの原則

ファイル規約

ファイル目的
page.tsxルートUI
layout.tsx共有レイアウト
loading.tsxローディング状態
error.tsxエラーバウンダリ
not-found.tsx404ページ

ルート構成

パターン使用例
ルートグループ (name)URLに影響を与えずに整理
パラレルルート @slot同じ階層の複数ページ
インターセプト (.)モーダルオーバーレイ

4. APIルート

ルートハンドラ

メソッド使用例
GETデータ読み取り
POSTデータ作成
PUT/PATCHデータ更新
DELETEデータ削除

ベストプラクティス

  • 入力をZodで検証する
  • 適切なステータスコードを返す
  • エラーを適切に処理する
  • 可能な場合はEdgeランタイムを使用する

5. パフォーマンスの原則

画像最適化

  • next/imageコンポーネントを使用する
  • ファーストビューにはpriorityを設定する
  • ブラーフプレースホルダを用意する
  • レスポンシブサイズを使用する

バンドル最適化

  • 重いコンポーネントには動的インポート
  • ルートベースのコード分割(自動)
  • バンドルアナライザで分析する

6. メタデータ

静的 vs 動的

タイプ使用例
静的エクスポート固定メタデータ
generateMetadataルートごとに動的生成

必須タグ

  • title(50〜60文字)
  • description(150〜160文字)
  • Open Graph画像
  • 正規URL

7. キャッシュ戦略

キャッシュレイヤー

レイヤー制御方法
リクエストfetchオプション
データrevalidate/tags
フルルートルート設定

再検証

方法使用例
時間ベースrevalidate: 60
オンデマンドrevalidatePath/Tag
キャッシュなしno-store

8. サーバーアクション

ユースケース

  • フォーム送信
  • データ変更
  • 再検証トリガー

ベストプラクティス

  • 'use server'でマークする
  • すべての入力を検証する
  • 型付きレスポンスを返す
  • エラーを処理する

9. アンチパターン

❌ やらないこと✅ やること
あらゆる場所で'use client'デフォルトでサーバー
クライアントコンポーネントでフェッチサーバーでフェッチ
ローディング状態をスキップloading.tsxを使用
エラーバウンダリを無視error.tsxを使用
大きなクライアントバンドル動的インポート

10. プロジェクト構造

app/
├── (marketing)/     # ルートグループ
│   └── page.tsx
├── (dashboard)/
│   ├── layout.tsx   # ダッシュボードレイアウト
│   └── page.tsx
├── api/
│   └── [resource]/
│       └── route.ts
└── components/
    └── ui/

覚えておいてください: サーバーコンポーネントがデフォルトであるのには理由があります。まずはそこから始め、必要な場合にのみクライアントを追加しましょう。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

関連スキル