From 6ec8b5b36f4dfc235d4c99c54a58a7b519cd4c00 Mon Sep 17 00:00:00 2001 From: Rob Wise Date: Wed, 11 Oct 2017 10:36:34 -0400 Subject: [PATCH] Don't handleScroll after component has unmounted `handleScroll` is throttled by 200ms, so it's often the case that the listener gets fired after the component has already unmounted and removed the listener. Adding this guard clause protects against this. --- src/scroll-animation.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/scroll-animation.js b/src/scroll-animation.js index cec1ee1..15eceee 100644 --- a/src/scroll-animation.js +++ b/src/scroll-animation.js @@ -36,15 +36,18 @@ export default class ScrollAnimation extends Component { elementTop: this.node.getBoundingClientRect().top + ScrollAnimation.posTop() }, this.handleScroll); this.handleScroll(); + this.isMounted = true; } componentWillUnmount() { if (window && window.addEventListener) { window.removeEventListener("scroll", this.listener); } + this.isMounted = false; } handleScroll() { + if (!this.isMounted) return; const visible = this.isVisible(); if (!visible.partially) { this.state.timeouts.forEach(function (tid) {