react-best-practices
Comprehensive React and Next.js performance optimization guide with 40+ rules for eliminating waterfalls, optimizing bundles, and improving rendering. Use when optimizing React apps, reviewing performance, or refactoring components.
- License 许可
- MIT
- 最近更新
- 2026-11-11
- Stars
- ★ 3.3w
- Forks
- 3.9k
01 前言 Front Matter
- name
- react-best-practices
- license
- MIT
- metadata
- { "tags": [ "React", "Next.js", "Performance", "Optimization", "Best Practices", "Bundle Size", "Rendering", "Server Components" ], "author": "Vercel Engineering", "version": "1.0.0", "dependencies": [] }
- description
- Comprehensive React and Next.js performance optimization guide with 40+ rules for eliminating waterfalls, optimizing bundles, and improving rendering. Use when optimizing React apps, reviewing performance, or refactoring components.
02 资源文件 50
- 参考文档reference/example.md1.7 KB
- 参考文档reference/generative-delivery-closeout.md6.7 KB
- 参考文档reference/scan-commands.md1.1 KB
- 参考文档references/react-performance-guidelines.md45.8 KB
- 参考文档references/rules/_sections.md1.5 KB
- 参考文档references/rules/_template.md631 B
- 参考文档references/rules/advanced-event-handler-refs.md960 B
- 参考文档references/rules/advanced-use-latest.md1.2 KB
- 参考文档references/rules/async-api-routes.md1.1 KB
- 参考文档references/rules/async-defer-await.md2.0 KB
- 参考文档references/rules/async-dependencies.md942 B
- 参考文档references/rules/async-parallel.md654 B
- 参考文档references/rules/async-suspense-boundaries.md1.6 KB
- 参考文档references/rules/bundle-barrel-imports.md2.3 KB
- 参考文档references/rules/bundle-conditional.md870 B
- 参考文档references/rules/bundle-defer-third-party.md922 B
- 参考文档references/rules/bundle-dynamic-imports.md791 B
- 参考文档references/rules/bundle-preload.md1.1 KB
- 参考文档references/rules/client-event-listeners.md1.9 KB
- 参考文档references/rules/client-swr-dedup.md1.1 KB
- 脚本references/rules/download_rules.sh3.3 KB
- 参考文档references/rules/js-batch-dom-css.md1.9 KB
- 参考文档references/rules/js-cache-function-results.md1.9 KB
- 参考文档references/rules/js-cache-property-access.md532 B
- 参考文档references/rules/js-cache-storage.md1.6 KB
- 参考文档references/rules/js-combine-iterations.md753 B
- 参考文档references/rules/js-early-exit.md1.1 KB
- 参考文档references/rules/js-hoist-regexp.md994 B
- 参考文档references/rules/js-index-maps.md837 B
- 参考文档references/rules/js-length-check-first.md1.7 KB
- 参考文档references/rules/js-min-max-loop.md2.1 KB
- 参考文档references/rules/js-set-map-lookups.md532 B
- 参考文档references/rules/js-tosorted-immutable.md1.7 KB
- 参考文档references/rules/rendering-activity.md564 B
- 参考文档references/rules/rendering-animate-svg-wrapper.md1.2 KB
- 参考文档references/rules/rendering-conditional-render.md983 B
- 参考文档references/rules/rendering-content-visibility.md822 B
- 参考文档references/rules/rendering-hoist-jsx.md819 B
- 参考文档references/rules/rendering-hydration-no-flicker.md2.3 KB
- 参考文档references/rules/rendering-svg-precision.md591 B
- 参考文档references/rules/rerender-defer-reads.md973 B
- 参考文档references/rules/rerender-dependencies.md827 B
- 参考文档references/rules/rerender-derived-state.md724 B
- 参考文档references/rules/rerender-lazy-state-init.md2.0 KB
- 参考文档references/rules/rerender-memo.md935 B
- 参考文档references/rules/rerender-transitions.md1.0 KB
- 参考文档references/rules/server-cache-lru.md1011 B
- 参考文档references/rules/server-cache-react.md679 B
- 参考文档references/rules/server-parallel-fetching.md1.5 KB
- 参考文档references/rules/server-serialization.md826 B
03 SKILL.md 正文
React Best Practices - Performance Optimization
Comprehensive performance optimization guide for React and Next.js applications with 40+ rules organized by impact level. Designed to help developers eliminate performance bottlenecks and follow best practices.
When to use this skill
Use React Best Practices when:
- Optimizing React or Next.js application performance
- Reviewing code for performance improvements
- Refactoring existing components for better performance
- Implementing new features with performance in mind
- Debugging slow rendering or loading issues
- Reducing bundle size
- Eliminating request waterfalls
Key areas covered:
- Eliminating Waterfalls (CRITICAL): Prevent sequential async operations
- Bundle Size Optimization (CRITICAL): Reduce initial JavaScript payload
- Server-Side Performance (HIGH): Optimize RSC and data fetching
- Client-Side Data Fetching (MEDIUM-HIGH): Implement efficient caching
- Re-render Optimization (MEDIUM): Minimize unnecessary re-renders
- Rendering Performance (MEDIUM): Optimize browser rendering
- JavaScript Performance (LOW-MEDIUM): Micro-optimizations for hot paths
- Advanced Patterns (LOW): Specialized techniques for edge cases
Quick reference
Critical priorities
- Defer await until needed - Move awaits into branches where they're used
- Use Promise.all() - Parallelize independent async operations
- Avoid barrel imports - Import directly from source files
- Dynamic imports - Lazy-load heavy components
- Strategic Suspense - Stream content while showing layout
Common patterns
Parallel data fetching:
const [user, posts, comments] = await Promise.all([
fetchUser(),
fetchPosts(),
fetchComments()
])
Direct imports:
// ❌ Loads entire library
import { Check } from 'lucide-react'
// ✅ Loads only what you need
import Check from 'lucide-react/dist/esm/icons/check'
Dynamic components:
import dynamic from 'next/dynamic'
const MonacoEditor = dynamic(
() => import('./monaco-editor'),
{ ssr: false }
)
Using the guidelines
The complete performance guidelines are available in the references folder:
- react-performance-guidelines.md: Complete guide with all 40+ rules, code examples, and impact analysis
Each rule includes:
- Incorrect/correct code comparisons
- Specific impact metrics
- When to apply the optimization
- Real-world examples
Categories overview
1. Eliminating Waterfalls (CRITICAL)
Waterfalls are the #1 performance killer. Each sequential await adds full network latency.
- Defer await until needed
- Dependency-based parallelization
- Prevent waterfall chains in API routes
- Promise.all() for independent operations
- Strategic Suspense boundaries
2. Bundle Size Optimization (CRITICAL)
Reducing initial bundle size improves Time to Interactive and Largest Contentful Paint.
- Avoid barrel file imports
- Conditional module loading
- Defer non-critical third-party libraries
- Dynamic imports for heavy components
- Preload based on user intent
3. Server-Side Performance (HIGH)
Optimize server-side rendering and data fetching.
- Cross-request LRU caching
- Minimize serialization at RSC boundaries
- Parallel data fetching with component composition
- Per-request deduplication with React.cache()
4. Client-Side Data Fetching (MEDIUM-HIGH)
Automatic deduplication and efficient data fetching patterns.
- Deduplicate global event listeners
- Use SWR for automatic deduplication
5. Re-render Optimization (MEDIUM)
Reduce unnecessary re-renders to minimize wasted computation.
- Defer state reads to usage point
- Extract to memoized components
- Narrow effect dependencies
- Subscribe to derived state
- Use lazy state initialization
- Use transitions for non-urgent updates
6. Rendering Performance (MEDIUM)
Optimize the browser rendering process.
- Animate SVG wrapper instead of SVG element
- CSS content-visibility for long lists
- Hoist static JSX elements
- Optimize SVG precision
- Prevent hydration mismatch without flickering
- Use Activity component for show/hide
- Use explicit conditional rendering
7. JavaScript Performance (LOW-MEDIUM)
Micro-optimizations for hot paths.
- Batch DOM CSS changes
- Build index maps for repeated lookups
- Cache property access in loops
- Cache repeated function calls
- Cache storage API calls
- Combine multiple array iterations
- Early length check for array comparisons
- Early return from functions
- Hoist RegExp creation
- Use loop for min/max instead of sort
- Use Set/Map for O(1) lookups
- Use toSorted() instead of sort()
8. Advanced Patterns (LOW)
Specialized techniques for edge cases.
- Store event handlers in refs
- useLatest for stable callback refs
Implementation approach
When optimizing a React application:
- Profile first: Use React DevTools Profiler and browser performance tools to identify bottlenecks
- Focus on critical paths: Start with eliminating waterfalls and reducing bundle size
- Measure impact: Verify improvements with metrics (LCP, TTI, FID)
- Apply incrementally: Don't over-optimize prematurely
- Test thoroughly: Ensure optimizations don't break functionality
Key metrics to track
- Time to Interactive (TTI): When page becomes fully interactive
- Largest Contentful Paint (LCP): When main content is visible
- First Input Delay (FID): Responsiveness to user interactions
- Cumulative Layout Shift (CLS): Visual stability
- Bundle size: Initial JavaScript payload
- Server response time: TTFB for server-rendered content
Common pitfalls to avoid
❌ Don't:
- Use barrel imports from large libraries
- Block parallel operations with sequential awaits
- Re-render entire trees when only part needs updating
- Load analytics/tracking in the critical path
- Mutate arrays with .sort() instead of .toSorted()
- Create RegExp or heavy objects inside render
✅ Do:
- Import directly from source files
- Use Promise.all() for independent operations
- Memoize expensive components
- Lazy-load non-critical code
- Use immutable array methods
- Hoist static objects outside components
Resources
- React Documentation
- Next.js Documentation
- SWR Documentation
- Vercel Bundle Optimization
- Vercel Dashboard Performance
- better-all Library
- node-lru-cache
Version history
v0.1.0 (January 2026)
- Initial release from Vercel Engineering
- 40+ performance rules across 8 categories
- Comprehensive code examples and impact analysis
04 同仓库更多 Skills
wealthville-pool-scoring
Score DeFi liquidity pools before providing liquidity. Returns a 0-100 pool score and an Enter/Hold/Exit/Reduce/Avoid verdict with calibrated confidence for ~68,800 Solana pools and 575 EVM pools, plus a public miss-inclusive track record. Use when asked whether a pool is worth LPing into, which pools look best right now, or how accurate the scores have actually been.
technical-debt-auditor
Scans a codebase and produces a quantified technical debt report with a prioritized remediation plan. Analyzes dead code, TODO/FIXME/HACK markers, dependency staleness, complexity hotspots, code duplication signals, test coverage gaps, unused exports, and outdated patterns. Use this skill when the user asks to audit their codebase for tech debt, wants a health check of their code quality, says things like "where should I focus refactoring", "find code smells", "audit my codebase", "what technical debt do we have", "prioritize cleanup work", or asks about code quality metrics. Also trigger when the user mentions "code rot", "legacy cleanup", "refactoring priorities", or wants to understand the overall health of a project before a major effort. Trigger even if the user doesn't say "technical debt" explicitly — any request to systematically assess code quality and identify improvement priorities belongs here.
readonly-sql-guard
Make an agent's database access provably read-only. Use when an agent runs caller-supplied SQL against a production/ERP/analytics database (a "query" MCP tool, text-to-SQL, an admin console), or when reviewing DB-access code for write/DDL/side-effect/transaction-escape risks. Checks what a statement CALLS, not just its shape.
web-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
discernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals, or emails, estimates or projections, analysis or interpretation of data, factual claims they may rely on, or a multi-step argument — invoke this skill BEFORE finalizing your reply and then, if it applies, append 2-3 short follow-up questions, each tied to something specific in what you just produced, that help the user check key facts, probe the reasoning or assumptions, and notice missing context. Do this at most once per conversation. Skip it when the user asked a trivial how-to or simple lookup, wants a purely educational explanation, asked you only to format, convert, or assemble a file from content they provided, is writing code they will run, is doing creative writing or casual chat, or already asked you to double-check, cite, or review — the skill file explains these boundaries and the exact output format.