From 091534c3765a2cf038f1df7f8f96ae01985694ef Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Tue, 14 Jan 2014 20:30:07 -0800 Subject: [PATCH] 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. --- src/core/ReactCompositeComponent.js | 50 ++++++++++++++++------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/src/core/ReactCompositeComponent.js b/src/core/ReactCompositeComponent.js index fab9ffd78db..dc01652dc45 100644 --- a/src/core/ReactCompositeComponent.js +++ b/src/core/ReactCompositeComponent.js @@ -949,30 +949,34 @@ var ReactCompositeComponentMixin = { var nextState = this._pendingState || this.state; this._pendingState = null; - if (this._pendingForceUpdate || - !this.shouldComponentUpdate || - this.shouldComponentUpdate(nextProps, nextState, nextContext)) { - this._pendingForceUpdate = false; - // Will set `this.props`, `this.state` and `this.context`. - this._performComponentUpdate( - nextProps, - nextOwner, - nextState, - nextFullContext, - nextContext, - transaction - ); - } else { - // If it's determined that a component should not update, we still want - // to set props and state. - this.props = nextProps; - this._owner = nextOwner; - this.state = nextState; - this._currentContext = nextFullContext; - this.context = nextContext; + try { + if (this._pendingForceUpdate || + !this.shouldComponentUpdate || + this.shouldComponentUpdate(nextProps, nextState, nextContext)) { + this._pendingForceUpdate = false; + // Will set `this.props`, `this.state` and `this.context`. + this._performComponentUpdate( + nextProps, + nextOwner, + nextState, + nextFullContext, + nextContext, + transaction + ); + } else { + // If it's determined that a component should not update, we still want + // to set props and state. + this.props = nextProps; + this._owner = nextOwner; + this.state = nextState; + this._currentContext = nextFullContext; + this.context = nextContext; + } + } catch (e) { + throw e; + } finally { + this._compositeLifeCycleState = null; } - - this._compositeLifeCycleState = null; }, /**