Vercel react best practices skill

React and Next.js performance optimization guidelines from Vercel Engineering.

by CloudAI-X·MIT license·★ 1,416 Stars on the repo·GitHub ↗

Use now

Files of Vercel react best practices

CloudAI-X/main1 file shown
SKILL.md
Show the full text119 lines

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 47 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 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
1---
2name: vercel-react-best-practices
3description: 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.
4---
5 
6# Vercel React Best Practices
7 
8### When to Load
9 
10- **Trigger**: React or Next.js development, component writing, data fetching patterns, bundle optimization
11- **Skip**: Project does not use React or Next.js
12 
13Comprehensive performance optimization guide for React and Next.js applications, maintained by Vercel. Contains 47 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
14 
15## When to Apply
16 
17Reference these guidelines when:
18 
19- Writing new React components or Next.js pages
20- Implementing data fetching (client or server-side)
21- Reviewing code for performance issues
22- Refactoring existing React/Next.js code
23- Optimizing bundle size or load times
24 
25## Rule Categories by Priority
26 
27| Priority | Category | Impact | Prefix |
28| -------- | ------------------------- | ----------- | ------------ |
29| 1 | Eliminating Waterfalls | CRITICAL | `async-` |
30| 2 | Bundle Size Optimization | CRITICAL | `bundle-` |
31| 3 | Server-Side Performance | HIGH | `server-` |
32| 4 | Client-Side Data Fetching | MEDIUM-HIGH | `client-` |
33| 5 | Re-render Optimization | MEDIUM | `rerender-` |
34| 6 | Rendering Performance | MEDIUM | `rendering-` |
35| 7 | JavaScript Performance | LOW-MEDIUM | `js-` |
36| 8 | Advanced Patterns | LOW | `advanced-` |
37 
38## Quick Reference
39 
40### 1. Eliminating Waterfalls (CRITICAL)
41 
42- `async-defer-await` - Move await into branches where actually used
43- `async-parallel` - Use Promise.all() for independent operations
44- `async-dependencies` - Use better-all for partial dependencies
45- `async-api-routes` - Start promises early, await late in API routes
46- `async-suspense-boundaries` - Use Suspense to stream content
47 
48### 2. Bundle Size Optimization (CRITICAL)
49 
50- `bundle-barrel-imports` - Import directly, avoid barrel files
51- `bundle-dynamic-imports` - Use next/dynamic for heavy components
52- `bundle-defer-third-party` - Load analytics/logging after hydration
53- `bundle-conditional` - Load modules only when feature is activated
54- `bundle-preload` - Preload on hover/focus for perceived speed
55 
56### 3. Server-Side Performance (HIGH)
57 
58- `server-cache-react` - Use React.cache() for per-request deduplication
59- `server-cache-lru` - Use LRU cache for cross-request caching
60- `server-serialization` - Minimize data passed to client components
61- `server-parallel-fetching` - Restructure components to parallelize fetches
62- `server-after-nonblocking` - Use after() for non-blocking operations
63 
64### 4. Client-Side Data Fetching (MEDIUM-HIGH)
65 
66- `client-swr-dedup` - Use SWR for automatic request deduplication
67- `client-event-listeners` - Deduplicate global event listeners
68 
69### 5. Re-render Optimization (MEDIUM)
70 
71- `rerender-defer-reads` - Don't subscribe to state only used in callbacks
72- `rerender-memo` - Extract expensive work into memoized components
73- `rerender-dependencies` - Use primitive dependencies in effects
74- `rerender-derived-state` - Subscribe to derived booleans, not raw values
75- `rerender-functional-setstate` - Use functional setState for stable callbacks
76- `rerender-lazy-state-init` - Pass function to useState for expensive values
77- `rerender-transitions` - Use startTransition for non-urgent updates
78 
79### 6. Rendering Performance (MEDIUM)
80 
81- `rendering-animate-svg-wrapper` - Animate div wrapper, not SVG element
82- `rendering-content-visibility` - Use content-visibility for long lists
83- `rendering-hoist-jsx` - Extract static JSX outside components
84- `rendering-svg-precision` - Reduce SVG coordinate precision
85- `rendering-hydration-no-flicker` - Use inline script for client-only data
86- `rendering-activity` - Use Activity component for show/hide
87- `rendering-conditional-render` - Use ternary, not && for conditionals
88 
89### 7. JavaScript Performance (LOW-MEDIUM)
90 
91- `js-batch-dom-css` - Group CSS changes via classes or cssText
92- `js-index-maps` - Build Map for repeated lookups
93- `js-cache-property-access` - Cache object properties in loops
94- `js-cache-function-results` - Cache function results in module-level Map
95- `js-cache-storage` - Cache localStorage/sessionStorage reads
96- `js-combine-iterations` - Combine multiple filter/map into one loop
97- `js-length-check-first` - Check array length before expensive comparison
98- `js-early-exit` - Return early from functions
99- `js-hoist-regexp` - Hoist RegExp creation outside loops
100- `js-min-max-loop` - Use loop for min/max instead of sort
101- `js-set-map-lookups` - Use Set/Map for O(1) lookups
102- `js-tosorted-immutable` - Use toSorted() for immutability
103 
104### 8. Advanced Patterns (LOW)
105 
106- `advanced-event-handler-refs` - Store event handlers in refs
107- `advanced-use-latest` - useLatest for stable callback refs
108 
109## Full Compiled Document
110 
111For the complete guide with all rules expanded and detailed code examples, see [AGENTS.md](AGENTS.md).
112 
113Each rule contains:
114 
115- Brief explanation of why it matters
116- Incorrect code example with explanation
117- Correct code example with explanation
118- Additional context and references
119 

Discussion

Alternatives

shadcn/uiManages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI, including chat interfaces. Provides project context, component docs, and usage examples. Applies when working with shadcn/ui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for "shadcn init", "create an app with --preset", or "switch to --preset".Coding · MITADK Code ReferenceThis skill should be used when the user wants to "write agent code", build an agent with ADK", "add a tool", "create a callback", "define an agent", use state management" — in a project that needs ADK (Agent Development Kit) API patterns and code examples. It provides a quick reference for agent types, tool definitions, orchestration patterns, callbacks, state management, the graph Workflow API, and reference recipes to study. Do NOT use for scaffolding (use google-agents-cli-scaffold) or deployment (use google-agents-cli-deploy).Coding · Apache-2.0Visual editOpen and collaboratively edit a running local app in Design, with shared fallback previews and source handoff. Use when the user asks to inspect, share, or edit a real local app in Design.Coding · MITModsmithPatterns, cost review and ready templates for Claude Mods (Claude Code plugins whose behaviour is a function-hooks module). Adds what the built-in mod authoring does not: proven designs (fork-check-draw, tool + ledger, mode registry, artifact-backed state), prompt-cache and token-cost review, a vetting pass for someone else's mod, and rules for mods that compose. USE WHEN: build a mod, make a claude mod, mod templates, quiz me after each turn, assumptions tool / register_assumption, supervisor that checks the turn, next-steps check, mode selector / mode registry, effort by domain, model router that keeps the cache, prompt cache cost of a mod, what does this mod cost per turn, review or vet someone's mod before installing, mods that work together, Kanban artifact as shared project state. NOT FOR: classic shell-command hooks in settings.json (PreToolUse etc.), a plain skill or slash command, MCP server authoring, or looking up the hooks API itself (use the engine's plugin-authoring guidance and generated types).Coding · MIT