Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE during reconciliation #6028

Merged
merged 3 commits into from
Feb 13, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/renderers/dom/client/wrappers/ReactDOMSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me. We don't need to check the value of pendingUpdate, we can just blindly set it to true. Can you update the PR to remove that check?

this._wrapperState.pendingUpdate = true;
}
ReactUpdates.asap(updateOptionsIfPendingUpdateAndMounted, this);
return returnValue;
}
Expand Down
20 changes: 20 additions & 0 deletions src/renderers/dom/client/wrappers/__tests__/ReactDOMSelect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
});
});