fixing-motion-performance
When to Use
Use this skill when you need audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects. Use when animations stutter, transitions jank, or reviewing CSS/JS animation performance.
Fix animation performance issues.
how to use
Do not migrate animation libraries unless explicitly requested. Apply rules within the existing stack.
when to apply
Reference these guidelines when:
- adding or changing UI animations (CSS, WAAPI, Motion, rAF, GSAP)
- refactoring janky interactions or transitions
- implementing scroll-linked motion or reveal-on-scroll
- animating layout, filters, masks, gradients, or CSS variables
- reviewing components that use will-change, transforms, or measurement
rendering steps glossary
- composite: transform, opacity
- paint: color, borders, gradients, masks, images, filters
- layout: size, position, flow, grid, flex
rule categories by priority
| priority |
category |
impact |
| 1 |
never patterns |
critical |
| 2 |
choose the mechanism |
critical |
| 3 |
measurement |
high |
| 4 |
scroll |
high |
| 5 |
paint |
medium-high |
| 6 |
layers |
medium |
| 7 |
blur and filters |
medium |
| 8 |
view transitions |
low |
| 9 |
tool boundaries |
critical |
quick reference
1. never patterns (critical)
- do not interleave layout reads and writes in the same frame
- do not animate layout continuously on large or meaningful surfaces
- do not drive animation from scrollTop, scrollY, or scroll events
- no requestAnimationFrame loops without a stop condition
- do not mix multiple animation systems that each measure or mutate layout
2. choose the mechanism (critical)
- default to transform and opacity for motion
- use JS-driven animation only when interaction requires it
- paint or layout animation is acceptable only on small, isolated surfaces
- one-shot effects are acceptable more often than continuous motion
- prefer downgrading technique over removing motion entirely
3. measurement (high)
- measure once, then animate via transform or opacity
- batch all DOM reads before writes
- do not read layout repeatedly during an animation
- prefer FLIP-style transitions for layout-like effects
- prefer approaches that batch measurement and writes
4. scroll (high)
- prefer Scroll or View Timelines for scroll-linked motion when available
- use IntersectionObserver for visibility and pausing
- do not poll scroll position for animation
- pause or stop animations when off-screen
- scroll-linked motion must not trigger continuous layout or paint on large surfaces
5. paint (medium-high)
- paint-triggering animation is allowed only on small, isolated elements
- do not animate paint-heavy properties on large containers
- do not animate CSS variables for transform, opacity, or position
- do not animate inherited CSS variables
- scope animated CSS variables locally and avoid inheritance
6. layers (medium)
- compositor motion requires layer promotion, never assume it
- use will-change temporarily and surgically
- avoid many or large promoted layers
- validate layer behavior with tooling when performance matters
7. blur and filters (medium)
- keep blur animation small (<=8px)
- use blur only for short, one-time effects
- never animate blur continuously
- never animate blur on large surfaces
- prefer opacity and translate before blur
8. view transitions (low)
- use view transitions only for navigation-level changes
- avoid view transitions for interaction-heavy UI
- avoid view transitions when interruption or cancellation is required
- treat size changes as potentially layout-triggering
9. tool boundaries (critical)
- do not migrate or rewrite animation libraries unless explicitly requested
- apply these rules within the existing animation system
- never partially migrate APIs or mix styles within the same component
common fixes
/* layout thrashing: animate transform instead of width */
/* before */ .panel { transition: width 0.3s; }
/* after */ .panel { transition: transform 0.3s; }
/* scroll-linked: use scroll-timeline instead of JS */
/* before */ window.addEventListener('scroll', () => el.style.opacity = scrollY / 500)
/* after */ .reveal { animation: fade-in linear; animation-timeline: view(); }
// measurement: batch reads before writes (FLIP)
// before — layout thrash
el.style.left = el.getBoundingClientRect().left + 10 + 'px';
// after — measure once, animate via transform
const first = el.getBoundingClientRect();
el.classList.add('moved');
const last = el.getBoundingClientRect();
el.style.transform = `translateX(${first.left - last.left}px)`;
requestAnimationFrame(() => { el.style.transition = 'transform 0.3s'; el.style.transform = ''; });
review guidance
- enforce critical rules first (never patterns, tool boundaries)
- choose the least expensive rendering work that matches the intent
- for any non-default choice, state the constraint that justifies it (surface size, duration, or interaction requirement)
- when reviewing, prefer actionable notes and concrete alternatives over theory
Limitations
- Use this skill only when the task clearly matches its upstream source and local project context.
- Verify commands, generated code, dependencies, credentials, and external service behavior before applying changes.
- Do not treat examples as a substitute for environment-specific tests, security review, or user approval for destructive or costly actions.
1---2name: fixing-motion-performance3description: Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects. Use when animations stutter, transitions jank, or reviewing CSS/JS animation performance.4license: MIT5---6
7# fixing-motion-performance
8## When to Use
9
10Use this skill when you need audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects. Use when animations stutter, transitions jank, or reviewing CSS/JS animation performance.
11
12
13Fix animation performance issues.
14
15## how to use
16
17- `/fixing-motion-performance`
18 Apply these constraints to any UI animation work in this conversation.
19
20- `/fixing-motion-performance <file>`
21 Review the file against all rules below and report:
22 - violations (quote the exact line or snippet)
23 - why it matters (one short sentence)
24 - a concrete fix (code-level suggestion)
25
26Do not migrate animation libraries unless explicitly requested. Apply rules within the existing stack.
27
28## when to apply
29
30Reference these guidelines when:
31- adding or changing UI animations (CSS, WAAPI, Motion, rAF, GSAP)
32- refactoring janky interactions or transitions
33- implementing scroll-linked motion or reveal-on-scroll
34- animating layout, filters, masks, gradients, or CSS variables
35- reviewing components that use will-change, transforms, or measurement
36
37## rendering steps glossary
38
39- composite: transform, opacity
40- paint: color, borders, gradients, masks, images, filters
41- layout: size, position, flow, grid, flex
42
43## rule categories by priority
44
45| priority | category | impact |
46|----------|----------|--------|
47| 1 | never patterns | critical |
48| 2 | choose the mechanism | critical |
49| 3 | measurement | high |
50| 4 | scroll | high |
51| 5 | paint | medium-high |
52| 6 | layers | medium |
53| 7 | blur and filters | medium |
54| 8 | view transitions | low |
55| 9 | tool boundaries | critical |
56
57## quick reference
58
59### 1. never patterns (critical)
60
61- do not interleave layout reads and writes in the same frame
62- do not animate layout continuously on large or meaningful surfaces
63- do not drive animation from scrollTop, scrollY, or scroll events
64- no requestAnimationFrame loops without a stop condition
65- do not mix multiple animation systems that each measure or mutate layout
66
67### 2. choose the mechanism (critical)
68
69- default to transform and opacity for motion
70- use JS-driven animation only when interaction requires it
71- paint or layout animation is acceptable only on small, isolated surfaces
72- one-shot effects are acceptable more often than continuous motion
73- prefer downgrading technique over removing motion entirely
74
75### 3. measurement (high)
76
77- measure once, then animate via transform or opacity
78- batch all DOM reads before writes
79- do not read layout repeatedly during an animation
80- prefer FLIP-style transitions for layout-like effects
81- prefer approaches that batch measurement and writes
82
83### 4. scroll (high)
84
85- prefer Scroll or View Timelines for scroll-linked motion when available
86- use IntersectionObserver for visibility and pausing
87- do not poll scroll position for animation
88- pause or stop animations when off-screen
89- scroll-linked motion must not trigger continuous layout or paint on large surfaces
90
91### 5. paint (medium-high)
92
93- paint-triggering animation is allowed only on small, isolated elements
94- do not animate paint-heavy properties on large containers
95- do not animate CSS variables for transform, opacity, or position
96- do not animate inherited CSS variables
97- scope animated CSS variables locally and avoid inheritance
98
99### 6. layers (medium)
100
101- compositor motion requires layer promotion, never assume it
102- use will-change temporarily and surgically
103- avoid many or large promoted layers
104- validate layer behavior with tooling when performance matters
105
106### 7. blur and filters (medium)
107
108- keep blur animation small (<=8px)
109- use blur only for short, one-time effects
110- never animate blur continuously
111- never animate blur on large surfaces
112- prefer opacity and translate before blur
113
114### 8. view transitions (low)
115
116- use view transitions only for navigation-level changes
117- avoid view transitions for interaction-heavy UI
118- avoid view transitions when interruption or cancellation is required
119- treat size changes as potentially layout-triggering
120
121### 9. tool boundaries (critical)
122
123- do not migrate or rewrite animation libraries unless explicitly requested
124- apply these rules within the existing animation system
125- never partially migrate APIs or mix styles within the same component
126
127## common fixes
128
129```css
130/* layout thrashing: animate transform instead of width */
131/* before */ .panel { transition: width 0.3s; }
132/* after */ .panel { transition: transform 0.3s; }
133
134/* scroll-linked: use scroll-timeline instead of JS */
135/* before */ window.addEventListener('scroll', () => el.style.opacity = scrollY / 500)
136/* after */ .reveal { animation: fade-in linear; animation-timeline: view(); }
137```
138
139```js
140// measurement: batch reads before writes (FLIP)
141// before — layout thrash
142el.style.left = el.getBoundingClientRect().left + 10 + 'px';
143// after — measure once, animate via transform
144const first = el.getBoundingClientRect();
145el.classList.add('moved');
146const last = el.getBoundingClientRect();
147el.style.transform = `translateX(${first.left - last.left}px)`;
148requestAnimationFrame(() => { el.style.transition = 'transform 0.3s'; el.style.transform = ''; });
149```
150
151## review guidance
152
153- enforce critical rules first (never patterns, tool boundaries)
154- choose the least expensive rendering work that matches the intent
155- for any non-default choice, state the constraint that justifies it (surface size, duration, or interaction requirement)
156- when reviewing, prefer actionable notes and concrete alternatives over theory
157
158## Limitations
159
160- Use this skill only when the task clearly matches its upstream source and local project context.
161- Verify commands, generated code, dependencies, credentials, and external service behavior before applying changes.
162- Do not treat examples as a substitute for environment-specific tests, security review, or user approval for destructive or costly actions.