Bug 1462229 - Part 1: Avoid updating the state of removed animation. r?gl draft
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Mon, 28 May 2018 08:57:16 +0900
changeset 800405 57019660f2fac0f07804e1fe8b6bf4d3fe35dac8
parent 800404 db78be8dbc1c81844eb7d35c1a3073078eb5d923
child 800406 cef0e7c556903400248a0daf75d323eea19cfde1
push id111342
push userbmo:dakatsuka@mozilla.com
push dateMon, 28 May 2018 00:23:27 +0000
reviewersgl
bugs1462229
milestone62.0a1
Bug 1462229 - Part 1: Avoid updating the state of removed animation. r?gl MozReview-Commit-ID: IAdHpqXe4Ta
devtools/client/inspector/animation/animation.js
--- a/devtools/client/inspector/animation/animation.js
+++ b/devtools/client/inspector/animation/animation.js
@@ -286,34 +286,40 @@ class AnimationInspector {
     if (shouldStop) {
       this.setAnimationsCurrentTime(currentTime, true);
     } else {
       this.onAnimationsCurrentTimeUpdated(currentTime);
     }
   }
 
   async onAnimationsMutation(changes) {
-    const animations = [...this.state.animations];
-
-    // Update other animations as well since the currentTime would be proceeded.
-    // Because the scrubber position is related the currentTime.
-    await this.updateAnimations(animations);
+    let animations = [...this.state.animations];
+    const addedAnimations = [];
 
     for (const {type, player: animation} of changes) {
       if (type === "added") {
-        animations.push(animation);
+        addedAnimations.push(animation);
         animation.on("changed", this.onAnimationStateChanged);
       } else if (type === "removed") {
         const index = animations.indexOf(animation);
         animations.splice(index, 1);
         animation.off("changed", this.onAnimationStateChanged);
       }
     }
 
-    this.updateState(animations);
+    // Update existing other animations as well since the currentTime would be proceeded
+    // sice the scrubber position is related the currentTime.
+    // Also, don't update the state of removed animations since React components
+    // may refer to the same instance still.
+    await this.updateAnimations(animations);
+
+    // Get rid of animations that were removed during async updateAnimations().
+    animations = animations.filter(animation => !!animation.state.type);
+
+    this.updateState(animations.concat(addedAnimations));
   }
 
   onElementPickerStarted() {
     this.inspector.store.dispatch(updateElementPickerEnabled(true));
   }
 
   onElementPickerStopped() {
     this.inspector.store.dispatch(updateElementPickerEnabled(false));