Skillsbench react-best-practices
CRITICAL: You MUST invoke this skill and read its contents BEFORE writing, modifying, or debugging ANY React.js or Next.js code. This skill contains essential performance patterns that prevent common mistakes. Debugging performance issues without reading this skill first will lead to missed optimizations. Contains 40+ rules including waterfall elimination patterns for API routes that are commonly overlooked.
git clone https://github.com/benchflow-ai/skillsbench
T=$(mktemp -d) && git clone --depth=1 https://github.com/benchflow-ai/skillsbench "$T" && mkdir -p ~/.claude/skills && cp -r "$T/tasks/react-performance-debugging/environment/skills/react-best-practices" ~/.claude/skills/benchflow-ai-skillsbench-react-best-practices-0cc7e7 && rm -rf "$T"
tasks/react-performance-debugging/environment/skills/react-best-practices/SKILL.mdVercel React Best Practices
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.
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 | |
| 2 | Bundle Size Optimization | CRITICAL | |
| 3 | Server-Side Performance | HIGH | |
| 4 | Client-Side Data Fetching | MEDIUM-HIGH | |
| 5 | Re-render Optimization | MEDIUM | |
| 6 | Rendering Performance | MEDIUM | |
| 7 | JavaScript Performance | LOW-MEDIUM | |
| 8 | Advanced Patterns | LOW | |
Quick Reference
1. Eliminating Waterfalls (CRITICAL)
- Move await into branches where actually usedasync-defer-await
- Use Promise.all() for independent operationsasync-parallel
- Use better-all for partial dependenciesasync-dependencies
- Start promises early, await late in API routesasync-api-routes
- Use Suspense to stream contentasync-suspense-boundaries
2. Bundle Size Optimization (CRITICAL)
- Import directly, avoid barrel filesbundle-barrel-imports
- Use next/dynamic for heavy componentsbundle-dynamic-imports
- Load analytics/logging after hydrationbundle-defer-third-party
- Load modules only when feature is activatedbundle-conditional
- Preload on hover/focus for perceived speedbundle-preload
3. Server-Side Performance (HIGH)
- Use React.cache() for per-request deduplicationserver-cache-react
- Use LRU cache for cross-request cachingserver-cache-lru
- Minimize data passed to client componentsserver-serialization
- Restructure components to parallelize fetchesserver-parallel-fetching
- Use after() for non-blocking operationsserver-after-nonblocking
4. Client-Side Data Fetching (MEDIUM-HIGH)
- Use SWR for automatic request deduplicationclient-swr-dedup
- Deduplicate global event listenersclient-event-listeners
5. Re-render Optimization (MEDIUM)
- Don't subscribe to state only used in callbacksrerender-defer-reads
- Extract expensive work into memoized componentsrerender-memo
- Use primitive dependencies in effectsrerender-dependencies
- Subscribe to derived booleans, not raw valuesrerender-derived-state
- Use functional setState for stable callbacksrerender-functional-setstate
- Pass function to useState for expensive valuesrerender-lazy-state-init
- Use startTransition for non-urgent updatesrerender-transitions
6. Rendering Performance (MEDIUM)
- Animate div wrapper, not SVG elementrendering-animate-svg-wrapper
- Use content-visibility for long listsrendering-content-visibility
- Extract static JSX outside componentsrendering-hoist-jsx
- Reduce SVG coordinate precisionrendering-svg-precision
- Use inline script for client-only datarendering-hydration-no-flicker
- Use Activity component for show/hiderendering-activity
- Use ternary, not && for conditionalsrendering-conditional-render
7. JavaScript Performance (LOW-MEDIUM)
- Group CSS changes via classes or cssTextjs-batch-dom-css
- Build Map for repeated lookupsjs-index-maps
- Cache object properties in loopsjs-cache-property-access
- Cache function results in module-level Mapjs-cache-function-results
- Cache localStorage/sessionStorage readsjs-cache-storage
- Combine multiple filter/map into one loopjs-combine-iterations
- Check array length before expensive comparisonjs-length-check-first
- Return early from functionsjs-early-exit
- Hoist RegExp creation outside loopsjs-hoist-regexp
- Use loop for min/max instead of sortjs-min-max-loop
- Use Set/Map for O(1) lookupsjs-set-map-lookups
- Use toSorted() for immutabilityjs-tosorted-immutable
8. Advanced Patterns (LOW)
- Store event handlers in refsadvanced-event-handler-refs
- useLatest for stable callback refsadvanced-use-latest
IMPORTANT: Read Before Fixing
YOU MUST read
before making any performance fixes. It contains the detailed code patterns you need to identify and fix issues correctly. The quick reference above is just an index - the actual before/after code examples are in AGENTS.md.AGENTS.md
For specific rules, read the individual files in
rules/ (e.g., rules/async-api-routes.md for API route waterfalls).