Vercel react best practices skill
React and Next.js performance optimization guidelines from Vercel Engineering.
by CloudAI-X·MIT license·★ 1,416 Stars on the repo·GitHub ↗
Use now
npx degit CloudAI-X/claude-workflow-v2/skills/vercel-react-best-practices#main ~/.claude/skills/vercel-react-best-practicesChecked ·commit main
Files of Vercel react best practices
SKILL.md
Show the full text119 lines
Vercel React Best Practices
When to Load
- Trigger: React or Next.js development, component writing, data fetching patterns, bundle optimization
- Skip: Project does not use React or Next.js
Comprehensive performance optimization guide for React and Next.js applications, maintained by Vercel. Contains 47 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
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Eliminating Waterfalls | CRITICAL | async- |
| 2 | Bundle Size Optimization | CRITICAL | bundle- |
| 3 | Server-Side Performance | HIGH | server- |
| 4 | Client-Side Data Fetching | MEDIUM-HIGH | client- |
| 5 | Re-render Optimization | MEDIUM | rerender- |
| 6 | Rendering Performance | MEDIUM | rendering- |
| 7 | JavaScript Performance | LOW-MEDIUM | js- |
| 8 | Advanced Patterns | LOW | advanced- |
Quick Reference
1. Eliminating Waterfalls (CRITICAL)
async-defer-await- Move await into branches where actually usedasync-parallel- Use Promise.all() for independent operationsasync-dependencies- Use better-all for partial dependenciesasync-api-routes- Start promises early, await late in API routesasync-suspense-boundaries- Use Suspense to stream content
2. Bundle Size Optimization (CRITICAL)
bundle-barrel-imports- Import directly, avoid barrel filesbundle-dynamic-imports- Use next/dynamic for heavy componentsbundle-defer-third-party- Load analytics/logging after hydrationbundle-conditional- Load modules only when feature is activatedbundle-preload- Preload on hover/focus for perceived speed
3. Server-Side Performance (HIGH)
server-cache-react- Use React.cache() for per-request deduplicationserver-cache-lru- Use LRU cache for cross-request cachingserver-serialization- Minimize data passed to client componentsserver-parallel-fetching- Restructure components to parallelize fetchesserver-after-nonblocking- Use after() for non-blocking operations
4. Client-Side Data Fetching (MEDIUM-HIGH)
client-swr-dedup- Use SWR for automatic request deduplicationclient-event-listeners- Deduplicate global event listeners
5. Re-render Optimization (MEDIUM)
rerender-defer-reads- Don't subscribe to state only used in callbacksrerender-memo- Extract expensive work into memoized componentsrerender-dependencies- Use primitive dependencies in effectsrerender-derived-state- Subscribe to derived booleans, not raw valuesrerender-functional-setstate- Use functional setState for stable callbacksrerender-lazy-state-init- Pass function to useState for expensive valuesrerender-transitions- Use startTransition for non-urgent updates
6. Rendering Performance (MEDIUM)
rendering-animate-svg-wrapper- Animate div wrapper, not SVG elementrendering-content-visibility- Use content-visibility for long listsrendering-hoist-jsx- Extract static JSX outside componentsrendering-svg-precision- Reduce SVG coordinate precisionrendering-hydration-no-flicker- Use inline script for client-only datarendering-activity- Use Activity component for show/hiderendering-conditional-render- Use ternary, not && for conditionals
7. JavaScript Performance (LOW-MEDIUM)
js-batch-dom-css- Group CSS changes via classes or cssTextjs-index-maps- Build Map for repeated lookupsjs-cache-property-access- Cache object properties in loopsjs-cache-function-results- Cache function results in module-level Mapjs-cache-storage- Cache localStorage/sessionStorage readsjs-combine-iterations- Combine multiple filter/map into one loopjs-length-check-first- Check array length before expensive comparisonjs-early-exit- Return early from functionsjs-hoist-regexp- Hoist RegExp creation outside loopsjs-min-max-loop- Use loop for min/max instead of sortjs-set-map-lookups- Use Set/Map for O(1) lookupsjs-tosorted-immutable- Use toSorted() for immutability
8. Advanced Patterns (LOW)
advanced-event-handler-refs- Store event handlers in refsadvanced-use-latest- useLatest for stable callback refs
Full Compiled Document
For the complete guide with all rules expanded and detailed code examples, see AGENTS.md.
Each rule contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
| 1 | |
| 2 | name vercel-react-best-practices |
| 3 | description 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. |
| 4 | |
| 5 | |
| 6 | # Vercel React Best Practices |
| 7 | |
| 8 | ### When to Load |
| 9 | |
| 10 | **Trigger**: React or Next.js development, component writing, data fetching patterns, bundle optimization |
| 11 | **Skip**: Project does not use React or Next.js |
| 12 | |
| 13 | Comprehensive performance optimization guide for React and Next.js applications, maintained by Vercel. Contains 47 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation. |
| 14 | |
| 15 | ## When to Apply |
| 16 | |
| 17 | Reference these guidelines when: |
| 18 | |
| 19 | Writing new React components or Next.js pages |
| 20 | Implementing data fetching (client or server-side) |
| 21 | Reviewing code for performance issues |
| 22 | Refactoring existing React/Next.js code |
| 23 | Optimizing bundle size or load times |
| 24 | |
| 25 | ## Rule Categories by Priority |
| 26 | |
| 27 | | Priority | Category | Impact | Prefix | |
| 28 | | -------- | ------------------------- | ----------- | ------------ | |
| 29 | | 1 | Eliminating Waterfalls | CRITICAL | `async-` | |
| 30 | | 2 | Bundle Size Optimization | CRITICAL | `bundle-` | |
| 31 | | 3 | Server-Side Performance | HIGH | `server-` | |
| 32 | | 4 | Client-Side Data Fetching | MEDIUM-HIGH | `client-` | |
| 33 | | 5 | Re-render Optimization | MEDIUM | `rerender-` | |
| 34 | | 6 | Rendering Performance | MEDIUM | `rendering-` | |
| 35 | | 7 | JavaScript Performance | LOW-MEDIUM | `js-` | |
| 36 | | 8 | Advanced Patterns | LOW | `advanced-` | |
| 37 | |
| 38 | ## Quick Reference |
| 39 | |
| 40 | ### 1. Eliminating Waterfalls (CRITICAL) |
| 41 | |
| 42 | `async-defer-await` - Move await into branches where actually used |
| 43 | `async-parallel` - Use Promise.all() for independent operations |
| 44 | `async-dependencies` - Use better-all for partial dependencies |
| 45 | `async-api-routes` - Start promises early, await late in API routes |
| 46 | `async-suspense-boundaries` - Use Suspense to stream content |
| 47 | |
| 48 | ### 2. Bundle Size Optimization (CRITICAL) |
| 49 | |
| 50 | `bundle-barrel-imports` - Import directly, avoid barrel files |
| 51 | `bundle-dynamic-imports` - Use next/dynamic for heavy components |
| 52 | `bundle-defer-third-party` - Load analytics/logging after hydration |
| 53 | `bundle-conditional` - Load modules only when feature is activated |
| 54 | `bundle-preload` - Preload on hover/focus for perceived speed |
| 55 | |
| 56 | ### 3. Server-Side Performance (HIGH) |
| 57 | |
| 58 | `server-cache-react` - Use React.cache() for per-request deduplication |
| 59 | `server-cache-lru` - Use LRU cache for cross-request caching |
| 60 | `server-serialization` - Minimize data passed to client components |
| 61 | `server-parallel-fetching` - Restructure components to parallelize fetches |
| 62 | `server-after-nonblocking` - Use after() for non-blocking operations |
| 63 | |
| 64 | ### 4. Client-Side Data Fetching (MEDIUM-HIGH) |
| 65 | |
| 66 | `client-swr-dedup` - Use SWR for automatic request deduplication |
| 67 | `client-event-listeners` - Deduplicate global event listeners |
| 68 | |
| 69 | ### 5. Re-render Optimization (MEDIUM) |
| 70 | |
| 71 | `rerender-defer-reads` - Don't subscribe to state only used in callbacks |
| 72 | `rerender-memo` - Extract expensive work into memoized components |
| 73 | `rerender-dependencies` - Use primitive dependencies in effects |
| 74 | `rerender-derived-state` - Subscribe to derived booleans, not raw values |
| 75 | `rerender-functional-setstate` - Use functional setState for stable callbacks |
| 76 | `rerender-lazy-state-init` - Pass function to useState for expensive values |
| 77 | `rerender-transitions` - Use startTransition for non-urgent updates |
| 78 | |
| 79 | ### 6. Rendering Performance (MEDIUM) |
| 80 | |
| 81 | `rendering-animate-svg-wrapper` - Animate div wrapper, not SVG element |
| 82 | `rendering-content-visibility` - Use content-visibility for long lists |
| 83 | `rendering-hoist-jsx` - Extract static JSX outside components |
| 84 | `rendering-svg-precision` - Reduce SVG coordinate precision |
| 85 | `rendering-hydration-no-flicker` - Use inline script for client-only data |
| 86 | `rendering-activity` - Use Activity component for show/hide |
| 87 | `rendering-conditional-render` - Use ternary, not && for conditionals |
| 88 | |
| 89 | ### 7. JavaScript Performance (LOW-MEDIUM) |
| 90 | |
| 91 | `js-batch-dom-css` - Group CSS changes via classes or cssText |
| 92 | `js-index-maps` - Build Map for repeated lookups |
| 93 | `js-cache-property-access` - Cache object properties in loops |
| 94 | `js-cache-function-results` - Cache function results in module-level Map |
| 95 | `js-cache-storage` - Cache localStorage/sessionStorage reads |
| 96 | `js-combine-iterations` - Combine multiple filter/map into one loop |
| 97 | `js-length-check-first` - Check array length before expensive comparison |
| 98 | `js-early-exit` - Return early from functions |
| 99 | `js-hoist-regexp` - Hoist RegExp creation outside loops |
| 100 | `js-min-max-loop` - Use loop for min/max instead of sort |
| 101 | `js-set-map-lookups` - Use Set/Map for O(1) lookups |
| 102 | `js-tosorted-immutable` - Use toSorted() for immutability |
| 103 | |
| 104 | ### 8. Advanced Patterns (LOW) |
| 105 | |
| 106 | `advanced-event-handler-refs` - Store event handlers in refs |
| 107 | `advanced-use-latest` - useLatest for stable callback refs |
| 108 | |
| 109 | ## Full Compiled Document |
| 110 | |
| 111 | For the complete guide with all rules expanded and detailed code examples, see [AGENTS.md]. |
| 112 | |
| 113 | Each rule contains: |
| 114 | |
| 115 | Brief explanation of why it matters |
| 116 | Incorrect code example with explanation |
| 117 | Correct code example with explanation |
| 118 | Additional context and references |
| 119 |
Discussion
Alternatives
Browse more free Claude skills or everything in Development.