Performance: JavaScript hooks for transitions
MEDIUM IMPACT
This affects the smoothness and timing of animations during component state changes, impacting interaction responsiveness and visual stability.
const hooks = { beforeEnter(el) { el.style.opacity = '0'; }, enter(el, done) { requestAnimationFrame(() => { el.style.transition = 'opacity 0.5s'; el.style.opacity = '1'; setTimeout(done, 500); }); } };
const hooks = { beforeEnter(el) { // heavy synchronous logic for(let i = 0; i < 100000000; i++) {} el.style.opacity = '0'; }, enter(el, done) { el.style.transition = 'opacity 0.5s'; el.style.opacity = '1'; setTimeout(done, 500); } };
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous logic in hooks | Multiple style changes | Multiple reflows triggered | High paint cost due to layout thrashing | [X] Bad |
| Lightweight hooks with requestAnimationFrame | Minimal style changes | Single reflow | Low paint cost with smooth animation | [OK] Good |