Skip to content

Commit

Permalink
Fix a race condition in the animation module
Browse files Browse the repository at this point in the history
Summary:
update() is called from the choreographer, so it can be
invoked asynchronously relative to RN.  If it's called while the node
tree is incomplete, this can be called with no parent.  Don't treat an
unparented node as an invariant failure, just skip over it.

Reviewed By: AaaChiuuu

Differential Revision: D6249038

fbshipit-source-id: d22807dff1659bf29a81893ab97d0fe7c19de512
  • Loading branch information
mhorowitz authored and facebook-github-bot committed Nov 6, 2017
1 parent 1ee64cc commit 515eb0e
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/**
* Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
*
* <p>This source code is licensed under the BSD-style license found in the LICENSE file in the root
* directory of this source tree. An additional grant of patent rights can be found in the PATENTS
* file in the same directory.
*/
package com.facebook.react.animated;

import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;

import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -133,8 +139,9 @@ public void onDetachedFromNode(AnimatedNode parent) {
@Override
public void update() {
if (mParent == null) {
throw new IllegalStateException("Trying to update interpolation node that has not been " +
"attached to the parent");
// The graph is in the middle of being created, just skip this
// unattached node.
return;
}
mValue = interpolate(mParent.getValue(), mInputRange, mOutputRange, mExtrapolateLeft, mExtrapolateRight);
}
Expand Down

0 comments on commit 515eb0e

Please sign in to comment.