Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply 62 React and Next.js performance optimization rules from Vercel Engineering
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: vercel-react-best-practices3description: React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.4license: MIT5metadata:6author: vercel7version: "1.0.0"8---910# Vercel React Best Practices1112Comprehensive 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.1314## When to Apply1516Reference these guidelines when:17- Writing new React components or Next.js pages18- Implementing data fetching (client or server-side)19- Reviewing code for performance issues20- Refactoring existing React/Next.js code21- Optimizing bundle size or load times2223## Rule Categories by Priority2425| Priority | Category | Impact | Prefix |26|----------|----------|--------|--------|27| 1 | Eliminating Waterfalls | CRITICAL | `async-` |28| 2 | Bundle Size Optimization | CRITICAL | `bundle-` |29| 3 | Server-Side Performance | HIGH | `server-` |30| 4 | Client-Side Data Fetching | MEDIUM-HIGH | `client-` |31| 5 | Re-render Optimization | MEDIUM | `rerender-` |32| 6 | Rendering Performance | MEDIUM | `rendering-` |33| 7 | JavaScript Performance | LOW-MEDIUM | `js-` |34| 8 | Advanced Patterns | LOW | `advanced-` |3536## Quick Reference3738### 1. Eliminating Waterfalls (CRITICAL)3940- `async-cheap-condition-before-await` - Check cheap sync conditions before awaiting flags or remote values41- `async-defer-await` - Move await into branches where actually used42- `async-parallel` - Use Promise.all() for independent operations43- `async-dependencies` - Use better-all for partial dependencies44- `async-api-routes` - Start promises early, await late in API routes45- `async-suspense-boundaries` - Use Suspense to stream content4647### 2. Bundle Size Optimization (CRITICAL)4849- `bundle-barrel-imports` - Import directly, avoid barrel files50- `bundle-analyzable-paths` - Prefer statically analyzable import and file-system paths to avoid broad bundles and traces51- `bundle-dynamic-imports` - Use next/dynamic for heavy components52- `bundle-defer-third-party` - Load analytics/logging after hydration53- `bundle-conditional` - Load modules only when feature is activated54- `bundle-preload` - Preload on hover/focus for perceived speed5556### 3. Server-Side Performance (HIGH)5758- `server-auth-actions` - Authenticate server actions like API routes59- `server-cache-react` - Use React.cache() for per-request deduplication60- `server-cache-lru` - Use LRU cache for cross-request caching61- `server-dedup-props` - Avoid duplicate serialization in RSC props62- `server-hoist-static-io` - Hoist static I/O (fonts, logos) to module level63- `server-no-shared-module-state` - Avoid module-level mutable request state in RSC/SSR64- `server-serialization` - Minimize data passed to client components65- `server-parallel-fetching` - Restructure components to parallelize fetches66- `server-parallel-nested-fetching` - Chain nested fetches per item in Promise.all67- `server-after-nonblocking` - Use after() for non-blocking operations6869### 4. Client-Side Data Fetching (MEDIUM-HIGH)7071- `client-swr-dedup` - Use SWR for automatic request deduplication72- `client-event-listeners` - Deduplicate global event listeners73- `client-passive-event-listeners` - Use passive listeners for scroll74- `client-localstorage-schema` - Version and minimize localStorage data7576### 5. Re-render Optimization (MEDIUM)7778- `rerender-defer-reads` - Don't subscribe to state only used in callbacks79- `rerender-memo` - Extract expensive work into memoized components80- `rerender-memo-with-default-value` - Hoist default non-primitive props81- `rerender-dependencies` - Use primitive dependencies in effects82- `rerender-derived-state` - Subscribe to derived booleans, not raw values83- `rerender-derived-state-no-effect` - Derive state during render, not effects84- `rerender-functional-setstate` - Use functional setState for stable callbacks85- `rerender-lazy-state-init` - Pass function to useState for expensive values86- `rerender-simple-expression-in-memo` - Avoid memo for simple primitives87- `rerender-split-combined-hooks` - Split hooks with independent dependencies88- `rerender-move-effect-to-event` - Put interaction logic in event handlers89- `rerender-transitions` - Use startTransition for non-urgent updates90- `rerender-use-deferred-value` - Defer expensive renders to keep input responsive91- `rerender-use-ref-transient-values` - Use refs for transient frequent values92- `rerender-no-inline-components` - Don't define components inside components9394### 6. Rendering Performance (MEDIUM)9596- `rendering-animate-svg-wrapper` - Animate div wrapper, not SVG element97- `rendering-content-visibility` - Use content-visibility for long lists98- `rendering-hoist-jsx` - Extract static JSX outside components99- `rendering-svg-precision` - Reduce SVG coordinate precision100- `rendering-hydration-no-flicker` - Use inline script for client-only data101- `rendering-hydration-suppress-warning` - Suppress expected mismatches102- `rendering-activity` - Use Activity component for show/hide103- `rendering-conditional-render` - Use ternary, not && for conditionals104- `rendering-usetransition-loading` - Prefer useTransition for loading state105- `rendering-resource-hints` - Use React DOM resource hints for preloading106- `rendering-script-defer-async` - Use defer or async on script tags107108### 7. JavaScript Performance (LOW-MEDIUM)109110- `js-batch-dom-css` - Group CSS changes via classes or cssText111- `js-index-maps` - Build Map for repeated lookups112- `js-cache-property-access` - Cache object properties in loops113- `js-cache-function-results` - Cache function results in module-level Map114- `js-cache-storage` - Cache localStorage/sessionStorage reads115- `js-combine-iterations` - Combine multiple filter/map into one loop116- `js-length-check-first` - Check array length before expensive comparison117- `js-early-exit` - Return early from functions118- `js-hoist-regexp` - Hoist RegExp creation outside loops119- `js-min-max-loop` - Use loop for min/max instead of sort120- `js-set-map-lookups` - Use Set/Map for O(1) lookups121- `js-tosorted-immutable` - Use toSorted() for immutability122- `js-flatmap-filter` - Use flatMap to map and filter in one pass123- `js-request-idle-callback` - Defer non-critical work to browser idle time124125### 8. Advanced Patterns (LOW)126127- `advanced-effect-event-deps` - Don't put `useEffectEvent` results in effect deps128- `advanced-event-handler-refs` - Store event handlers in refs129- `advanced-init-once` - Initialize app once per app load130- `advanced-use-latest` - useLatest for stable callback refs131132## How to Use133134Read individual rule files for detailed explanations and code examples:135136```137rules/async-parallel.md138rules/bundle-barrel-imports.md139```140141Each rule file contains:142- Brief explanation of why it matters143- Incorrect code example with explanation144- Correct code example with explanation145- Additional context and references146147## Full Compiled Document148149For the complete guide with all rules expanded: `AGENTS.md`150