SKILL.md
SKILL.mdBrowse 47 files
1,299 tokens
5,316 bytes
Token encoding: o200k_base
Snapshot 6bc4529
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:6 author: vercel7 version: "1.0.0"8---9 10# Vercel React Best Practices11 12Comprehensive performance optimization guide for React and Next.js applications, maintained by Vercel. Contains 45 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.13 14## When to Apply15 16Reference 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 times22 23## Rule Categories by Priority24 25| 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-` |35 36## Quick Reference37 38### 1. Eliminating Waterfalls (CRITICAL)39 40- `async-defer-await` - Move await into branches where actually used41- `async-parallel` - Use Promise.all() for independent operations42- `async-dependencies` - Use better-all for partial dependencies43- `async-api-routes` - Start promises early, await late in API routes44- `async-suspense-boundaries` - Use Suspense to stream content45 46### 2. Bundle Size Optimization (CRITICAL)47 48- `bundle-barrel-imports` - Import directly, avoid barrel files49- `bundle-dynamic-imports` - Use next/dynamic for heavy components50- `bundle-defer-third-party` - Load analytics/logging after hydration51- `bundle-conditional` - Load modules only when feature is activated52- `bundle-preload` - Preload on hover/focus for perceived speed53 54### 3. Server-Side Performance (HIGH)55 56- `server-cache-react` - Use React.cache() for per-request deduplication57- `server-cache-lru` - Use LRU cache for cross-request caching58- `server-serialization` - Minimize data passed to client components59- `server-parallel-fetching` - Restructure components to parallelize fetches60- `server-after-nonblocking` - Use after() for non-blocking operations61 62### 4. Client-Side Data Fetching (MEDIUM-HIGH)63 64- `client-swr-dedup` - Use SWR for automatic request deduplication65- `client-event-listeners` - Deduplicate global event listeners66 67### 5. Re-render Optimization (MEDIUM)68 69- `rerender-defer-reads` - Don't subscribe to state only used in callbacks70- `rerender-memo` - Extract expensive work into memoized components71- `rerender-dependencies` - Use primitive dependencies in effects72- `rerender-derived-state` - Subscribe to derived booleans, not raw values73- `rerender-functional-setstate` - Use functional setState for stable callbacks74- `rerender-lazy-state-init` - Pass function to useState for expensive values75- `rerender-transitions` - Use startTransition for non-urgent updates76 77### 6. Rendering Performance (MEDIUM)78 79- `rendering-animate-svg-wrapper` - Animate div wrapper, not SVG element80- `rendering-content-visibility` - Use content-visibility for long lists81- `rendering-hoist-jsx` - Extract static JSX outside components82- `rendering-svg-precision` - Reduce SVG coordinate precision83- `rendering-hydration-no-flicker` - Use inline script for client-only data84- `rendering-activity` - Use Activity component for show/hide85- `rendering-conditional-render` - Use ternary, not && for conditionals86 87### 7. JavaScript Performance (LOW-MEDIUM)88 89- `js-batch-dom-css` - Group CSS changes via classes or cssText90- `js-index-maps` - Build Map for repeated lookups91- `js-cache-property-access` - Cache object properties in loops92- `js-cache-function-results` - Cache function results in module-level Map93- `js-cache-storage` - Cache localStorage/sessionStorage reads94- `js-combine-iterations` - Combine multiple filter/map into one loop95- `js-length-check-first` - Check array length before expensive comparison96- `js-early-exit` - Return early from functions97- `js-hoist-regexp` - Hoist RegExp creation outside loops98- `js-min-max-loop` - Use loop for min/max instead of sort99- `js-set-map-lookups` - Use Set/Map for O(1) lookups100- `js-tosorted-immutable` - Use toSorted() for immutability101 102### 8. Advanced Patterns (LOW)103 104- `advanced-event-handler-refs` - Store event handlers in refs105- `advanced-use-latest` - useLatest for stable callback refs106 107## How to Use108 109Read individual rule files for detailed explanations and code examples:110 111```112rules/async-parallel.md113rules/bundle-barrel-imports.md114rules/_sections.md115```116 117Each rule file contains:118- Brief explanation of why it matters119- Incorrect code example with explanation120- Correct code example with explanation121- Additional context and references122 123## Full Compiled Document124 125For the complete guide with all rules expanded: `AGENTS.md`126 Discovery context
Discovered by repository scan. No exact path reference found in the snapshot’s root AGENTS.md.