---
title: Nuxt4 Patterns Skill for Claude Code
canonical: https://skillselion.com/skills/affaan-m/ecc/nuxt4-patterns
content_type: text/markdown
description: "nuxt4-patterns is a Claude Code skill that applies battle-tested Nuxt 4 patterns for hydration safety, SSR data fetching, route rules, and lazy loading."
---

# Nuxt4 Patterns Skill

Title: Nuxt4 Patterns Skill for Claude Code

> nuxt4-patterns is a Claude Code skill that applies battle-tested Nuxt 4 patterns for hydration safety, SSR data fetching, route rules, and lazy loading.

Canonical: https://skillselion.com/skills/affaan-m/ecc/nuxt4-patterns

nuxt4-patterns is a Claude Code skill that applies battle-tested Nuxt 4 patterns for hydration safety, SSR data fetching, route rules, and lazy loading for developers who build or debug server-rendered Vue applications.

nuxt4-patterns is an ECC skill for building and debugging Nuxt 4 applications that mix SSR, hybrid rendering, and client-only islands. Hydration guidance keeps the first render deterministic by moving Date.now(), Math.random(), browser APIs, and storage reads behind onMounted, import.meta.client, ClientOnly, or .client.vue components. Data-fetching rules prefer await useFetch for SSR-safe reads, useAsyncData with stable keys for composed sources, and reserve $fetch for user-triggered writes. Route rules in nuxt.config.ts cover prerender, swr, isr, ssr false, and Nitro cache strategies per route group rather than globally. Performance patterns use Lazy-prefixed dynamic imports, hydrate-on-visible lazy hydration, and NuxtLink prefetching. A five-item review checklist verifies matching server and client markup, correct fetch composables, lazy non-critical data, aligned route rules, and lazy-loaded interactive islands. Developers reach for nuxt4-patterns when hydration warnings, route-rule tuning, or payload bloat appear in Nuxt 4 apps.

## Key facts

- Installs: 12,039
- GitHub stars: 316,020
- Author: affaan-m
- Repository: affaan-m/ECC
- Install command: `npx skills add https://github.com/affaan-m/ECC --skill nuxt4-patterns`
- Last updated: December 1, 2026

## What Nuxt4 Patterns does

Eliminate hydration errors and apply battle-tested Nuxt 4 patterns for SSR, data fetching, lazy loading, and route rules.

How do you fix Nuxt 4 hydration mismatches?

Deterministic SSR markup, routeRules config, lazy-loaded components, and a passed five-item Nuxt review checklist

Best for: Frontend developers building or debugging Nuxt 4 apps with SSR, hybrid rendering, route rules, or useFetch and useAsyncData hydration issues.

Not for: Teams on Nuxt 2-only codebases or static SPAs with no SSR requirements should use framework-specific migration guides instead of nuxt4-patterns.

- Hydration safety rules that keep first render deterministic
- 5 core data fetching patterns with useFetch and useAsyncData
- Route rules guidance for prerender, SWR, ISR and client-only sections
- Lazy loading and lazy hydration performance checklist
- SSR vs client composable and component best practices

## SKILL.md

## Nuxt 4パターン

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

### アクティベートするタイミング

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

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

- 最初のレンダリングを決定論的に保つ。SSRレンダリングされたテンプレートの状態に`Date.now()`、`Math.random()`、ブラウザのみのAPI、またはストレージ読み取りを直接入れないこと。
- サーバーが同じマークアップを生成できない場合、ブラウザのみのロジックを`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'`を処理する。
- `server: false`はSEOや最初のペイントに不要なデータのみに使用する。
- `pick`でペイロードサイズを削減し、深いリアクティビティが不要な場合はより浅いペイロードを優先する。

```ts
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`を優先する:

```ts
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`プレフィックスを使用する。
- UIが実際に必要になるまでチャンクが読み込まれないよう、`v-if`で遅延コンポーネントを条件付きでレンダリングする。
- フォールドより下または非重要なインタラクティブUIには遅延ハイドレーションを使用する。

```vue
<template>
  <LazyRecommendations v-if="showRecommendations" />
  <LazyProductGallery hydrate-on-visible />
</template>
```

- カスタム戦略には、可視性またはアイドル戦略で`defineLazyHydrationComponent()`を使用する。
- Nuxtの遅延ハイドレーションは単一ファイルコンポーネントで機能する。遅延ハイドレーションコンポーネントに新しいpropsを渡すと、すぐにハイドレーションがトリガーされる。
- Nuxtがルートコンポーネントと生成されたペイロードをプリフェッチできるよう、内部ナビゲーションには`NuxtLink`を使用する。

### レビューチェックリスト

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

## Nuxt4 Patterns FAQ

### How does nuxt4-patterns prevent hydration mismatches?

nuxt4-patterns keeps the first SSR render deterministic by excluding Date.now(), Math.random(), browser-only APIs, and storage reads from server templates. Browser-only logic moves behind onMounted, import.meta.client, ClientOnly, or .client.vue components.

### When should Nuxt 4 apps use useFetch versus $fetch?

nuxt4-patterns recommends await useFetch for SSR-safe page and component reads that hydrate from the Nuxt payload. useAsyncData suits custom fetchers or composed sources, while $fetch is reserved for user-triggered writes or client-only actions.

### How do I install Nuxt4 Patterns Skill?

npx skills add https://github.com/affaan-m/ECC --skill nuxt4-patterns

## Machine access

- [Sitemap](https://skillselion.com/sitemap.xml)
- [llms.txt](https://skillselion.com/llms.txt)
- [llms-full.txt](https://skillselion.com/llms-full.txt)
- [Developer resources](https://skillselion.com/developers)
- [OpenAPI spec](https://skillselion.com/openapi.json)
- [MCP handshake](https://skillselion.com/.well-known/mcp)
- [API catalog](https://skillselion.com/.well-known/api-catalog)
- [AI catalog](https://skillselion.com/.well-known/ai-catalog.json)
- [Pricing](https://skillselion.com/pricing.md)
- [Auth](https://skillselion.com/auth.md)
- [AGENTS.md](https://skillselion.com/AGENTS.md)
- [Contact](https://skillselion.com/contact)
- [Home](https://skillselion.com/)
