Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply 62 React and Next.js performance optimization rules from Vercel Engineering
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/rerender-transitions.md
1---2title: Use Transitions for Non-Urgent Updates3impact: MEDIUM4impactDescription: maintains UI responsiveness5tags: rerender, transitions, startTransition, performance6---78## Use Transitions for Non-Urgent Updates910Mark frequent, non-urgent state updates as transitions to maintain UI responsiveness.1112**Incorrect (blocks UI on every scroll):**1314```tsx15function ScrollTracker() {16const [scrollY, setScrollY] = useState(0)17useEffect(() => {18const handler = () => setScrollY(window.scrollY)19window.addEventListener('scroll', handler, { passive: true })20return () => window.removeEventListener('scroll', handler)21}, [])22}23```2425**Correct (non-blocking updates):**2627```tsx28import { startTransition } from 'react'2930function ScrollTracker() {31const [scrollY, setScrollY] = useState(0)32useEffect(() => {33const handler = () => {34startTransition(() => setScrollY(window.scrollY))35}36window.addEventListener('scroll', handler, { passive: true })37return () => window.removeEventListener('scroll', handler)38}, [])39}40```41