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.
Sam Beveridge committed
Feb 12, 2016 at 14:00 UTC
c4a2425eca4e2b093213f6d4a5f35469f9850a62
2 files changed
+23
-1
src/renderers/dom/client/wrappers/ReactDOMSelect.js
+3
-1
@@ -236,7 +236,9 @@ function _handleChange(event) {
236
var props = this._currentElement.props;
237
var returnValue = LinkedValueUtils.executeOnChange(props, event);
238
239
- this._wrapperState.pendingUpdate = true;
239
+ if (this._rootNodeID && this._wrapperState.pendingUpdate) {
240
+ this._wrapperState.pendingUpdate = true;
241
+ }
242
ReactUpdates.asap(updateOptionsIfPendingUpdateAndMounted, this);
243
return returnValue;
244
}
src/renderers/dom/client/wrappers/__tests__/ReactDOMSelect-test.js
+20
@@ -517,4 +517,24 @@ describe('ReactDOMSelect', function() {
517
);
518
expect(console.error.argsForCall.length).toBe(1);
519
});
520
+
521
+ it('should be able to safely remove select onChange', function() {
522
+ function changeView() {
523
+ ReactDOM.unmountComponentAtNode(container);
524
+ }
525
+
526
+ var container = document.createElement('div');
527
+ var stub =
528
+ <select value="giraffe" onChange={changeView}>
529
+ <option value="monkey">A monkey!</option>
530
+ <option value="giraffe">A giraffe!</option>
531
+ <option value="gorilla">A gorilla!</option>
532
+ </select>;
533
+ stub = ReactDOM.render(stub, container);
534
+ var node = ReactDOM.findDOMNode(stub);
535
+
536
+ expect(() => ReactTestUtils.Simulate.change(node)).not.toThrow(
537
+ "Cannot set property 'pendingUpdate' of null"
538
+ );
539
+ });
540
});