mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Temporarily fix EmptyComponents
This a workaround for the problem described in #2770. It should be temporary because this is really just working around the real problem.
This commit is contained in:
@@ -30,10 +30,21 @@ var ReactEmptyComponentInjection = {
|
||||
var ReactEmptyComponentType = function() {};
|
||||
ReactEmptyComponentType.prototype.componentDidMount = function() {
|
||||
var internalInstance = ReactInstanceMap.get(this);
|
||||
// TODO: Make sure we run these methods in the correct order, we shouldn't
|
||||
// need this check. We're going to assume if we're here it means we ran
|
||||
// componentWillUnmount already so there is no internal instance (it gets
|
||||
// removed as part of the unmounting process).
|
||||
if (!internalInstance) {
|
||||
return;
|
||||
}
|
||||
registerNullComponentID(internalInstance._rootNodeID);
|
||||
};
|
||||
ReactEmptyComponentType.prototype.componentWillUnmount = function() {
|
||||
var internalInstance = ReactInstanceMap.get(this);
|
||||
// TODO: Get rid of this check. See TODO in componentDidMount.
|
||||
if (!internalInstance) {
|
||||
return;
|
||||
}
|
||||
deregisterNullComponentID(internalInstance._rootNodeID);
|
||||
};
|
||||
ReactEmptyComponentType.prototype.render = function() {
|
||||
|
||||
@@ -231,4 +231,38 @@ describe('ReactEmptyComponent', function() {
|
||||
'Invariant Violation: React.render(): Invalid component element.'
|
||||
);
|
||||
});
|
||||
|
||||
it('does not break when updating during mount', function() {
|
||||
var Child = React.createClass({
|
||||
componentDidMount() {
|
||||
this.props.onMount && this.props.onMount();
|
||||
},
|
||||
render() {
|
||||
if (!this.props.visible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <div>hello world</div>;
|
||||
}
|
||||
});
|
||||
|
||||
var Parent = React.createClass({
|
||||
update() {
|
||||
this.forceUpdate();
|
||||
},
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Child key="1" visible={false} />
|
||||
<Child key="0" visible={true} onMount={this.update} />
|
||||
<Child key="2" visible={false} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
ReactTestUtils.renderIntoDocument(<Parent/>)
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user