Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
affaan-m avatar

Nuxt4 Patterns

  • 1.4k installs
  • 238k repo stars
  • Updated August 5, 2026
  • affaan-m/ecc

This is a copy of nuxt4-patterns by affaan-m - installs and ranking accrue to the original listing.

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.

About

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.

  • 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

Nuxt4 Patterns by the numbers

  • 1,364 all-time installs (skills.sh)
  • +86 installs in the week ending Aug 4, 2026 (Skillselion tracking)
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/affaan-m/ecc --skill nuxt4-patterns

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1.4k
repo stars238k
Last updatedAugust 5, 2026
Repositoryaffaan-m/ecc

How do you fix Nuxt 4 hydration mismatches?

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

Who is it for?

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

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

When should I use this skill?

A Nuxt 4 app shows hydration mismatches, route-level prerender or SWR decisions, or page data fetching with useFetch, useAsyncData, or $fetch.

What you get

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

  • Hydration-safe component patterns
  • routeRules configuration
  • SSR data-fetching refactor

By the numbers

  • Includes a 5-item Nuxt 4 review checklist for SSR and fetch patterns
  • Documents 5 routeRules strategies: prerender, swr, isr, ssr false, and cache

Files

SKILL.mdMarkdownGitHub ↗

Nuxt 4パターン

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

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

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

ハイドレーション安全性

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

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には遅延ハイドレーションを使用する。
<template>
  <LazyRecommendations v-if="showRecommendations" />
  <LazyProductGallery hydrate-on-visible />
</template>
  • カスタム戦略には、可視性またはアイドル戦略でdefineLazyHydrationComponent()を使用する。
  • Nuxtの遅延ハイドレーションは単一ファイルコンポーネントで機能する。遅延ハイドレーションコンポーネントに新しいpropsを渡すと、すぐにハイドレーションがトリガーされる。
  • Nuxtがルートコンポーネントと生成されたペイロードをプリフェッチできるよう、内部ナビゲーションにはNuxtLinkを使用する。

レビューチェックリスト

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

Related skills

How it compares

Choose nuxt4-patterns over generic Vue SSR advice when the stack is Nuxt 4-specific—routeRules, useFetch payload hydration, and Lazy hydration APIs.

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.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.