Animation Library Exploration
This page showcases proof-of-concept implementations for different animation approaches in our DSA visualization playgrounds.
Current Setup
We currently use Framer Motion (v12.23.24) for all animations. This exploration evaluates:
- LazyMotion Optimization - Reduce bundle size from ~32KB to ~5.5KB
- React Spring - Physics-based animations with
useTrailfor arrays - GSAP - Timeline-based orchestration for complex sequences
- Comparison - Side-by-side evaluation of all approaches
Option A: LazyMotion Optimization
Demonstrates how to reduce Framer Motion bundle size by ~80% using LazyMotion and the m component.
Key Benefits:
- Bundle size: ~5.5KB (vs ~32KB full)
- Same API, just use
minstead ofmotion - Tree-shakeable - only loads what you use
Option B: React Spring
Physics-based animations with natural motion feel. Uses useTrail for staggered array animations.
Key Benefits:
- Physics-based (tension, friction) instead of duration
useTrailfor natural staggered animations- No re-render overhead - runs on RAF
Option C: GSAP Timeline
True timeline control with precise orchestration. Best for complex multi-element choreography.
Key Benefits:
- Global timeline with labels and markers
- Precise timing control (
"<0.5"= 0.5s before previous ends) useGSAP()hook for React integration- 100% FREE (all plugins included)
Option D: Side-by-Side Comparison
Direct comparison of the same swap animation implemented with all three libraries.
Recommendation
| Scenario | Recommended Library |
|---|---|
| Most playgrounds | Framer Motion with LazyMotion |
| Array traversals | React Spring useTrail (optional) |
| Complex sorting | GSAP Timeline (optional) |
| Current approach | Keep Framer Motion, add LazyMotion optimization |
Immediate Action Items
- Add LazyMotion wrapper to
PlaygroundContainercomponent - Replace
motionwithmin existing components for tree-shaking - Consider GSAP only for sorting algorithm playgrounds with complex swaps
Installation (if proceeding with full implementation)
# React Spring (optional)
npm install @react-spring/web
# GSAP (optional)
npm install gsap @gsap/react