diff --git a/apps/webapp/app/components/primitives/Timeline.tsx b/apps/webapp/app/components/primitives/Timeline.tsx index 9b685fd1f..16a2cd6ed 100644 --- a/apps/webapp/app/components/primitives/Timeline.tsx +++ b/apps/webapp/app/components/primitives/Timeline.tsx @@ -75,12 +75,24 @@ export function MousePositionProvider({ children }: { children: ReactNode }) { }, [computeFromClient]); useEffect(() => { - if (position === undefined || !lastClient.current) return; + if (position === undefined || !lastClient.current || !ref.current) return; + + const isAnimating = () => { + if (!ref.current) return false; + const styles = window.getComputedStyle(ref.current); + return styles.transition !== "none" || styles.animation !== "none"; + }; const tick = () => { const lc = lastClient.current; - if (lc) computeFromClient(lc.clientX, lc.clientY); - rafId.current = requestAnimationFrame(tick); + if (lc) { + computeFromClient(lc.clientX, lc.clientY); + if (isAnimating()) { + rafId.current = requestAnimationFrame(tick); + } else { + rafId.current = null; + } + } }; rafId.current = requestAnimationFrame(tick);