Skip to content

Commit

Permalink
Wrap _performComponentUpdate call in try/finally
Browse files Browse the repository at this point in the history
Fixes facebook#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.
  • Loading branch information
sophiebits committed Jan 15, 2014
1 parent 17de856 commit 091534c
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/core/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

/**
Expand Down

0 comments on commit 091534c

Please sign in to comment.