4.2 KiB
4.2 KiB
name, description, license, metadata
| name | description | license | metadata | ||||
|---|---|---|---|---|---|---|---|
| vercel-react-best-practices | 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. | MIT |
|
Vercel React Best Practices
Comprehensive performance optimization guide for React and Next.js applications, maintained by Vercel. Contains 57 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- Avoid large barrel files; use direct importsbundle-large-libraries- Optimize heavy deps (e.g. framer-motion, lucide)bundle-conditional- Lazy load conditional componentsbundle-route-split- Split huge page componentsbundle-dynamic-imports- Use next/dynamic for heavy client components
3. Server-Side Performance (HIGH)
server-cache-react- Use React.cache() for per-request deduplicationserver-cache-next- Use unstable_cache for data coachingserver-only-utils- Mark server-only code with 'server-only' packageserver-component-boundaries- Keep client components at leavesserver-image-optimization- Use next/image with proper sizing
4. Client-Side Data Fetching (MEDIUM-HIGH)
client-use-swr- Use SWR/TanStack Query for client-side dataclient-no-effect-fetch- Avoid fetching in useEffect without caching librariesclient-prefetch-link- Use next/link prefetchingclient-caching-headers- Respect cache-control headers
5. Re-render Optimization (MEDIUM)
rerender-memo-props- Memoize complex propsrerender-dependencies- Use primitive dependencies in effectsrerender-functional-setstate- Use functional setState for stable callbacksrerender-context-split- Split context to avoid wide re-renders
6. Rendering Performance (MEDIUM)
rendering-image-priority- Priority load LCP imagesrendering-list-virtualization- Virtualize long listsrendering-content-visibility- Use content-visibility for long listsrendering-hoist-jsx- Extract static JSX outside componentsrendering-hydration-no-flicker- Use inline script for client-only data
7. JavaScript Performance (LOW-MEDIUM)
js-batch-dom-css- Group CSS changesjs-index-maps- Build Map for repeated lookupsjs-combine-iterations- Combine multiple filter/map into one loopjs-set-map-lookups- Use Set/Map for O(1) lookups
8. Advanced Patterns (LOW)
advanced-event-handler-refs- Store event handlers in refsadvanced-init-once- Initialize app once per app load