-
Notifications
You must be signed in to change notification settings - Fork 121
Open
Description
🐛 Describe the bug
The animation loop created using requestAnimationFrame in App.js is never cancelled when the component unmounts.
As a result, the RAF loop continues executing after unmount, while lenis.destroy() is called during cleanup. This can lead to runtime errors, unnecessary CPU usage, and memory leaks.
Location
- File:
src/App.js - Hook:
useEffect
Steps to Reproduce
- Run the application locally.
- Trigger a component unmount (e.g., route change, hot reload, or conditional rendering).
- Observe that the animation loop continues running after unmount.
Expected Behavior
- The
requestAnimationFrameloop should be properly cancelled during the cleanup phase. - No animation callbacks should execute after
lenis.destroy().
Actual Behavior
- The RAF loop continues after component unmount.
lenis.raf(time)may be invoked on a destroyed Lenis instance.- This can cause:
- Memory leaks
- Console errors
- Unstable behavior over time
Root Cause
The ID returned by requestAnimationFrame is not stored, and cancelAnimationFrame is never called in the useEffect cleanup function.
Proposed Fix
Store the RAF ID and cancel it during cleanup.
Impact
- Prevents memory leaks
- Avoids runtime errors after unmount
- Improves overall application stability and performance
Environment
- React
- Lenis
- Browser: All major browsers
- OS: Platform independent
Additional Notes
This issue becomes more impactful when using smooth-scrolling libraries like Lenis, as destroyed instances may still receive animation frame callbacks if not properly cancelled.
I am willing to submit a PR.
Metadata
Metadata
Assignees
Labels
No labels