Get the FREE Ultimate OpenClaw Setup Guide β†’

vercel-react-best-practices

Scanned
npx machina-cli add skill CloudAI-X/claude-workflow-v2/vercel-react-best-practices --openclaw
Files (1)
SKILL.md
5.4 KB

Vercel React Best Practices

When to Load

  • Trigger: React or Next.js development, component writing, data fetching patterns, bundle optimization
  • Skip: Project does not use React or Next.js

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

PriorityCategoryImpactPrefix
1Eliminating WaterfallsCRITICALasync-
2Bundle Size OptimizationCRITICALbundle-
3Server-Side PerformanceHIGHserver-
4Client-Side Data FetchingMEDIUM-HIGHclient-
5Re-render OptimizationMEDIUMrerender-
6Rendering PerformanceMEDIUMrendering-
7JavaScript PerformanceLOW-MEDIUMjs-
8Advanced PatternsLOWadvanced-

Quick Reference

1. Eliminating Waterfalls (CRITICAL)

  • async-defer-await - Move await into branches where actually used
  • async-parallel - Use Promise.all() for independent operations
  • async-dependencies - Use better-all for partial dependencies
  • async-api-routes - Start promises early, await late in API routes
  • async-suspense-boundaries - Use Suspense to stream content

2. Bundle Size Optimization (CRITICAL)

  • bundle-barrel-imports - Import directly, avoid barrel files
  • bundle-dynamic-imports - Use next/dynamic for heavy components
  • bundle-defer-third-party - Load analytics/logging after hydration
  • bundle-conditional - Load modules only when feature is activated
  • bundle-preload - Preload on hover/focus for perceived speed

3. Server-Side Performance (HIGH)

  • server-cache-react - Use React.cache() for per-request deduplication
  • server-cache-lru - Use LRU cache for cross-request caching
  • server-serialization - Minimize data passed to client components
  • server-parallel-fetching - Restructure components to parallelize fetches
  • server-after-nonblocking - Use after() for non-blocking operations

4. Client-Side Data Fetching (MEDIUM-HIGH)

  • client-swr-dedup - Use SWR for automatic request deduplication
  • client-event-listeners - Deduplicate global event listeners

5. Re-render Optimization (MEDIUM)

  • rerender-defer-reads - Don't subscribe to state only used in callbacks
  • rerender-memo - Extract expensive work into memoized components
  • rerender-dependencies - Use primitive dependencies in effects
  • rerender-derived-state - Subscribe to derived booleans, not raw values
  • rerender-functional-setstate - Use functional setState for stable callbacks
  • rerender-lazy-state-init - Pass function to useState for expensive values
  • rerender-transitions - Use startTransition for non-urgent updates

6. Rendering Performance (MEDIUM)

  • rendering-animate-svg-wrapper - Animate div wrapper, not SVG element
  • rendering-content-visibility - Use content-visibility for long lists
  • rendering-hoist-jsx - Extract static JSX outside components
  • rendering-svg-precision - Reduce SVG coordinate precision
  • rendering-hydration-no-flicker - Use inline script for client-only data
  • rendering-activity - Use Activity component for show/hide
  • rendering-conditional-render - Use ternary, not && for conditionals

7. JavaScript Performance (LOW-MEDIUM)

  • js-batch-dom-css - Group CSS changes via classes or cssText
  • js-index-maps - Build Map for repeated lookups
  • js-cache-property-access - Cache object properties in loops
  • js-cache-function-results - Cache function results in module-level Map
  • js-cache-storage - Cache localStorage/sessionStorage reads
  • js-combine-iterations - Combine multiple filter/map into one loop
  • js-length-check-first - Check array length before expensive comparison
  • js-early-exit - Return early from functions
  • js-hoist-regexp - Hoist RegExp creation outside loops
  • js-min-max-loop - Use loop for min/max instead of sort
  • js-set-map-lookups - Use Set/Map for O(1) lookups
  • js-tosorted-immutable - Use toSorted() for immutability

8. Advanced Patterns (LOW)

  • advanced-event-handler-refs - Store event handlers in refs
  • advanced-use-latest - useLatest for stable callback refs

Full Compiled Document

For the complete guide with all rules expanded and detailed code examples, see: AGENTS.md

Each rule contains:

  • Brief explanation of why it matters
  • Incorrect code example with explanation
  • Correct code example with explanation
  • Additional context and references

Source

git clone https://github.com/CloudAI-X/claude-workflow-v2/blob/main/skills/vercel-react-best-practices/SKILL.mdView on GitHub

Overview

Vercel React Best Practices is a comprehensive guide from Vercel Engineering with 45 rules across 8 categories. It’s designed to guide you when writing, reviewing, or refactoring React/Next.js code to optimize performance, load times, and user experience.

How This Skill Works

The guide groups rules by priority and prefixes (e.g., async-, bundle-, server-, client-, rerender-, rendering-, js-, advanced-). Developers apply these patterns during writing, reviewing, or refactoring to eliminate waterfalls, shrink bundles, improve server/client data handling, and reduce unnecessary re-renders and render-time costs.

When to Use It

  • 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

Quick Start

  1. Step 1: Run a quick performance audit against React/Next.js code to identify waterfalls and large bundles.
  2. Step 2: Apply relevant prefixes (async-, bundle-, server-, client-, rerender-, rendering-) to refactor the code paths with the highest impact.
  3. Step 3: Measure performance improvements with your preferred tooling and iterate.

Best Practices

  • Follow the priority-driven rules: Eliminate Waterfalls (async-), Bundle Size Optimization (bundle-), Server-Side Performance (server-), Client-Side Data Fetching (client-), Re-render Optimization (rerender-), Rendering Performance (rendering-), JavaScript Performance (js-), and Advanced Patterns (advanced-).
  • Apply concrete rule examples: async-defer-await, async-parallel, bundle-barrel-imports, bundle-dynamic-imports, bundle-defer-third-party, server-cache-react, server-cache-lru, server-serialization, server-parallel-fetching, client-swr-dedup, client-event-listeners, rerender-memo, rerender-transitions, rendering-content-visibility, rendering-hoist-jsx.
  • Prefer direct imports over barrel files, and lazy-load heavy components with next/dynamic to reduce initial bundle size.
  • Defer non-critical analytics or third-party scripts until after hydration using bundle-defer-third-party patterns.
  • Deduplicate client data fetches with SWR and minimize global event listeners to lower runtime overhead.

Example Use Cases

  • Refactor a Next.js page to lazy-load a heavy chart component using next/dynamic and bundle-dynamic-imports.
  • Parallelize multiple API calls in a component with server-parallel-fetching to prevent waterfalls.
  • Move analytics loading to after hydration with bundle-defer-third-party to reduce initial load cost.
  • Replace repeated fetches with SWR deduplication (client-swr-dedup) to minimize network calls.
  • Memoize expensive child components and apply startTransition for non-urgent UI updates (rerender-memo, rerender-transitions).

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers β†—