---
name: fixing-motion-performance
description: Optimize CSS animations, React rendering, and bundle performance. Invoke for animation jank, slow renders, large bundle size, or transition issues.
user-invocable: true
title: fixing-motion-performance
canonical_url: https://skilld.dev/gh/colaberryintern/colaberryenterprise_ai_leadershipaccelerator/fixing-motion-performance
last_updated: 2026-10-08T09:39:34.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install colaberryintern/colaberryenterprise_ai_leadershipaccelerator/fixing-motion-performance`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/fixing-motion-performance`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/colaberryintern/colaberryenterprise_ai_leadershipaccelerator/fixing-motion-performance) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/fixing-motion-performance`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/fixing-motion-performance --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/fixing-motion-performance --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Fixing Motion & Performance

## Before You Start

1. Read the target file(s) to understand current implementation.
2. Read `frontend/src/styles/global.css` for existing animation patterns.
3. Read `frontend/src/styles/responsive.css` for the `prefers-reduced-motion` rule.

---

## CSS Animation Rules

### GPU-Composited Properties Only
Only animate properties that trigger compositing, not layout or paint:

| Safe (Composite) | Avoid (Layout/Paint) |
|---|---|
| `transform` | `width`, `height` |
| `opacity` | `top`, `left`, `right`, `bottom` |
| `filter` | `margin`, `padding` |
| | `border-width` |
| | `font-size` |

### Transition Duration Limits
- **Micro-interactions** (hover, focus): 150–250ms
- **Content transitions** (fade, slide): 250–400ms
- **Maximum**: 600ms — anything longer feels sluggish
- **Easing**: `ease-out` for entrances, `ease-in` for exits, `ease` for hover states

### Existing Animation Patterns (global.css)

**Card lift** (`.card-lift`):
```css
transition: transform 0.25s ease, box-shadow 0.25s ease;
/* hover: translateY(-4px) + deeper shadow */
```

**Fade-in section** (`.fade-in-section`):
```css
opacity: 0;
transform: translateY(24px);
transition: opacity 0.6s ease-out, transform 0.6s ease-out;
/* .is-visible: opacity 1, translateY(0) */
```

### Respect prefers-reduced-motion
The project already has a global rule in `responsive.css`:
```css
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
```

For JavaScript animations, check the preference:
```ts
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
```

---

## React Rendering Optimization

### Memoize Expensive Computations
```tsx
// Before: recalculates on every render
const filtered = leads.filter(l => l.status === filterStatus);
const sorted = filtered.sort((a, b) => b.score - a.score);

// After: only recalculates when dependencies change
const filtered = useMemo(
  () => leads.filter(l => l.status === filterStatus).sort((a, b) => b.score - a.score),
  [leads, filterStatus]
);
```

### Stabilize Callback References
```tsx
// Before: new function every render, causes child re-renders
<LeadRow onRemove={(id) => handleRemove(id)} />

// After: stable reference
const handleRemoveCallback = useCallback((id: number) => handleRemove(id), []);
<LeadRow onRemove={handleRemoveCallback} />
```

### Memo List Item Components
```tsx
// Wrap frequently re-rendered list items
const LeadRow = React.memo(function LeadRow({ lead, onRemove }: Props) {
  return <tr>...</tr>;
});
```

### Lazy-Load Heavy Libraries (Recharts)
```tsx
import { lazy, Suspense } from 'react';

const AnalyticsTab = lazy(() => import('./components/campaign/AnalyticsTab'));

// Usage
<Suspense fallback={<div className="spinner-border text-primary" />}>
  <AnalyticsTab analytics={analytics} loading={analyticsLoading} />
</Suspense>
```

### Avoid Unnecessary State Updates
```tsx
// Before: causes re-render even if value hasn't changed
setFilterStatus(e.target.value);

// After: skip if unchanged
const newVal = e.target.value;
if (newVal !== filterStatus) setFilterStatus(newVal);
```

---

## Bundle Performance

### Named Imports (Tree-Shaking)
```tsx
// Before: imports entire library
import * as Recharts from 'recharts';

// After: named imports allow tree-shaking
import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts';
```

### Check for Duplicate Dependencies
```bash
# Identify duplicates in node_modules
npx npm-dedupe
# Or check bundle
npx webpack-bundle-analyzer dist/static/js/*.js
```

### Image Optimization
- Use WebP format where possible
- Lazy-load below-the-fold images: `loading="lazy"`
- Set explicit `width` and `height` to prevent layout shift

---

## Diagnostic Checklist

When called to investigate a performance issue:

1. **Identify the symptom**: jank, slow load, large bundle, unresponsive UI
2. **Read the target file(s)** to understand current implementation
3. **Check for**:
   - Layout-triggering animations (non-composited properties)
   - Missing `useMemo` / `useCallback` on expensive operations
   - Unnecessary re-renders (new object/array references in props)
   - Large synchronous data processing in render
   - Unthrottled event handlers (scroll, resize, input)
   - Missing lazy loading for heavy components
4. **Apply fixes** using the patterns above
5. **Verify** `prefers-reduced-motion` is still respected after changes
