| name | frontend-scene-timeline-playback |
| description | Use when implementing or modifying timeline playback, animation loops, or audio synchronization in the Scene Editor |
Frontend: Scene Timeline Playback
Guidelines for implementing smooth, performant playback in the Scene Editor timeline. Covers RAF architecture, audio sync, and common pitfalls.
Critical Rule: Single RAF Loop Architecture
NEVER create multiple independent requestAnimationFrame loops for the same feature.
The Scene Editor uses a single RAF loop in PageScene_Timeline.tsx that:
- Advances time based on
performance.now() delta
- Updates
timelineTimeRef.current (the source of truth)
- Updates playhead DOM directly (no React re-renders)
- Updates time display DOM directly
Why Multiple RAF Loops Are Bad
useEffect(() => {
const tick = () => {
syncAudio(timelineTimeRef.current);
rafRef.current = requestAnimationFrame(tick);
};
rafRef.current = requestAnimationFrame(tick);
}, []);