Fix for issue/6027.

ReactDOMSelect's _handleChange function tries to set
this._wrapperState.pendingUpdate = true after executing the onChange
function. However, if the select was removed as a result of said
fuction, this._wrapperState would be null. Resulting in an
Uncaught TypeError: Cannot set property 'pendingUpdate' of null.
This commit is contained in:
Sam Beveridge
2016-02-12 14:00:15 -07:00
parent bbd5a78efa
commit c4a2425eca
2 changed files with 23 additions and 1 deletions
@@ -236,7 +236,9 @@ function _handleChange(event) {
var props = this._currentElement.props;
var returnValue = LinkedValueUtils.executeOnChange(props, event);
this._wrapperState.pendingUpdate = true;
if (this._rootNodeID && this._wrapperState.pendingUpdate) {
this._wrapperState.pendingUpdate = true;
}
ReactUpdates.asap(updateOptionsIfPendingUpdateAndMounted, this);
return returnValue;
}
@@ -517,4 +517,24 @@ describe('ReactDOMSelect', function() {
);
expect(console.error.argsForCall.length).toBe(1);
});
it('should be able to safely remove select onChange', function() {
function changeView() {
ReactDOM.unmountComponentAtNode(container);
}
var container = document.createElement('div');
var stub =
<select value="giraffe" onChange={changeView}>
<option value="monkey">A monkey!</option>
<option value="giraffe">A giraffe!</option>
<option value="gorilla">A gorilla!</option>
</select>;
stub = ReactDOM.render(stub, container);
var node = ReactDOM.findDOMNode(stub);
expect(() => ReactTestUtils.Simulate.change(node)).not.toThrow(
"Cannot set property 'pendingUpdate' of null"
);
});
});