Communitygithub.com

nuxt4-patterns

Nuxt 4 앱에서 수화 안전성, 성능, 라우트 규칙, 지연 로딩, 그리고 useFetch와 useAsyncData를 이용한 SSR-안전 데이터 페칭을 위한 패턴입니다. Nuxt 4 앱을 빌드하거나 리뷰할 때, 또는 수화 불일치와 SSR-안전 데이터 페칭을 디버깅할 때 사용하세요.

nuxt4-patterns란 무엇인가요?

이 스킬은 SSR, 하이브리드 렌더링, 라우트 규칙, 페이지 수준 데이터 페칭을 사용하는 Nuxt 4 앱을 개발하거나 디버깅할 때 적용됩니다. 주로 수화 불일치(Hydration Mismatch) 문제 해결, 라우트별 렌더링 전략(prerender, SWR, ISR 등) 설정, 성능 최적화(지연 로딩, 지연 수화, 페이로드 크기 축소)를 도와줍니다. 핵심 기능으로는 `useFetch`, `useAsyncData`를 통한 SSR-안전 데이터 페칭 패턴 제시, `nuxt.config.ts`의 `routeRules`를 통한 라우트별 렌더링/캐싱 전략 설명, 그리고 `Lazy` 접두사 컴포넌트나 `defineLazyHydrationComponent`를 활용한 성능 최적화 방법을 포함합니다. 이 스킬은 Claude Code, Cursor, Codex 등 다양한 AI 에이전트 환경에서 Nuxt 4 앱의 SSR 관련 문제를 진단하고 해결하는 데 유용하며, 특히 첫 번째 SSR 렌더와 클라이언트 수화 결과가 동일한지 확인하는 리뷰 체크리스트를 제공합니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/nuxt4-patterns

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

Nuxt 4 패턴

SSR, 하이브리드 렌더링, 라우트 규칙 또는 페이지 수준 데이터 페칭을 사용하는 Nuxt 4 앱을 빌드하거나 디버깅할 때 사용합니다.

활성화 시점

  • 서버 HTML과 클라이언트 상태 간의 수화 불일치(Hydration Mismatch)
  • prerender, SWR, ISR 또는 클라이언트 전용 섹션과 같은 라우트 수준 렌더링 결정
  • 지연 로딩, 지연 수화 또는 페이로드 크기 관련 성능 작업
  • useFetch, useAsyncData 또는 $fetch를 사용한 페이지 또는 컴포넌트 데이터 페칭
  • 라우트 파라미터, 미들웨어 또는 SSR/클라이언트 차이와 관련된 Nuxt 라우팅 문제

수화 안전성

  • 첫 번째 렌더는 결정적(Deterministic)이어야 합니다. Date.now(), Math.random(), 브라우저 전용 API 또는 storage 읽기를 SSR 렌더링된 템플릿 상태에 직접 넣지 마십시오.
  • 서버가 동일한 마크업을 생성할 수 없는 경우 브라우저 전용 로직을 onMounted(), import.meta.client, ClientOnly 또는 .client.vue 컴포넌트 뒤로 이동하십시오.
  • Nuxt의 useRoute() 컴포저블(Composable)을 사용하고, vue-router의 것은 사용하지 마십시오.
  • SSR 렌더링된 마크업을 구동하기 위해 route.fullPath를 사용하지 마십시오. URL 프래그먼트는 클라이언트 전용이므로 수화 불일치를 일으킬 수 있습니다.
  • ssr: false는 진정한 브라우저 전용 영역을 위한 탈출구로 취급하고, 불일치에 대한 기본 수정으로 사용하지 마십시오.

데이터 페칭

  • 페이지와 컴포넌트에서 SSR-안전 API 읽기를 위해 await useFetch()를 선호하십시오. 서버에서 가져온 데이터를 Nuxt 페이로드에 전달하고 수화 시 두 번째 페치를 방지합니다.
  • 페처(Fetcher)가 단순한 $fetch() 호출이 아닌 경우, 사용자 정의 키가 필요한 경우, 또는 여러 비동기 소스를 구성해야 하는 경우 useAsyncData()를 사용하십시오.
  • 캐시 재사용과 예측 가능한 새로고침 동작을 위해 useAsyncData()에 안정적인 키를 제공하십시오.
  • useAsyncData() 핸들러를 부수 효과(Side-effect) 없이 유지하십시오. 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 렌더와 수화된 클라이언트 렌더가 동일한 마크업을 생성합니다.
  • 페이지 데이터는 최상위 $fetch가 아닌 useFetch 또는 useAsyncData를 사용합니다.
  • 중요하지 않은 데이터는 지연되고 명시적인 로딩 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/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

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.

관련 스킬