From best-practices
React + Vite performance optimization and best practices guidelines
npx claudepluginhub devnogari/devnogari-claude-plugins --plugin best-practicesThis skill uses the workspace's default tool permissions.
Performance optimization and best practices for React applications using Vite.
Guides Payload CMS config (payload.config.ts), collections, fields, hooks, access control, APIs. Debugs validation errors, security, relationships, queries, transactions, hook behavior.
Builds scalable data pipelines, modern data warehouses, and real-time streaming architectures using Spark, dbt, Airflow, Kafka, and cloud platforms like Snowflake, BigQuery.
Builds production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. For data pipelines, workflow orchestration, and batch job scheduling.
Performance 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