Communitygithub.com

ASoudy/AGS

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

AGS とは?

このスキルは、Next.js 13以降のApp Routerを使用した開発におけるベストプラクティスを体系的にまとめたものです。主な内容は、サーバーコンポーネントとクライアントコンポーネントの適切な使い分け、効率的なデータフェッチング戦略(ISRやダイナミックフェッチを含む)、ファイルベースのルーティングとレイアウトのパターン、APIルートハンドラ、メタデータ管理、キャッシュ戦略、サーバーアクションの正しい実装方法など多岐にわたります。また、パフォーマンス最適化(画像最適化、バンドルサイズ削減)やアンチパターンも解説しており、Next.jsの設計思想を反映した実用的なガイドラインを提供します。このスキルは、Claude CodeやCursor、CodexなどのAIエージェントがプロジェクトでNext.js App Routerを使用する際に、適切な設計判断とコード生成を支援するために設計されています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ASoudy/AGS/tree/HEAD/AGAS/plugins/antigravity-awesome-skills-claude/skills/nextjs-best-practices

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

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

ドキュメント

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

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


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

判断ツリー

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

デフォルトでの使い分け

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

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

フェッチ戦略

パターン用途
デフォルト静的(ビルド時にキャッシュ)
RevalidateISR(時間ベースのリフレッシュ)
No-store動的(リクエストごとにフェッチ)

データフロー

ソースパターン
データベースサーバーコンポーネントでのfetch
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(Canonical URL)

7. キャッシュ戦略

キャッシュレイヤー

レイヤー制御方法
リクエストキャッシュfetch options
データキャッシュ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.

ASoudy/AGS

Advanced JavaScript animation library skill for creating complex, high-performance web animations.

ASoudy/AGS

Astropy is the core Python package for astronomy, providing essential functionality for astronomical research and data analysis.

ASoudy/AGS

Build content-focused websites with Astro — zero JS by default, islands architecture, multi-framework components, and Markdown/MDX support.

ASoudy/AGS

One sentence - what this skill does and when to invoke it

ASoudy/AGS

Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects. Use when animations stutter, transitions jank, or reviewing CSS/JS animation performance.

ASoudy/AGS

Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.

ASoudy/AGS

Pull a YouTube video transcript into a queryable markdown vault with yt-dlp subtitle discovery, VTT cleanup, metadata frontmatter, and capture-seed stubs.

ASoudy/AGS

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities.

ASoudy/AGS

Generates high-converting Next.js/React landing pages with Tailwind CSS. Uses PAS, AIDA, and BAB frameworks for optimized copy/components (Heroes, Features, Pricing). Focuses on Core Web Vitals/SEO.

ASoudy/AGS

AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

ASoudy/AGS

CRITICAL: Use for Makepad animation system. Triggers on: makepad animation, makepad animator, makepad hover, makepad state, makepad transition, "from: { all: Forward", makepad pressed, makepad 动画, makepad 状态, makepad 过渡, makepad 悬停效果

ASoudy/AGS

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

ASoudy/AGS

Expert integration of Supabase Auth with Next.js App Router

ASoudy/AGS

React and Next.js 14+ application development with App Router, Server Components, TypeScript, Tailwind CSS, and modern frontend patterns.

ASoudy/AGS

Best practices for Remotion - Video creation in React

ASoudy/AGS

Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays

ASoudy/AGS

Seek and analyze video content using Memories.ai Large Visual Memory Model for persistent video intelligence

ASoudy/AGS

Writes complete, structured landing pages optimized for SEO ranking, AEO citation, and visitor conversion. Activate when the user wants to write or generate a landing page for a product, service, or offer.

ASoudy/AGS

Three.js animation - keyframe animation, skeletal animation, morph targets, animation mixing. Use when animating objects, playing GLTF animations, creating procedural motion, or blending animations.

ASoudy/AGS

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

関連スキル