Bug 1438755 - Part 1: Avoid updating while the state of SummaryGraphPath component is updating asynchronously. r?gl draft
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Tue, 20 Mar 2018 14:42:18 +0900
changeset 769825 34a24c0b00e28a5fa7f0671e7e66ea17daf1e252
parent 769824 7a1e55aa1a6b3bacede832a123c29b7ae68fd3c3
child 769826 9845e068570464539220ffd22a7983dfc7ba0c59
push id103228
push userbmo:dakatsuka@mozilla.com
push dateTue, 20 Mar 2018 06:02:17 +0000
reviewersgl
bugs1438755
milestone61.0a1
Bug 1438755 - Part 1: Avoid updating while the state of SummaryGraphPath component is updating asynchronously. r?gl MozReview-Commit-ID: ERRkCdhEO9x
devtools/client/inspector/animation/components/graph/SummaryGraphPath.js
--- a/devtools/client/inspector/animation/components/graph/SummaryGraphPath.js
+++ b/devtools/client/inspector/animation/components/graph/SummaryGraphPath.js
@@ -30,29 +30,38 @@ class SummaryGraphPath extends PureCompo
   }
 
   constructor(props) {
     super(props);
 
     this.state = {
       // Duration which can display in one pixel.
       durationPerPixel: 0,
+      // To avoid rendering while the state is updating
+      // since we call an async function in updateState.
+      isStateUpdating: false,
       // List of keyframe which consists by only offset and easing.
       keyframesList: [],
     };
   }
 
   componentDidMount() {
+    // No need to set isStateUpdating state since paint sequence is finish here.
     this.updateState(this.props.animation);
   }
 
   componentWillReceiveProps(nextProps) {
+    this.setState({ isStateUpdating: true });
     this.updateState(nextProps.animation);
   }
 
+  shouldComponentUpdate(nextProps, nextState) {
+    return !nextState.isStateUpdating;
+  }
+
   /**
    * Return animatable keyframes list which has only offset and easing.
    * Also, this method remove duplicate keyframes.
    * For example, if the given animatedPropertyMap is,
    * [
    *   {
    *     key: "color",
    *     values: [
@@ -160,17 +169,23 @@ class SummaryGraphPath extends PureCompo
     }
 
     const keyframesList = this.getOffsetAndEasingOnlyKeyframes(animatedPropertyMap);
 
     const thisEl = ReactDOM.findDOMNode(this);
     const totalDuration = this.getTotalDuration(animation, timeScale);
     const durationPerPixel = totalDuration / thisEl.parentNode.clientWidth;
 
-    this.setState({ durationPerPixel, keyframesList });
+    this.setState(
+      {
+        durationPerPixel,
+        isStateUpdating: false,
+        keyframesList
+      }
+    );
 
     emitEventForTest("animation-summary-graph-rendered");
   }
 
   render() {
     const { durationPerPixel, keyframesList } = this.state;
 
     if (!durationPerPixel) {