Wrap _performComponentUpdate call in try/finally
Fixes #208. If you attempt a state update with a bad state then the render will fail (and the DOM won't change) but if you switch back to a valid state later then it'll rerender properly.
Ben Alpert committed
Jan 14, 2014 at 20:30 UTC
091534c3765a2cf038f1df7f8f96ae01985694ef
1 file changed
+27
-23
src/core/ReactCompositeComponent.js
+27
-23
@@ -949,30 +949,34 @@ var ReactCompositeComponentMixin = {
949
var nextState = this._pendingState || this.state;
950
this._pendingState = null;
951
952
- if (this._pendingForceUpdate ||
953
- !this.shouldComponentUpdate ||
954
- this.shouldComponentUpdate(nextProps, nextState, nextContext)) {
955
- this._pendingForceUpdate = false;
956
- // Will set `this.props`, `this.state` and `this.context`.
957
- this._performComponentUpdate(
958
- nextProps,
959
- nextOwner,
960
- nextState,
961
- nextFullContext,
962
- nextContext,
963
- transaction
964
- );
965
- } else {
966
- // If it's determined that a component should not update, we still want
967
- // to set props and state.
968
- this.props = nextProps;
969
- this._owner = nextOwner;
970
- this.state = nextState;
971
- this._currentContext = nextFullContext;
972
- this.context = nextContext;
952
+ try {
953
+ if (this._pendingForceUpdate ||
954
+ !this.shouldComponentUpdate ||
955
+ this.shouldComponentUpdate(nextProps, nextState, nextContext)) {
956
+ this._pendingForceUpdate = false;
957
+ // Will set `this.props`, `this.state` and `this.context`.
958
+ this._performComponentUpdate(
959
+ nextProps,
960
+ nextOwner,
961
+ nextState,
962
+ nextFullContext,
963
+ nextContext,
964
+ transaction
965
+ );
966
+ } else {
967
+ // If it's determined that a component should not update, we still want
968
+ // to set props and state.
969
+ this.props = nextProps;
970
+ this._owner = nextOwner;
971
+ this.state = nextState;
972
+ this._currentContext = nextFullContext;
973
+ this.context = nextContext;
974
+ }
975
+ } catch (e) {
976
+ throw e;
977
+ } finally {
978
+ this._compositeLifeCycleState = null;
979
}
974
-
975
- this._compositeLifeCycleState = null;
980
},
981
982
/**