git:20260307.ad5ece6 to git:20261115.40dedaf

65 added, 294 removed. Audit A to A.

What this update changes in the checks

No check changed: every fixed check gives the same answer before and after this update.

A tripped check is a label, not a verdict: read the matched text and the lines below. This week's updates that newly trip a check.

---
name: react-animations
description: >-
- Use when implementing animations, transitions, or motion effects in React apps. Invoke this skill whenever someone asks about animation, transition, motion, framer motion, react spring, GSAP, entrance/exit effects, scroll animation, parallax, gesture, drag, card flip, screen shake, health bar, damage numbers, loading states, page transitions, hover effects, or any element that should move, fade, scale, or respond to interaction — even if they don't use the word "animation".
+ Motion for React (the `motion` package): choosing between CSS and Motion, exit animations, reduced-motion handling, bundle size, and game HUD effects such as health bars, damage numbers, card flips and screen shake. Use when adding or fixing in-component animation in a React app that uses, or should use, Motion. Not for other animation libraries or for route changes.
---
- # React Animations
-
- Production-quality animations in React using Framer Motion (primary), React Spring (physics), GSAP (timelines), and CSS/Tailwind (simple cases).
-
- ## Library Decision Table
-
- | Use Case | Library | Why |
- |---|---|---|
- | Entrance/exit animations | Framer Motion | AnimatePresence handles unmount |
- | Shared element transitions | Framer Motion | layoutId |
- | Physics-based (spring, bounce) | Framer Motion or React Spring | spring config |
- | Complex timelines / sequences | GSAP | Timeline API |
- | Scroll-triggered | Framer Motion (whileInView / useScroll) | Built-in scroll hooks |
- | Simple hover/focus states | CSS Tailwind | No JS needed |
- | Drag and drop | Framer Motion | Built-in gesture support |
- | SVG path animations | GSAP or Framer Motion | Both support SVG |
- | Imperative / programmatic | Framer Motion useAnimate | Modern imperative API |
-
- ## Core Principles
-
- > Matt Perry (Framer Motion creator): "Animations should be declared, not imperatively managed. Describe the target state — the library handles the rest."
- > Sarah Drasner: "Animation is not decoration — it's communication. Every motion should serve a purpose."
-
- 1. **CSS for simple, JS for complex** — if Tailwind `transition` works, use it; don't add Framer Motion for hover states
- 2. **Only animate composited properties** — `transform` and `opacity`; never `width`, `height`, `top`, `left` (causes reflow)
- 3. **AnimatePresence wraps conditional renders** — without it, exit animations are skipped
- 4. **Variants for coordinated animations** — define animation states as objects outside the component, not inline values
- 5. **layoutId for shared element transitions** — Framer Motion handles the interpolation between positions
- 6. **useMotionValue for gesture-driven** — don't use useState for values that drive animations
- 7. **60fps budget** — keep animation logic out of render cycle; use transforms
-
- ## Key Framer Motion Patterns
-
- ### Basic Animate
-
- ```tsx
- <motion.div
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- transition={{ duration: 0.3 }}
- />
- ```
-
- ### Gesture States (whileHover, whileTap)
-
- ```tsx
- <motion.button
- whileHover={{ scale: 1.05 }}
- whileTap={{ scale: 0.95 }}
- transition={{ type: 'spring', stiffness: 400, damping: 17 }}
- />
- ```
-
- ### Variants with Children Stagger
-
- ```tsx
- const container = {
- hidden: { opacity: 0 },
- visible: {
- opacity: 1,
- transition: { staggerChildren: 0.1 },
- },
- };
-
- const item = {
- hidden: { opacity: 0, y: 20 },
- visible: { opacity: 1, y: 0 },
- };
+ # React animations with Motion
- <motion.ul variants={container} initial="hidden" animate="visible">
- {items.map((i) => (
- <motion.li key={i} variants={item} />
- ))}
- </motion.ul>
- ```
+ Motion is the library formerly named Framer Motion. `framer-motion` publishes the same code under the old name, so existing projects keep working. New code installs `motion` and imports from `motion/react`.
- ### AnimatePresence with Exit
+ ## Use the official Motion tooling first
- The `mode` prop controls how entering/exiting elements interact:
- - `"sync"` (default) — enter and exit happen simultaneously
- - `"wait"` — exit completes before enter starts (good for page transitions)
- - `"popLayout"` — exiting element is removed from layout flow immediately
+ Use the `motion` skill (Motion AI Kit) if it is installed, otherwise run `bunx motion-ai` or read https://github.com/motiondivision/ai-kit. It also configures the docs MCP server at https://mcp.motion.dev. For API details, read https://motion.dev/llms.txt. Every docs page serves Markdown when you add `.md` to its URL. This skill keeps only the decisions and the game-UI recipes those sources do not hold.
- ```tsx
- <AnimatePresence mode="wait">
- {isVisible && (
- <motion.div
- key="modal"
- initial={{ opacity: 0, scale: 0.9 }}
- animate={{ opacity: 1, scale: 1 }}
- exit={{ opacity: 0, scale: 0.9 }}
- />
- )}
- </AnimatePresence>
- ```
+ ## Choose the tool
- ### whileInView for Scroll-Triggered Animations
+ | Need | Use |
+ |---|---|
+ | Hover, focus, simple fades | CSS `transition` (Tailwind). Do not add Motion for this. |
+ | Enter and exit of conditional elements, variants, gestures, drag, layout and `layoutId` | `motion` components with `AnimatePresence` |
+ | Values driven by input or game state (bars, counters) | `useMotionValue`, `useSpring`, `useTransform` |
+ | One-off imperative sequences (shake, pulse) | `useAnimate` |
+ | Timelines, ScrollTrigger, SVG drawing | GSAP. Use the `gsap-react` skill. |
+ | Native page and route transitions | The `vercel-react-view-transitions` skill. Use Motion's `AnimateView` (`import { AnimateView } from 'motion/react-animate-view'`, not `motion/react`) only if the project already uses Motion. It needs React and React DOM 19.3 or later. |
- The simplest approach — no scroll hooks needed:
+ ## Setup
- ```tsx
- <motion.div
- initial={{ opacity: 0, y: 40 }}
- whileInView={{ opacity: 1, y: 0 }}
- viewport={{ once: true, margin: '-100px' }}
- transition={{ duration: 0.5 }}
- />
+ ```bash
+ bun add motion
```
- Use `viewport.once: true` so the animation doesn't replay on scroll back.
-
- ### useScroll + useTransform for Parallax
-
```tsx
- const { scrollYProgress } = useScroll();
- const y = useTransform(scrollYProgress, [0, 1], [0, -200]);
-
- <motion.div style={{ y }} />
+ import { motion } from 'motion/react';
```
- ### layoutId Shared Element
-
- ```tsx
- // In list view
- <motion.div layoutId={`card-${id}`}>
- <Thumbnail />
- </motion.div>
+ In a Next.js App Router server file, use `import * as motion from 'motion/react-client'`. Otherwise add `'use client'`.
- // In detail view
- <motion.div layoutId={`card-${id}`}>
- <FullImage />
- </motion.div>
- ```
+ ## Rules that save debugging time
- ### Drag with Constraints
+ 1. Animate `transform` and `opacity`. Animating `width`, `height`, `top` or `left` forces layout work. Use `scaleX`, `scaleY` or the `layout` prop.
+ 2. Wrap conditional elements in `AnimatePresence`, or `exit` never runs. Give each child a stable `key`.
+ 3. Put variants outside the component so they keep one identity.
+ 4. Drive animation values with motion values, not `useState`. Motion values update without re-rendering the component.
+ 5. Do not mix a CSS `transition` and Motion on one element. They fight over the same property.
+ 6. An element animates on mount from its first-rendered values to `animate`. Set `initial` to choose the start. If those values already match `animate`, nothing plays. `initial={false}` renders at the `animate` values with no enter animation.
+ 7. Call `motion.create(Component)` at module level, never inside a render. The component you wrap must forward its `ref`.
- ```tsx
- <motion.div
- drag
- dragConstraints={{ left: -100, right: 100, top: -50, bottom: 50 }}
- dragElastic={0.2}
- whileDrag={{ scale: 1.1 }}
- />
- ```
+ `AnimatePresence` modes: `"sync"` (default), `"wait"` (one child only), `"popLayout"` (custom children must forward `ref`; give the animating parent a non-static `position`).
- ### useAnimate — Imperative Animations (v11+)
+ ## Reduced motion
- Prefer `useAnimate` over `useAnimation` for programmatic sequences. It's scoped to a ref and works with any selector within that scope:
+ Set it once at the app root:
```tsx
- const [scope, animate] = useAnimate();
-
- const handleClick = async () => {
- await animate(scope.current, { scale: 1.2 }, { duration: 0.2 });
- await animate(scope.current, { scale: 1 }, { duration: 0.1 });
- };
-
- <div ref={scope}>
- <button onClick={handleClick}>Click me</button>
- </div>
- ```
-
- ### MotionConfig — Global Animation Settings
-
- Wrap your app (or a subtree) to set defaults like reduced motion or spring presets:
+ import { MotionConfig } from 'motion/react';
- ```tsx
<MotionConfig reducedMotion="user">
<App />
</MotionConfig>
```
- `reducedMotion="user"` automatically disables animations for users with OS-level "reduce motion" preferences. This is the easiest way to handle accessibility at scale.
+ `"user"` turns off transform and layout animations. It keeps animations of other values such as `opacity` and `backgroundColor`. It does not stop every animation. For effects that are large movement by design (shake, parallax, big slides), read `useReducedMotion()` and skip or swap them for a fade. `ScreenShake` in `boilerplate/motion-components.tsx` does this. `"always"` and `"never"` let a user setting override the OS value. `useReducedMotion()` reports the device setting. Do not rely on it to reflect a `MotionConfig` override.
- ### LazyMotion — Bundle Size Optimization
+ ## Bundle size
- For production apps, replace `motion` with `LazyMotion` + `m` to code-split the animation engine:
+ `motion` is about 43 kB gzipped. `LazyMotion` with `m` starts near 5 kB. Add `domAnimation` (+24 kB) for animations, variants, exit and hover, tap and focus gestures. Add `domMax` (+38 kB) for drag and layout animations instead.
```tsx
- import { LazyMotion, domAnimation, m } from 'framer-motion';
+ import { LazyMotion, domAnimation } from 'motion/react';
+ import * as m from 'motion/react-m';
<LazyMotion features={domAnimation}>
<m.div animate={{ opacity: 1 }} />
</LazyMotion>
```
- Use `domMax` instead of `domAnimation` if you need drag or layout animations.
-
- ## Game UI Patterns
-
- ### Health Bar Smooth Tweening
-
- ```tsx
- const motionWidth = useMotionValue(current / max);
- const springWidth = useSpring(motionWidth, { stiffness: 200, damping: 30 });
-
- useEffect(() => {
- motionWidth.set(Math.max(0, Math.min(1, current / max)));
- }, [current, max]);
-
- <motion.div style={{ scaleX: springWidth, transformOrigin: 'left' }} />
- ```
-
- ### Damage Numbers Floating Up
-
- ```tsx
- <motion.span
- initial={{ opacity: 1, y: 0 }}
- animate={{ opacity: 0, y: -60 }}
- transition={{ duration: 0.8, ease: 'easeOut' }}
- onAnimationComplete={onComplete}
- >
- -{damage}
- </motion.span>
- ```
-
- ### Card Flip (rotateY)
-
- ```tsx
- <motion.div animate={{ rotateY: isFlipped ? 180 : 0 }} style={{ perspective: 1000 }}>
- <div style={{ backfaceVisibility: 'hidden' }}>{front}</div>
- <div style={{ backfaceVisibility: 'hidden', rotateY: 180 }}>{back}</div>
- </motion.div>
- ```
-
- ### Screen Shake (useAnimate)
-
- ```tsx
- const [scope, animate] = useAnimate();
-
- const shake = async () => {
- await animate(scope.current, { x: [0, -10, 10, -10, 10, 0] }, { duration: 0.4 });
- };
-
- <div ref={scope}>{children}</div>
- ```
-
- ### Menu Slide-In / Slide-Out
-
- ```tsx
- <AnimatePresence>
- {isOpen && (
- <motion.nav
- initial={{ x: -300 }}
- animate={{ x: 0 }}
- exit={{ x: -300 }}
- transition={{ type: 'spring', stiffness: 300, damping: 30 }}
- />
- )}
- </AnimatePresence>
- ```
-
- ### Inventory Item Drop (Spring Physics)
-
- ```tsx
- <motion.div
- initial={{ y: -200, opacity: 0 }}
- animate={{ y: 0, opacity: 1 }}
- transition={{ type: 'spring', stiffness: 400, damping: 15 }}
- />
- ```
-
- ## Accessibility
-
- Always respect the user's motion preferences. Two approaches:
-
- **1. MotionConfig (recommended for apps)** — wraps your entire component tree:
- ```tsx
- <MotionConfig reducedMotion="user">
- <App />
- </MotionConfig>
- ```
-
- **2. useReducedMotion hook** — for component-level control:
- ```tsx
- const shouldReduceMotion = useReducedMotion();
-
- <motion.div
- animate={{ opacity: 1, y: shouldReduceMotion ? 0 : -20 }}
- />
- ```
-
- ## Performance
-
- - Animate only `transform` and `opacity` — GPU-composited, no layout/paint triggered
- - `will-change: transform` for elements that always animate (promotes to own layer)
- - Use `motion.create(Component)` to animate custom components without wrapper divs
- - `layout` prop triggers automatic layout animations — expensive on large DOM trees; scope to smallest possible subtree
- - Prefer `useMotionValue` over `useState` for animation-driving values — motion values don't trigger re-renders
- - `LazyMotion` with `domAnimation` saves ~15kb gzip vs the full bundle
-
- ## Setup
-
- ```bash
- bun add framer-motion
- ```
-
- Zero-config — no providers required. Import and use `motion.div` directly.
-
- For global accessibility handling, wrap your app root:
- ```tsx
- import { MotionConfig } from 'framer-motion';
+ Pass `strict` to `LazyMotion` to throw if a `motion` component slips in. `useAnimate` has a mini version at `motion/react-mini`, about 3.3 kB, that runs on WAAPI only.
- <MotionConfig reducedMotion="user">
- <App />
- </MotionConfig>
- ```
+ ## Game HUD recipes
- ## Boilerplate
+ The working code is in `boilerplate/motion-components.tsx`. Copy the component, then adjust numbers.
- `boilerplate/motion-components.tsx` — ready-to-use components: `FadeIn`, `SlideIn`, `ScaleIn`, `StaggerList`, `FloatingNumber`, `HealthBar`, `AnimatedCard`
+ | Effect | Component | How it works |
+ |---|---|---|
+ | Health or XP bar | `HealthBar` | `useSpring` on a motion value, applied as `scaleX` with `transformOrigin: 'left'`. Clamp the ratio to 0..1. |
+ | Damage or score pop-up | `FloatingNumber` | Animates `y` and `opacity`, calls `onComplete` so the parent removes it. |
+ | Card flip | `AnimatedCard` | See below. |
+ | Screen shake | `ScreenShake` | `useAnimate` on a keyframe array of `x`, skipped under reduced motion. |
+ | Menu slide | `SlideIn` inside `AnimatePresence` | Ease on `x`; under reduced motion it drops the `x` offset and keeps a short opacity fade. |
- `templates/animation-variants.ts` — reusable variant objects and spring transition presets
+ Card flip needs three things. Put `perspective` on the parent. Put `transformStyle: 'preserve-3d'` on the element that rotates. Give each face `backfaceVisibility: 'hidden'`, with the back face at `transform: 'rotateY(180deg)'`. Animate `rotateY` on the rotating element through `animate`. In Motion `rotateY` is a style shorthand, so a plain `div` needs the `transform` string instead.
- ## Cross-References
+ ## Pitfalls
- - `vercel-react-best-practices` — React performance patterns
- - `ui-ux-game` — game HUD and UI patterns
- - `frontend-design` — component design and Tailwind patterns
+ - Using `AnimatePresence` with `mode="wait"` and several children. It supports one child.
+ - A `motion` component imported from `motion/react` inside a `LazyMotion strict` tree. Import `m` from `motion/react-m`.
+ - Treating `reducedMotion="user"` as "no animation". Opacity and color animations still run.
+ - Putting `perspective` on the rotating element. It must be on the parent.
+ - Exposing an imperative handle from an effect with empty deps. The parent keeps a stale closure. List the handle in the deps, as `ScreenShake` does.
+ - Large `layout` trees. Layout animation measures the DOM. Scope `layout` to the smallest subtree.
+ - Using `useAnimation`. Current docs do not list it. Use `useAnimate`.
+ - Over-animating. Animate to show a state change, not to decorate.
- ## Pitfalls & Anti-Patterns
+ ## Files
- - **Animating layout-triggering properties** (`width`, `height`, `top`, `left`) — use `scaleX`/`scaleY` or the `layout` prop instead
- - **Forgetting AnimatePresence** when using `exit` prop — exit animations silently skip without the wrapper
- - **Creating motion values in render** — use `useMotionValue` hook; creating in render causes memory leaks
- - **Using CSS `transition` AND Framer Motion on same element** — they conflict; pick one
- - **Over-animating** — every interaction animated is sensory overload; animate to communicate, not to decorate
- - **Animating on mount without `initial`** — component flashes before animating; always set `initial`
- - **Using `useAnimation`** — deprecated; use `useAnimate` for imperative animations instead
- - **Large `layout` animations** — `layout` prop on deeply nested trees causes expensive recalculations; scope to smallest possible subtree
- - **Skipping accessibility** — always use `MotionConfig reducedMotion="user"` or `useReducedMotion`
+ - `boilerplate/motion-components.tsx` - copy when you need `FadeIn`, `SlideIn`, `ScaleIn`, `StaggerList`, `FloatingNumber`, `HealthBar`, `AnimatedCard` or `ScreenShake`.
+ - `templates/animation-variants.ts` - copy when you want shared variant objects, spring presets or a stagger container factory.
+ - `references/sources.md` - read when you need the page behind a claim in this skill.
- ## Sources
+ ## Related skills
- - Framer Motion documentation — https://motion.dev
- - Matt Perry — Framer Motion creator, API design talks
- - Sarah Drasner — "SVG Animations", animation design patterns
- - GSAP documentation — https://gsap.com
+ - `gsap-react` - timelines, ScrollTrigger and SVG drawing.
+ - `vercel-react-view-transitions` - native page and route transitions.
+ - `ui-ux-game` - HUD layout and game UI patterns.
+ - `vercel-react-best-practices` - React performance patterns.