jlmakes / scrollreveal

Animate elements as they scroll into view.
https://scrollrevealjs.org/
22.35k stars 2.26k forks source link

Calling sr.clean() during scroll throws uncaught TypeError #349

Closed jlmakes closed 6 years ago

jlmakes commented 7 years ago

ScrollReveal v4.0.0-beta.6

The sr.clean(selector) works as intended (deleting elements and unbinding event handlers), but if called during scroll can remove elements that are still being worked on by the last call of the event handler.

Uncaught TypeError: Cannot read property 'bounds' of undefined
    at ScrollReveal.isElementVisible (scrollreveal.js:172)
    at ScrollReveal.animate (scrollreveal.js:1029)
    at scrollreveal.js:1218
    at each (scrollreveal.js:80)
    at scrollreveal.js:1218
isElementVisible @ scrollreveal.js:172
animate @ scrollreveal.js:1029
(anonymous) @ scrollreveal.js:1218
each @ scrollreveal.js:80
(anonymous) @ scrollreveal.js:1218
jlmakes commented 7 years ago

I can reproduce this using JSBin, but not in my local environment! (Argh!)

From my tinkering, it seems the ScrollReveal store is being nuked by clean() or destroy() midway through looping over elements, so isElementVisible() attempts to access element and container data that no longer exists.