vercel-labs/agent-skills

vercel-react-best-practices

React と Next.js の性能に関わるコードを、影響の大きい項目から確認するための Vercel の指針です。

ソースを見る

詳しい説明

この Skill は、React や Next.js の性能レビューをどこから始めるか判断するための資料です。固定した版では 70 のルールを八つの分野に整理し、リクエストの待ち合わせによる遅延とバンドルサイズを最優先にしています。続いてサーバー処理、クライアントでのデータ取得、再レンダー、描画、JavaScript、応用パターンを確認できます。細かい書き換えに入る前に、依存関係や読み込み処理の負担を調べる順序が分かります。

SKILL.md は索引です。詳しい説明と変更前後のコード例は rules/ の各ファイルにあり、AGENTS.md には展開されたガイドがまとめられています。例えば async-parallel は独立した処理の並列化、bundle-barrel-imports はインポート構造を扱います。短い要約だけで変更せず、対象のコンポーネント、データ依存、認可の境界、利用中のフレームワークに照らして該当ルールを読むことが大切です。

用意するもの

  • React または Next.js のバージョン、対象ページやコンポーネントのファイル、確認したい課題。
  • 関連するデータ取得とインポートのコード。既存のバンドル分析や性能診断があれば併せて用意します。
  • 処理の依存順序、サーバーとクライアントの境界、ユーザー権限など、維持すべき動作。

得られるもの

  • 具体的なルールと影響区分に結び付いたレビューの提案。
  • 変更の適否を考えるためのコードパターンと個別ルールの例。
  • プロジェクト自身のビルド、動作確認、計測で検証する改善候補。

使い方

  1. 対象のページやコンポーネント、フレームワークの版、調べたい動作や読み込みの問題を特定します。
  2. リクエストの待ち合わせとバンドルサイズから確認し、対象コードに合う他の分野へ進みます。
  3. 該当するルールファイルか AGENTS.md の説明を開き、索引の一行だけで判断しません。
  4. 実際の依存関係、リクエストの範囲、認可、使用可能な API と提案を照合します。
  5. 自分のプロジェクトでコードを変更する場合は範囲を絞り、同じ条件で動作と診断結果を比較します。

制約と確認事項

  • 並列化する処理が本当に独立しており、データや認可に必要な順序を維持している。
  • インポートや遅延読み込みの変更がコンポーネントの実行場所に適している。
  • キャッシュがリクエスト間で可変状態を共有したり、別のユーザーのデータを混在させたりしない。
  • 選んだルールが使う React や Next.js の API をプロジェクトが利用できる。
  • 影響区分のラベルを実測値と混同せず、テストと計測で変更を評価している。

よくある質問

Next.js 専用ですか?

資料は React と Next.js を対象にしています。状態管理や再レンダー、JavaScript の項目は関連する React コードでも参考になりますが、サーバーアクションなど固有のパターンには対応する環境が必要です。全項目を必須の変更とせず、適用できるものを選びます。

SKILL.md だけをコピーすれば十分ですか?

入口の文書は個別ルールと AGENTS.md を参照しています。短い索引の背景にある説明やコード例も読めるよう、完全な Skill パッケージを助手から利用できる状態にします。

アプリの性能スコアも分かりますか?

パッケージにあるのは指針とコード例であり、対象アプリの計測結果ではありません。自分のビルドや診断ツールを使い、一貫した条件で変更前後を比較する必要があります。

この Skill を導入

Skills CLI を使い、検証済みの GitHub ソースから追加します。

npx skills add https://github.com/vercel-labs/agent-skills --skill vercel-react-best-practices

出典情報

リポジトリの原文

見出し、例、コード、表、リンク、参照画像を含む原文を表示しています。

Vercel React Best Practices

Comprehensive performance optimization guide for React and Next.js applications, maintained by Vercel. Contains 70 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.

When to Apply

Reference these guidelines when:

  • Writing new React components or Next.js pages
  • Implementing data fetching (client or server-side)
  • Reviewing code for performance issues
  • Refactoring existing React/Next.js code
  • Optimizing bundle size or load times

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Eliminating WaterfallsCRITICALasync-
2Bundle Size OptimizationCRITICALbundle-
3Server-Side PerformanceHIGHserver-
4Client-Side Data FetchingMEDIUM-HIGHclient-
5Re-render OptimizationMEDIUMrerender-
6Rendering PerformanceMEDIUMrendering-
7JavaScript PerformanceLOW-MEDIUMjs-
8Advanced PatternsLOWadvanced-

Quick Reference

1. Eliminating Waterfalls (CRITICAL)

  • async-cheap-condition-before-await - Check cheap sync conditions before awaiting flags or remote values
  • async-defer-await - Move await into branches where actually used
  • async-parallel - Use Promise.all() for independent operations
  • async-dependencies - Use better-all for partial dependencies
  • async-api-routes - Start promises early, await late in API routes
  • async-suspense-boundaries - Use Suspense to stream content

2. Bundle Size Optimization (CRITICAL)

  • bundle-barrel-imports - Import directly, avoid barrel files
  • bundle-analyzable-paths - Prefer statically analyzable import and file-system paths to avoid broad bundles and traces
  • bundle-dynamic-imports - Use next/dynamic for heavy components
  • bundle-defer-third-party - Load analytics/logging after hydration
  • bundle-conditional - Load modules only when feature is activated
  • bundle-preload - Preload on hover/focus for perceived speed

3. Server-Side Performance (HIGH)

  • server-auth-actions - Authenticate server actions like API routes
  • server-cache-react - Use React.cache() for per-request deduplication
  • server-cache-lru - Use LRU cache for cross-request caching
  • server-dedup-props - Avoid duplicate serialization in RSC props
  • server-hoist-static-io - Hoist static I/O (fonts, logos) to module level
  • server-no-shared-module-state - Avoid module-level mutable request state in RSC/SSR
  • server-serialization - Minimize data passed to client components
  • server-parallel-fetching - Restructure components to parallelize fetches
  • server-parallel-nested-fetching - Chain nested fetches per item in Promise.all
  • server-after-nonblocking - Use after() for non-blocking operations

4. Client-Side Data Fetching (MEDIUM-HIGH)

  • client-swr-dedup - Use SWR for automatic request deduplication
  • client-event-listeners - Deduplicate global event listeners
  • client-passive-event-listeners - Use passive listeners for scroll
  • client-localstorage-schema - Version and minimize localStorage data

5. Re-render Optimization (MEDIUM)

  • rerender-defer-reads - Don't subscribe to state only used in callbacks
  • rerender-memo - Extract expensive work into memoized components
  • rerender-memo-with-default-value - Hoist default non-primitive props
  • rerender-dependencies - Use primitive dependencies in effects
  • rerender-derived-state - Subscribe to derived booleans, not raw values
  • rerender-derived-state-no-effect - Derive state during render, not effects
  • rerender-functional-setstate - Use functional setState for stable callbacks
  • rerender-lazy-state-init - Pass function to useState for expensive values
  • rerender-simple-expression-in-memo - Avoid memo for simple primitives
  • rerender-split-combined-hooks - Split hooks with independent dependencies
  • rerender-move-effect-to-event - Put interaction logic in event handlers
  • rerender-transitions - Use startTransition for non-urgent updates
  • rerender-use-deferred-value - Defer expensive renders to keep input responsive
  • rerender-use-ref-transient-values - Use refs for transient frequent values
  • rerender-no-inline-components - Don't define components inside components

6. Rendering Performance (MEDIUM)

  • rendering-animate-svg-wrapper - Animate div wrapper, not SVG element
  • rendering-content-visibility - Use content-visibility for long lists
  • rendering-hoist-jsx - Extract static JSX outside components
  • rendering-svg-precision - Reduce SVG coordinate precision
  • rendering-hydration-no-flicker - Use inline script for client-only data
  • rendering-hydration-suppress-warning - Suppress expected mismatches
  • rendering-activity - Use Activity component for show/hide
  • rendering-conditional-render - Use ternary, not && for conditionals
  • rendering-usetransition-loading - Prefer useTransition for loading state
  • rendering-resource-hints - Use React DOM resource hints for preloading
  • rendering-script-defer-async - Use defer or async on script tags

7. JavaScript Performance (LOW-MEDIUM)

  • js-batch-dom-css - Group CSS changes via classes or cssText
  • js-index-maps - Build Map for repeated lookups
  • js-cache-property-access - Cache object properties in loops
  • js-cache-function-results - Cache function results in module-level Map
  • js-cache-storage - Cache localStorage/sessionStorage reads
  • js-combine-iterations - Combine multiple filter/map into one loop
  • js-length-check-first - Check array length before expensive comparison
  • js-early-exit - Return early from functions
  • js-hoist-regexp - Hoist RegExp creation outside loops
  • js-min-max-loop - Use loop for min/max instead of sort
  • js-set-map-lookups - Use Set/Map for O(1) lookups
  • js-tosorted-immutable - Use toSorted() for immutability
  • js-flatmap-filter - Use flatMap to map and filter in one pass
  • js-request-idle-callback - Defer non-critical work to browser idle time

8. Advanced Patterns (LOW)

  • advanced-effect-event-deps - Don't put useEffectEvent results in effect deps
  • advanced-event-handler-refs - Store event handlers in refs
  • advanced-init-once - Initialize app once per app load
  • advanced-use-latest - useLatest for stable callback refs

How to Use

Read individual rule files for detailed explanations and code examples:

rules/async-parallel.md
rules/bundle-barrel-imports.md

Each rule file contains:

  • Brief explanation of why it matters
  • Incorrect code example with explanation
  • Correct code example with explanation
  • Additional context and references

Full Compiled Document

For the complete guide with all rules expanded: AGENTS.md

タスクに関連する項目

同じリポジトリから

関連する Skills

すべての Skills
vercel-labs
公式

web-design-guidelines

Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".

累計インストール
88.9万
GitHub Stars
3.5万
更新日
11月20日
vercel-labs
公式

vercel-composition-patterns

React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component libraries, or designing reusable APIs. Triggers on tasks involving compound components, render props, context providers, or component architecture. Includes React 19 API changes.

累計インストール
46.6万
GitHub Stars
3.5万
更新日
11月20日
vercel-labs
公式

vercel-react-native-skills

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

累計インストール
28.5万
GitHub Stars
3.5万
更新日
11月20日
vercel-labs
公式

vercel-react-view-transitions

Guide for implementing smooth, native-feeling animations using React's View Transition API ( component, addTransitionType, and CSS view transition pseudo-elements). Use this skill whenever the user wants to add page transitions, animate route changes, create shared element animations, animate enter/exit of components, animate list reorder, implement directional (forward/back) navigation animations, or integrate view transitions in Next.js. Also use when the user mentions view transitions, startV

累計インストール
19.9万
GitHub Stars
3.5万
更新日
11月20日