mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
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.
This commit is contained in:
parent
17de85689e
commit
091534c376
|
|
@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user