destroy() can restore the lenis class after a native scroll timeout
I can reproduce this with Lenis 1.3.26 and Chromium 148.0.7778.96. After a native scroll, destroy() removes the root classes, but lenis returns about 400ms later. This leaves the class present after the instance is gone, including when destroying an instance to enable reduced motion.
Run this in a browser module with Lenis installed and enough content to scroll:
import Lenis from 'lenis'
document.body.style.minHeight = '4000px'
const lenis = new Lenis()
const scrolled = new Promise((resolve) => {
const off = lenis.on('scroll', () => {
if (lenis.isScrolling === 'native' && lenis.velocity !== 0) {
off()
resolve()
}
})
})
window.scrollTo(0, 200)
await scrolled
lenis.destroy()
console.log(document.documentElement.className)
await new Promise((resolve) => setTimeout(resolve, 600))
console.log(document.documentElement.className)On a page without other root classes, the first log is empty and the second is lenis. I expect both to be empty.
In the source, onNativeScroll schedules _resetVelocityTimeout. destroy() removes listeners and classes without clearing that timeout. Its callback sets isScrolling to false, and the setter updates the root classes after destruction.
As a diagnostic, calling the internal reset() before destroy() leaves both logs empty. Clearing the pending native-scroll timeout during destruction would prevent the callback itself from running. I reproduced this in an isolated page without a framework or animation loop.
Source: darkroomengineering/lenis