Get the FREE Ultimate OpenClaw Setup Guide →

react-best-practices

Scanned
npx machina-cli add skill vudovn/antigravity-kit/nextjs-react-expert --openclaw
Files (1)
SKILL.md
9.6 KB

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

FileImpactRulesWhen to Read
1-async-eliminating-waterfalls.mdšŸ”“ CRITICAL5 rulesSlow page loads, sequential API calls, data fetching waterfalls
2-bundle-bundle-size-optimization.mdšŸ”“ CRITICAL5 rulesLarge bundle size, slow Time to Interactive, First Load issues
3-server-server-side-performance.md🟠 HIGH7 rulesSlow SSR, API route optimization, server-side waterfalls
4-client-client-side-data-fetching.md🟔 MEDIUM-HIGH4 rulesClient data management, SWR patterns, deduplication
5-rerender-re-render-optimization.md🟔 MEDIUM12 rulesExcessive re-renders, React performance, memoization
6-rendering-rendering-performance.md🟔 MEDIUM9 rulesRendering bottlenecks, virtualization, image optimization
7-js-javascript-performance.md⚪ LOW-MEDIUM12 rulesMicro-optimizations, caching, loop performance
8-advanced-advanced-patterns.mdšŸ”µ VARIABLE3 rulesAdvanced 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

NeedSkill
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

ScriptPurposeCommand
scripts/react_performance_checker.pyAutomated performance auditpython 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

Source

git clone https://github.com/vudovn/antigravity-kit/blob/main/.agent/skills/nextjs-react-expert/SKILL.mdView on GitHub

Overview

This skill distills React and Next.js performance optimization into 57 rules prioritized by impact, from eliminating waterfalls to bundle size and micro-optimizations. It guides developers to identify bottlenecks, apply server/client-side optimizations, and ship faster UIs.

How This Skill Works

It uses a selective reading approach: start with CRITICAL sections (waterfalls and bundle size), then progress to HIGH/MEDIUM topics like server-side and client-side performance. You apply the recommended patterns (parallel data fetching, dynamic imports, tree-shaking, memoization) to real components and flows, then measure impact on TTI, LCP, and overall UX.

When to Use It

  • Need to speed up slow page loads and eliminate data-fetching waterfalls
  • Trying to reduce bundle size and improve time to interactive
  • Optimizing server-side rendering and API route performance
  • Facing excessive re-renders or UI lag in React components
  • Dealing with rendering bottlenecks, virtualization, or image optimization

Quick Start

  1. Step 1: Identify waterfalls and large bundle hotspots with a performance audit
  2. Step 2: Apply dynamic imports and tree-shaking to reduce bundle size; parallelize data fetching where possible
  3. Step 3: Introduce memoization and virtualization; measure improvements with TTI/LCP

Best Practices

  • Prioritize eliminating waterfalls before bundle or micro-optimizations
  • Reduce bundle size with dynamic imports, barrel imports avoidance, and tree-shaking
  • Improve server-side performance by parallelizing data fetching and reducing SSR waterfalls
  • Use React.memo, useMemo, and useCallback to minimize re-renders
  • Implement virtualization and image optimizations for rendering performance

Example Use Cases

  • On a dashboard, split API calls to avoid sequential waterfalls and cache results
  • Refactor large React components into dynamically imported chunks to shrink bundles
  • Enable parallel data fetching in SSR routes to eliminate server-side waterfalls
  • Memoize heavy child components to cut down re-renders on frequent prop changes
  • Virtualize long lists and optimize images to boost rendering performance

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers ↗