]> cat aescling's git repositories - mastodon.git/commitdiff
Do not call setState from unmounted component (#3853)
authoralpaca-tc <alpaca-tc@alpaca.tc>
Tue, 20 Jun 2017 18:37:09 +0000 (03:37 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Tue, 20 Jun 2017 18:37:09 +0000 (20:37 +0200)
Stop an executing task if the component already unmounted.

app/javascript/mastodon/components/status.js

index 17f2eb9d30fb8dc7378b2848133bfc827ecae47b..8c444396743d685d55cd0dfeec58de822de1ad6b 100644 (file)
@@ -86,6 +86,8 @@ class Status extends ImmutablePureComponent {
       this.node,
       this.handleIntersection
     );
+
+    this.componentMounted = true;
   }
 
   componentWillUnmount () {
@@ -96,6 +98,8 @@ class Status extends ImmutablePureComponent {
     }
 
     this.props.intersectionObserverWrapper.unobserve(this.props.id, this.node);
+
+    this.componentMounted = false;
   }
 
   handleIntersection = (entry) => {
@@ -116,6 +120,10 @@ class Status extends ImmutablePureComponent {
   }
 
   hideIfNotIntersecting = () => {
+    if (!this.componentMounted) {
+      return;
+    }
+
     // When the browser gets a chance, test if we're still not intersecting,
     // and if so, set our isHidden to true to trigger an unrender. The point of
     // this is to save DOM nodes and avoid using up too much memory.