Communitygithub.com

Nuxt 4 パターン

ハイドレーションの安全性、パフォーマンス、ルートルール、レイジーローディング、useFetch と useAsyncData を用いた SSR セーフなデータフェッチングのための Nuxt 4 アプリケーションパターン。Nuxt 4 アプリの開発やレビュー、またはハイドレーションの不一致や SSR セーフなデータフェッチングのデバッグ時に使用します。

Nuxt 4 パターン とは?

このスキルは、SSR、ハイブリッドレンダリング、ルートルール、ページレベルのデータフェッチングを備えた Nuxt 4 アプリを構築またはデバッグするためのものです。ハイドレーションの不一致の修正、パフォーマンスの最適化(レイジーローディング、レイジーハイドレーション)、`useFetch` と `useAsyncData` を使用した SSR セーフなデータフェッチングのベストプラクティスを提供します。`routeRules` 設定を使用したルートレベルのレンダリング戦略(プリレンダリング、SWR、ISR、クライアント専用ルート)のガイダンスも含まれています。このスキルは、Claude Code、Cursor、Codex などのあらゆる AI エージェントプラットフォームと互換性があり、開発者が高品質で保守可能な Nuxt 4 アプリケーションを構築できるように支援します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/nuxt4-patterns

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

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

ドキュメント

Nuxt 4 パターン は何をしますか?

SSR、ハイブリッドレンダリング、ルートルール、またはページレベルのデータフェッチングを備えた Nuxt 4 アプリを構築またはデバッグする際に使用します。

有効化するタイミング

  • サーバー HTML とクライアント状態間のハイドレーションの不一致
  • プリレンダリング、SWR、ISR、クライアント専用セクションなどのルートレベルのレンダリングに関する決定
  • レイジーローディング、レイジーハイドレーション、ペイロードサイズに関するパフォーマンス作業
  • useFetch、useAsyncData、または $fetch を使用したページまたはコンポーネントのデータフェッチング
  • ルートパラメータ、ミドルウェア、または SSR/クライアントの違いに関連する Nuxt ルーティングの問題

ハイドレーションの安全性

  • 最初のレンダリングは決定論的に保ちます。Date.now()、Math.random()、ブラウザ専用 API、またはストレージへの読み取りを SSR でレンダリングされたテンプレート状態に直接配置しないでください。
  • サーバーが同じマークアップを生成できない場合は、onMounted()、import.meta.client、ClientOnly、または .client.vue コンポーネントの背後にブラウザ専用ロジックを移動します。
  • vue-router のものではなく、Nuxt の useRoute() コンポーザブルを使用します。
  • SSR でレンダリングされたマークアップを駆動するために route.fullPath を使用しないでください。URL フラグメントはクライアント専用であり、ハイドレーションの不一致を引き起こす可能性があります。
  • ssr: false は、不一致に対するデフォルトの修正としてではなく、真にブラウザ専用の領域のためのエスケープハッチとして扱います。

データフェッチング

  • ページとコンポーネントでの SSR セーフな API 読み取りには await useFetch() を優先します。これは、サーバーでフェッチされたデータを Nuxt ペイロードに転送し、ハイドレーション時の 2 回目のフェッチを回避します。
  • フェッチャーが単純な $fetch() 呼び出しでない場合、カスタムキーが必要な場合、または複数の非同期ソースを構成している場合に useAsyncData() を使用します。
  • キャッシュの再利用と予測可能なリフレッシュ動作のために、useAsyncData() に安定したキーを指定します。
  • useAsyncData() ハンドラーを副作用なしに保ちます。これらは SSR およびハイドレーション中に実行される可能性があります。
  • ユーザーがトリガーする書き込みまたはクライアント専用アクションには $fetch() を使用し、SSR からハイドレーションされるべきトップレベルのページデータには使用しません。
  • ナビゲーションをブロックすべきではない重要でないデータには、lazy: true、useLazyFetch()、または useLazyAsyncData() を使用します。UI で status === 'pending' を処理します。
  • SEO やファーストペイントに不要なデータにのみ server: false を使用します。
  • pick を使用してペイロードサイズを削減し、深いリアクティビティが不要な場合は、より浅いペイロードを優先します。
const route = useRoute()

const { data: article, status, error, refresh } = await useAsyncData(
  () => `article:${route.params.slug}`,
  () => $fetch(`/api/articles/${route.params.slug}`),
)

const { data: comments } = await useFetch(`/api/articles/${route.params.slug}/comments`, {
  lazy: true,
  server: false,
})

ルートルール

レンダリングおよびキャッシュ戦略には、nuxt.config.ts の routeRules を優先します。

export default defineNuxtConfig({
  routeRules: {
    '/': { prerender: true },
    '/products/**': { swr: 3600 },
    '/blog/**': { isr: true },
    '/admin/**': { ssr: false },
    '/api/**': { cache: { maxAge: 60 * 60 } },
  },
})
  • prerender: ビルド時に静的 HTML
  • swr: キャッシュされたコンテンツを提供し、バックグラウンドで再検証
  • isr: サポートされているプラットフォームでのインクリメンタル静的再生成
  • ssr: false: クライアントレンダリングルート
  • cache または redirect: Nitro レベルのレスポンス動作

ルートルールはグローバルではなく、ルートグループごとに選択します。マーケティングページ、カタログ、ダッシュボード、API は通常、異なる戦略を必要とします。

レイジーローディングとパフォーマンス

  • Nuxt はすでにルートごとにページをコード分割しています。コンポーネント分割をマイクロ最適化する前に、ルートの境界が意味のあるものになっていることを確認します。
  • Lazy プレフィックスを使用して、重要でないコンポーネントを動的にインポートします。
  • v-if を使用してレイジーコンポーネントを条件付きでレンダリングし、UI が実際に必要とするまでチャンクがロードされないようにします。
  • スクロールせずに見える範囲外、または重要でないインタラクティブ UI には、レイジーハイドレーションを使用します。
<template>
  <LazyRecommendations v-if="showRecommendations" />
  <LazyProductGallery hydrate-on-visible />
</template>
  • カスタム戦略には、可視性またはアイドル戦略を指定して defineLazyHydrationComponent() を使用します。
  • Nuxt のレイジーハイドレーションは、シングルファイルコンポーネントで機能します。レイジーハイドレートされたコンポーネントに新しい props を渡すと、すぐにハイドレーションがトリガーされます。
  • 内部ナビゲーションには NuxtLink を使用して、Nuxt がルートコンポーネントと生成されたペイロードをプリフェッチできるようにします。

レビューチェックリスト

  • 最初の SSR レンダリングとハイドレートされたクライアントレンダリングが同じマークアップを生成する
  • ページデータは useFetch または useAsyncData を使用し、トップレベルの $fetch は使用しない
  • 重要でないデータは遅延読み込みされ、明示的なローディング UI がある
  • ルートルールがページの SEO および鮮度要件と一致している
  • 重いインタラクティブアイランドは遅延読み込みまたは遅延ハイドレートされている

Individual skills in this repo

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

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

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.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

関連スキル