The Complete Production SOP: How to Deploy and Run Lottie-Web JSON Vector Animation Engine in Autonomous AI Agents
Production SOP to install and run Lottie-Web vector animations in Codex, Claude Code, & Cursor. Includes memory leak prevention, scroll scrubbing, and fixes.
Technical Overview & Architectural Context
Autonomous coding agents frequently make catastrophic performance and lifecycle mistakes when implementing Lottie vector animations. Unconstrained LLMs commonly bundle entire raw Bodymovin JSON schemas directly into client component codebases, fail to register cleanup hooks leading to severe DOM memory leaks, and configure continuous loop rendering on off-screen elements that throttle mobile CPUs to 100% capacity. Furthermore, agents often omit SSR guards, triggering hydration mismatches in Next.js or Remix when `window` is accessed before mount. The Lottie-Web JSON Vector Animation Engine skill injects deterministic SOP boundaries directly into agent context windows across Codex, Claude Code, Cursor, and Windsurf. By enforcing strict constraints—such as mandating `animationInstance.destroy()` in React `useEffect` cleanups, applying `IntersectionObserver` wrappers for viewport virtualization, selecting the optimal renderer (`svg` vs `canvas`) based on particle density, and orchestrating frame-bound segments via `playSegments`—agents deliver production-grade, 60fps animations without human intervention.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local skill manifest directory and inject verified procedural rules into the agent runtime directory.
Agent runtimes like Claude Code, Cursor, and Codex automatically scan `.agents/skills` or `.claude/skills` for deterministic instruction sets. Mounting this skill registers triggers like 'play lottie animation react' and 'scrub lottie on scroll' so the agent executes vector renders using production lifecycle patterns instead of hallucinated snippets.
mkdir -p .agents/skills/lottie-web-vector-animations && curl -fsSL https://askills.dev/api/skills/lottie-web-vector-animations/raw -o .agents/skills/lottie-web-vector-animations/SKILL.md---
name: "lottie-web-vector-animations"
description: "Render lightweight, scalable After Effects vector animations on the web with Lottie."
metadata:
author: "Airbnb"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "play lottie animation react"
- "trigger lottie on hover"
- "scrub lottie on scroll"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# Lottie-Web JSON Vector Animation Engine
Embeds Bodymovin JSON animation files using lottie-web / @lottiefiles/react-lottie-player: canvas/SVG renderers, frame markers, scroll scrubbing, and interactive hover triggers.
## Execution SOP & Rules
1. Prefer renderer: 'svg' for crisp vector shapes; use renderer: 'canvas' for complex particle scenes.
2. Pause animations when off-screen using IntersectionObserver to conserve mobile CPU cycles.
3. Trigger specific animation segments using animationInstance.playSegments([startFrame, endFrame], true).
4. Destroy animation instances with animationInstance.destroy() during component teardown.Keep the SKILL.md file locked in your repository's root `.agents/skills/` directory so all team members and CI coding agents inherit identical performance guidelines without wasting LLM tokens.
Ensure `fs_write` is constrained to `workspace`. Granting agents global filesystem permissions risks accidental overwrites outside the target project directory.
Dependency Installation & Runtime Asset Verification
Install official Lottie web bindings and establish asset directory boundaries for Bodymovin JSON files.
Autonomous agents should not install redundant wrapper packages. Enforce the official `lottie-web` engine or `@lottiefiles/dotlottie-react` depending on asset packaging. Also, store JSON animation data under `public/animations/` to enable streaming fetch requests rather than bloating client JS bundle sizes.
pnpm add lottie-web && mkdir -p public/animations{
"dependencies": {
"lottie-web": "^5.12.2",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/lottie-web": "^5.12.0",
"typescript": "^5.4.5"
}
}Instruct the agent to load Lottie JSON files via URL paths (e.g., `/animations/hero.json`) instead of `import heroData from './hero.json'` to prevent massive bundler tree-shaking failures.
Do not commit uncompressed 5MB+ Bodymovin JSON files into the source tree; require the agent to verify JSON size or suggest dotLottie (.lottie) compression.
Deterministic Implementation & Trigger Execution
Execute user trigger prompts to generate type-safe, lifecycle-managed Lottie components.
When prompted with triggers like 'trigger lottie on hover' or 'scrub lottie on scroll', the agent executes Step 1-4 of the SOP: creating a container reference, loading the animation instance, binding event listeners or scroll observers, and providing a clean unmount tear-down.
touch src/components/LottieInteractivePlayer.tsx"use client";
import React, { useEffect, useRef } from "react";
import lottie, { AnimationItem } from "lottie-web";
interface LottiePlayerProps {
animationPath: string;
loop?: boolean;
autoplay?: boolean;
hoverTrigger?: boolean;
className?: string;
}
export const LottieInteractivePlayer: React.FC<LottiePlayerProps> = ({
animationPath,
loop = false,
autoplay = false,
hoverTrigger = false,
className = "w-64 h-64",
}) => {
const containerRef = useRef<HTMLDivElement | null>(null);
const animInstanceRef = useRef<AnimationItem | null>(null);
useEffect(() => {
if (!containerRef.current) return;
// Initialize Lottie
const anim = lottie.loadAnimation({
container: containerRef.current,
renderer: "svg",
loop,
autoplay,
path: animationPath,
});
animInstanceRef.current = anim;
// IntersectionObserver to pause off-screen rendering
const observer = new IntersectionObserver(([entry]) => {
if (!animInstanceRef.current) return;
if (entry.isIntersecting) {
if (autoplay) animInstanceRef.current.play();
} else {
animInstanceRef.current.pause();
}
}, { threshold: 0.1 });
observer.observe(containerRef.current);
return () => {
observer.disconnect();
anim.destroy();
animInstanceRef.current = null;
};
}, [animationPath, loop, autoplay]);
const handleMouseEnter = () => {
if (hoverTrigger && animInstanceRef.current) {
animInstanceRef.current.setDirection(1);
animInstanceRef.current.play();
}
};
const handleMouseLeave = () => {
if (hoverTrigger && animInstanceRef.current) {
animInstanceRef.current.setDirection(-1);
animInstanceRef.current.play();
}
};
return (
<div
ref={containerRef}
className={className}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
aria-hidden="true"
/>
);
};Use `anim.setDirection(1)` and `anim.setDirection(-1)` on hover interactions to smoothly reverse vector animations without jarring jumps or frame skips.
In React 18 Strict Mode in development, `useEffect` triggers twice. Failure to call `anim.destroy()` in the return statement causes duplicate stacked SVG layers rendering simultaneously.
Verification, Linting & Memory Leak Audit
Run TypeScript compiler checks and automated tests verifying instance destruction and zero DOM leakages.
Instruct the agent to run the workspace test suite and verify that component unmounting successfully cleans up animation references and removes SVG/Canvas nodes from the DOM.
pnpm tsc --noEmit && pnpm test -- --runimport { render, screen } from "@testing-library/react";
import { describe, it, expect, vi } from "vitest";
import { LottieInteractivePlayer } from "../LottieInteractivePlayer";
import lottie from "lottie-web";
vi.mock("lottie-web", () => ({
default: {
loadAnimation: vi.fn().mockReturnValue({
destroy: vi.fn(),
play: vi.fn(),
pause: vi.fn(),
setDirection: vi.fn(),
}),
},
}));
describe("LottieInteractivePlayer", () => {
it("initializes and destroys lottie instance on unmount", () => {
const { unmount } = render(
<LottieInteractivePlayer animationPath="/animations/test.json" />
);
expect(lottie.loadAnimation).toHaveBeenCalledTimes(1);
unmount();
const animInstance = vi.mocked(lottie.loadAnimation).mock.results[0].value;
expect(animInstance.destroy).toHaveBeenCalledTimes(1);
});
});Require the agent to output the test coverage result confirming 100% cleanup pass rate before issuing pull request or marking the task finished.
Check `window` or DOM access if running inside Next.js Server Components. Ensure the component contains `"use client"` at the top of the file.
Real-World Scenario: Interactive Scroll-Linked Product Feature Section in Next.js
“Create a high-performance feature component in Next.js using lottie-web. Load '/animations/feature-reveal.json', pause it when scrolled out of view, and scrub the animation progress smoothly based on the container scroll position from 0% to 100%. Ensure no memory leaks or double-renders occur.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent attempted to invoke `lottie.loadAnimation` during Next.js Server-Side Rendering (SSR) where DOM globals like `window` and `document` do not exist.
Add 'use client'; to the file header or wrap the component with dynamic import: const DynamicLottie = dynamic(() => import('@/components/LottieInteractivePlayer'), { ssr: false });Root Cause: Asynchronous animation assets loaded after the React component unmounted, causing the agent's callback to invoke methods on a destroyed or nullified animation reference.
let isMounted = true; const anim = lottie.loadAnimation({...}); anim.addEventListener('DOMLoaded', () => { if (isMounted) anim.playSegments([0, 60], true); }); return () => { isMounted = false; anim.destroy(); };Frequently Asked Questions (Lottie-Web JSON Vector Animation Engine SOP)
Q:Can I use Lottie-Web JSON Vector Animation Engine across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification supported across all modern agent runtimes. Simply place the file in `.agents/skills/lottie-web-vector-animations/SKILL.md` and any runtime operating on the workspace will parse the frontmatter triggers and SOP.
Q:How does Lottie-Web JSON Vector Animation Engine prevent context window overflow during long agent sessions?
By establishing concise procedural boundaries and deterministic validation gates rather than polluting system prompts with redundant rules. It defines 4 strict execution tenets (SVG vs canvas, IntersectionObserver, segment controls, and destruction) so the agent does not output verbose exploratory reasoning.
Q:Does this skill require escalated root or container permissions?
No. It is audited with a security score of 98/100 and runs safely within workspace-scoped sandboxes with `net_access: false` and `shell_exec: false`.
Ready to equip your autonomous agent with Lottie-Web JSON Vector Animation Engine?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.