React + Vite performance optimization and best practices guidelines
Provides React performance optimization guidelines and Vite-specific configuration patterns.
npx claudepluginhub devnogari/devnogari-claude-pluginsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
rules/bundle-optimization.mdrules/form-patterns.mdrules/rerender-prevention.mdrules/state-management.mdrules/tanstack-query.mdPerformance optimization and best practices for React applications using Vite.
This skill extends /vercel-react-best-practices - Vercel's official 45-rule guide for React performance.
When working on React code, always invoke /vercel-react-best-practices first for comprehensive patterns, then apply Vite-specific optimizations below.
This skill activates when:
For these patterns, use /vercel-react-best-practices:
async-* rulesbundle-* rulesrerender-* rulesjs-* rules| # | Category | Priority | Typical Impact |
|---|---|---|---|
| 1 | Bundle Optimization | CRITICAL | 200-800ms load time reduction |
| 2 | Re-render Prevention | HIGH | 2-10x render performance |
| 3 | State Management | HIGH | Memory & render efficiency |
| 4 | Async Patterns | MEDIUM | Network efficiency |
| 5 | Component Patterns | MEDIUM | Maintainability & performance |
Avoid barrel imports:
// ❌ INCORRECT - imports entire library
import { Button, Input } from '@/components'
// ✅ CORRECT - imports only what's needed
import { Button } from '@/components/Button'
import { Input } from '@/components/Input'
Dynamic imports for large components:
// ❌ INCORRECT - loads immediately
import { HeavyChart } from './HeavyChart'
// ✅ CORRECT - loads on demand
const HeavyChart = lazy(() => import('./HeavyChart'))
Memoize expensive computations:
// ❌ INCORRECT - recalculates every render
const sortedItems = items.sort((a, b) => a.name.localeCompare(b.name))
// ✅ CORRECT - only recalculates when items change
const sortedItems = useMemo(
() => items.sort((a, b) => a.name.localeCompare(b.name)),
[items]
)
Stable callback references:
// ❌ INCORRECT - new function every render
<Button onClick={() => handleClick(id)} />
// ✅ CORRECT - stable reference
const handleButtonClick = useCallback(() => handleClick(id), [id])
<Button onClick={handleButtonClick} />
Colocate state with usage:
// ❌ INCORRECT - state too high in tree
function App() {
const [modalOpen, setModalOpen] = useState(false)
return <DeepChild modalOpen={modalOpen} />
}
// ✅ CORRECT - state near usage
function ModalContainer() {
const [modalOpen, setModalOpen] = useState(false)
return <Modal open={modalOpen} />
}
Split state by update frequency:
// ❌ INCORRECT - unrelated state together
const [state, setState] = useState({ user: null, theme: 'dark', count: 0 })
// ✅ CORRECT - independent state
const [user, setUser] = useState(null)
const [theme, setTheme] = useState('dark')
const [count, setCount] = useState(0)
See individual rule files in rules/ directory:
bundle-optimization.mdrerender-prevention.mdstate-management.mdasync-patterns.mdcomponent-patterns.mdvite-specific.mdWhen writing or reviewing React code:
These patterns are Vite-specific and extend the Vercel best practices:
Configure optimizeDeps:
// vite.config.ts
export default defineConfig({
optimizeDeps: {
include: ['react', 'react-dom', 'lodash-es'],
exclude: ['@my-org/heavy-lib']
}
})
Use manual chunks for code splitting:
// vite.config.ts
export default defineConfig({
build: {
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom'],
ui: ['@radix-ui/react-dialog', '@radix-ui/react-dropdown-menu']
}
}
}
}
})
When implementing React features:
/vercel-react-best-practices for comprehensive React patternsbundle-* and async-* rules/vercel-react-best-practices → React patterns (45 rules)
↓
This skill → Vite-specific config & chunking
Use when working with Payload CMS projects (payload.config.ts, collections, fields, hooks, access control, Payload API). Use when debugging validation errors, security issues, relationship queries, transactions, or hook behavior.