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/rendering-animate-svg-wrapper.md
1---2title: Animate SVG Wrapper Instead of SVG Element3impact: LOW4impactDescription: enables hardware acceleration5tags: rendering, svg, css, animation, performance6---78## Animate SVG Wrapper Instead of SVG Element910Many browsers don't have hardware acceleration for CSS3 animations on SVG elements. Wrap SVG in a `<div>` and animate the wrapper instead.1112**Incorrect (animating SVG directly - no hardware acceleration):**1314```tsx15function LoadingSpinner() {16return (17<svg18className="animate-spin"19width="24"20height="24"21viewBox="0 0 24 24"22>23<circle cx="12" cy="12" r="10" stroke="currentColor" />24</svg>25)26}27```2829**Correct (animating wrapper div - hardware accelerated):**3031```tsx32function LoadingSpinner() {33return (34<div className="animate-spin">35<svg36width="24"37height="24"38viewBox="0 0 24 24"39>40<circle cx="12" cy="12" r="10" stroke="currentColor" />41</svg>42</div>43)44}45```4647This applies to all CSS transforms and transitions (`transform`, `opacity`, `translate`, `scale`, `rotate`). The wrapper div allows browsers to use GPU acceleration for smoother animations.48