$npx -y skills add jarrodwatts/claude-code-config --skill vercel-react-best-practicesReact 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,
| 1 | # Vercel React Best Practices |
| 2 | |
| 3 | Comprehensive 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. |
| 4 | |
| 5 | ## When to Apply |
| 6 | |
| 7 | Reference these guidelines when: |
| 8 | - Writing new React components or Next.js pages |
| 9 | - Implementing data fetching (client or server-side) |
| 10 | - Reviewing code for performance issues |
| 11 | - Refactoring existing React/Next.js code |
| 12 | - Optimizing bundle size or load times |
| 13 | |
| 14 | ## Rule Categories by Priority |
| 15 | |
| 16 | | Priority | Category | Impact | Prefix | |
| 17 | |----------|----------|--------|--------| |
| 18 | | 1 | Eliminating Waterfalls | CRITICAL | `async-` | |
| 19 | | 2 | Bundle Size Optimization | CRITICAL | `bundle-` | |
| 20 | | 3 | Server-Side Performance | HIGH | `server-` | |
| 21 | | 4 | Client-Side Data Fetching | MEDIUM-HIGH | `client-` | |
| 22 | | 5 | Re-render Optimization | MEDIUM | `rerender-` | |
| 23 | | 6 | Rendering Performance | MEDIUM | `rendering-` | |
| 24 | | 7 | JavaScript Performance | LOW-MEDIUM | `js-` | |
| 25 | | 8 | Advanced Patterns | LOW | `advanced-` | |
| 26 | |
| 27 | ## Quick Reference |
| 28 | |
| 29 | ### 1. Eliminating Waterfalls (CRITICAL) |
| 30 | |
| 31 | - `async-defer-await` - Move await into branches where actually used |
| 32 | - `async-parallel` - Use Promise.all() for independent operations |
| 33 | - `async-dependencies` - Use better-all for partial dependencies |
| 34 | - `async-api-routes` - Start promises early, await late in API routes |
| 35 | - `async-suspense-boundaries` - Use Suspense to stream content |
| 36 | |
| 37 | ### 2. Bundle Size Optimization (CRITICAL) |
| 38 | |
| 39 | - `bundle-barrel-imports` - Import directly, avoid barrel files |
| 40 | - `bundle-dynamic-imports` - Use next/dynamic for heavy components |
| 41 | - `bundle-defer-third-party` - Load analytics/logging after hydration |
| 42 | - `bundle-conditional` - Load modules only when feature is activated |
| 43 | - `bundle-preload` - Preload on hover/focus for perceived speed |
| 44 | |
| 45 | ### 3. Server-Side Performance (HIGH) |
| 46 | |
| 47 | - `server-cache-react` - Use React.cache() for per-request deduplication |
| 48 | - `server-cache-lru` - Use LRU cache for cross-request caching |
| 49 | - `server-serialization` - Minimize data passed to client components |
| 50 | - `server-parallel-fetching` - Restructure components to parallelize fetches |
| 51 | - `server-after-nonblocking` - Use after() for non-blocking operations |
| 52 | |
| 53 | ### 4. Client-Side Data Fetching (MEDIUM-HIGH) |
| 54 | |
| 55 | - `client-swr-dedup` - Use SWR for automatic request deduplication |
| 56 | - `client-event-listeners` - Deduplicate global event listeners |
| 57 | |
| 58 | ### 5. Re-render Optimization (MEDIUM) |
| 59 | |
| 60 | - `rerender-defer-reads` - Don't subscribe to state only used in callbacks |
| 61 | - `rerender-memo` - Extract expensive work into memoized components |
| 62 | - `rerender-dependencies` - Use primitive dependencies in effects |
| 63 | - `rerender-derived-state` - Subscribe to derived booleans, not raw values |
| 64 | - `rerender-functional-setstate` - Use functional setState for stable callbacks |
| 65 | - `rerender-lazy-state-init` - Pass function to useState for expensive values |
| 66 | - `rerender-transitions` - Use startTransition for non-urgent updates |
| 67 | |
| 68 | ### 6. Rendering Performance (MEDIUM) |
| 69 | |
| 70 | - `rendering-animate-svg-wrapper` - Animate div wrapper, not SVG element |
| 71 | - `rendering-content-visibility` - Use content-visibility for long lists |
| 72 | - `rendering-hoist-jsx` - Extract static JSX outside components |
| 73 | - `rendering-svg-precision` - Reduce SVG coordinate precision |
| 74 | - `rendering-hydration-no-flicker` - Use inline script for client-only data |
| 75 | - `rendering-activity` - Use Activity component for show/hide |
| 76 | - `rendering-conditional-render` - Use ternary, not && for conditionals |
| 77 | |
| 78 | ### 7. JavaScript Performance (LOW-MEDIUM) |
| 79 | |
| 80 | - `js-batch-dom-css` - Group CSS changes via classes or cssText |
| 81 | - `js-index-maps` - Build Map for repeated lookups |
| 82 | - `js-cache-property-access` - Cache object properties in loops |
| 83 | - `js-cache-function-results` - Cache function results in module-level Map |
| 84 | - `js-cache-storage` - Cache localStorage/sessionStorage reads |
| 85 | - `js-combine-iterations` - Combine multiple filter/map into one loop |
| 86 | - `js-length-check-first` - Check array length before expensive comparison |
| 87 | - `js-early-exit` - Return early from functions |
| 88 | - `js-hoist-regexp` - Hoist RegExp creation outside loops |
| 89 | - `js-min-max-loop` - Use loop for min/max instead of sort |
| 90 | - `js-set-map-lookups` - Use Set/Map for O(1) lookups |
| 91 | - `js-tosorted-immutable` - Use toSorted() for immutability |
| 92 | |
| 93 | ### 8. Advanced Patterns (LOW) |
| 94 | |
| 95 | - `advanced-event-handler-refs` - Store event handlers in refs |
| 96 | - `advanced-use-latest` - useLatest for stable callback refs |
| 97 | |
| 98 | ## How to Use |
| 99 | |
| 100 | Read individual rule files for detailed explanations and code examples: |
| 101 | |
| 102 | ``` |
| 103 | rules/async-parallel.md |
| 104 | rules/bundle-barrel-imports.md |
| 105 | rules/_sections.md |
| 106 | ``` |
| 107 | |
| 108 | Each rule fi |