vudovn

react-best-practices

React and Next.js performance optimization from Vercel Engineering. Use when building React components, optimizing performance, eliminating waterfalls, reducing bundle size, reviewing code for performance issues, or implementing server/client-side optimizations.

vudovn 7,647 1,481 Updated 4mo ago

Resources

9
GitHub

Install

npx skillscat add vudovn/antigravity-kit/react-best-practices

Install via the SkillsCat registry.

SKILL.md

Next.js & React Performance Expert

From Vercel Engineering - 57 optimization rules prioritized by impact
Philosophy: Eliminate waterfalls first, optimize bundles second, then micro-optimize.


๐ŸŽฏ Selective Reading Rule (MANDATORY)

Read ONLY sections relevant to your task! Check the content map below and load what you need.

๐Ÿ”ด For performance reviews: Start with CRITICAL sections (1-2), then move to HIGH/MEDIUM.


๐Ÿ“‘ Content Map

File Impact Rules When to Read
1-async-eliminating-waterfalls.md ๐Ÿ”ด CRITICAL 5 rules Slow page loads, sequential API calls, data fetching waterfalls
2-bundle-bundle-size-optimization.md ๐Ÿ”ด CRITICAL 5 rules Large bundle size, slow Time to Interactive, First Load issues
3-server-server-side-performance.md ๐ŸŸ  HIGH 7 rules Slow SSR, API route optimization, server-side waterfalls
4-client-client-side-data-fetching.md ๐ŸŸก MEDIUM-HIGH 4 rules Client data management, SWR patterns, deduplication
5-rerender-re-render-optimization.md ๐ŸŸก MEDIUM 12 rules Excessive re-renders, React performance, memoization
6-rendering-rendering-performance.md ๐ŸŸก MEDIUM 9 rules Rendering bottlenecks, virtualization, image optimization
7-js-javascript-performance.md โšช LOW-MEDIUM 12 rules Micro-optimizations, caching, loop performance
8-advanced-advanced-patterns.md ๐Ÿ”ต VARIABLE 3 rules Advanced React patterns, useLatest, init-once

Total: 57 rules across 8 categories


๐Ÿš€ Quick Decision Tree

What's your performance issue?

๐ŸŒ Slow page loads / Long Time to Interactive
  โ†’ Read Section 1: Eliminating Waterfalls
  โ†’ Read Section 2: Bundle Size Optimization

๐Ÿ“ฆ Large bundle size (> 200KB)
  โ†’ Read Section 2: Bundle Size Optimization
  โ†’ Check: Dynamic imports, barrel imports, tree-shaking

๐Ÿ–ฅ๏ธ Slow Server-Side Rendering
  โ†’ Read Section 3: Server-Side Performance
  โ†’ Check: Parallel data fetching, streaming

๐Ÿ”„ Too many re-renders / UI lag
  โ†’ Read Section 5: Re-render Optimization
  โ†’ Check: React.memo, useMemo, useCallback

๐ŸŽจ Rendering performance issues
  โ†’ Read Section 6: Rendering Performance
  โ†’ Check: Virtualization, layout thrashing

๐ŸŒ Client-side data fetching problems
  โ†’ Read Section 4: Client-Side Data Fetching
  โ†’ Check: SWR deduplication, localStorage

โœจ Need advanced patterns
  โ†’ Read Section 8: Advanced Patterns

๐Ÿ“Š Impact Priority Guide

Use this order when doing comprehensive optimization:

1๏ธโƒฃ CRITICAL (Biggest Gains - Do First):
   โ”œโ”€ Section 1: Eliminating Waterfalls
   โ”‚  โ””โ”€ Each waterfall adds full network latency (100-500ms+)
   โ””โ”€ Section 2: Bundle Size Optimization
      โ””โ”€ Affects Time to Interactive and Largest Contentful Paint

2๏ธโƒฃ HIGH (Significant Impact - Do Second):
   โ””โ”€ Section 3: Server-Side Performance
      โ””โ”€ Eliminates server-side waterfalls, faster response times

3๏ธโƒฃ MEDIUM (Moderate Gains - Do Third):
   โ”œโ”€ Section 4: Client-Side Data Fetching
   โ”œโ”€ Section 5: Re-render Optimization
   โ””โ”€ Section 6: Rendering Performance

4๏ธโƒฃ LOW (Polish - Do Last):
   โ”œโ”€ Section 7: JavaScript Performance
   โ””โ”€ Section 8: Advanced Patterns

๐Ÿ”— Related Skills

Need Skill
API design patterns @[skills/api-patterns]
Database optimization @[skills/database-design]
Testing strategies @[skills/testing-patterns]
UI/UX design principles @[skills/frontend-design]
TypeScript patterns @[skills/typescript-expert]
Deployment & DevOps @[skills/deployment-procedures]

โœ… Performance Review Checklist

Before shipping to production:

Critical (Must Fix):

  • No sequential data fetching (waterfalls eliminated)
  • Bundle size < 200KB for main bundle
  • No barrel imports in app code
  • Dynamic imports used for large components
  • Parallel data fetching where possible

High Priority:

  • Server components used where appropriate
  • API routes optimized (no N+1 queries)
  • Suspense boundaries for data fetching
  • Static generation used where possible

Medium Priority:

  • Expensive computations memoized
  • List rendering virtualized (if > 100 items)
  • Images optimized with next/image
  • No unnecessary re-renders

Low Priority (Polish):

  • Hot path loops optimized
  • RegExp patterns hoisted
  • Property access cached in loops

โŒ Anti-Patterns (Common Mistakes)

DON'T:

  • โŒ Use sequential await for independent operations
  • โŒ Import entire libraries when you need one function
  • โŒ Use barrel exports (index.ts re-exports) in app code
  • โŒ Skip dynamic imports for large components/libraries
  • โŒ Fetch data in useEffect without deduplication
  • โŒ Forget to memoize expensive computations
  • โŒ Use client components when server components work

DO:

  • โœ… Fetch data in parallel with Promise.all()
  • โœ… Use dynamic imports: const Comp = dynamic(() => import('./Heavy'))
  • โœ… Import directly: import { specific } from 'library/specific'
  • โœ… Use Suspense boundaries for better UX
  • โœ… Leverage React Server Components
  • โœ… Measure performance before optimizing
  • โœ… Use Next.js built-in optimizations (next/image, next/font)

๐ŸŽฏ How to Use This Skill

For New Features:

  1. Check Section 1 & 2 while building (prevent waterfalls, keep bundle small)
  2. Use server components by default (Section 3)
  3. Apply memoization for expensive operations (Section 5)

For Performance Reviews:

  1. Start with Section 1 (waterfalls = biggest impact)
  2. Then Section 2 (bundle size)
  3. Then Section 3 (server-side)
  4. Finally other sections as needed

For Debugging Slow Performance:

  1. Identify the symptom (slow load, lag, etc.)
  2. Use Quick Decision Tree above
  3. Read relevant section
  4. Apply fixes in priority order

๐Ÿ“š Learning Path

Beginner (Focus on Critical):
โ†’ Section 1: Eliminating Waterfalls
โ†’ Section 2: Bundle Size Optimization

Intermediate (Add High Priority):
โ†’ Section 3: Server-Side Performance
โ†’ Section 5: Re-render Optimization

Advanced (Full Optimization):
โ†’ All sections + Section 8: Advanced Patterns


๐Ÿ” Validation Script

Script Purpose Command
scripts/react_performance_checker.py Automated performance audit python scripts/react_performance_checker.py <project_path>

๐Ÿ“– Section Details

Section 1: Eliminating Waterfalls (CRITICAL)

Impact: Each waterfall adds 100-500ms+ latency
Key Concepts: Parallel fetching, Promise.all(), Suspense boundaries, preloading

Section 2: Bundle Size Optimization (CRITICAL)

Impact: Directly affects Time to Interactive, Largest Contentful Paint
Key Concepts: Dynamic imports, tree-shaking, barrel import avoidance

Section 3: Server-Side Performance (HIGH)

Impact: Faster server responses, better SEO
Key Concepts: Parallel server fetching, streaming, API route optimization

Section 4: Client-Side Data Fetching (MEDIUM-HIGH)

Impact: Reduces redundant requests, better UX
Key Concepts: SWR deduplication, localStorage caching, event listeners

Section 5: Re-render Optimization (MEDIUM)

Impact: Smoother UI, less wasted computation
Key Concepts: React.memo, useMemo, useCallback, component structure

Section 6: Rendering Performance (MEDIUM)

Impact: Better rendering efficiency
Key Concepts: Virtualization, image optimization, layout thrashing

Section 7: JavaScript Performance (LOW-MEDIUM)

Impact: Incremental improvements in hot paths
Key Concepts: Loop optimization, caching, RegExp hoisting

Section 8: Advanced Patterns (VARIABLE)

Impact: Specific use cases
Key Concepts: useLatest hook, init-once patterns, event handler refs


๐ŸŽ“ Best Practices Summary

Golden Rules:

  1. Measure first - Use React DevTools Profiler, Chrome DevTools
  2. Biggest impact first - Waterfalls โ†’ Bundle โ†’ Server โ†’ Micro
  3. Don't over-optimize - Focus on real bottlenecks
  4. Use platform features - Next.js has optimizations built-in
  5. Think about users - Real-world conditions matter

Performance Mindset:

  • Every await in sequence = potential waterfall
  • Every import = potential bundle bloat
  • Every re-render = wasted computation (if unnecessary)
  • Server components = less JavaScript to ship
  • Measure, don't guess

Source: Vercel Engineering
Date: January 2026
Version: 1.0.0
Total Rules: 57 across 8 categories