Fix return value of ReactDOMFiber.unmountComponentAtNode (#9619)

This commit is contained in:
Ben Alpert
2017-05-05 17:54:53 -07:00
committed by GitHub
parent 767a5d60e8
commit 542dac4a23
3 changed files with 24 additions and 2 deletions
+2
View File
@@ -1240,6 +1240,8 @@ src/renderers/dom/shared/__tests__/ReactEventListener-test.js
src/renderers/dom/shared/__tests__/ReactMount-test.js
* throws when given a non-node
* returns false on non-React containers
* returns true on React containers
* throws when given a string
* throws when given a factory
* should render different components in same root
+7 -2
View File
@@ -518,11 +518,16 @@ var ReactDOM = {
}
// Unmount should not be batched.
return DOMRenderer.unbatchedUpdates(() => {
return renderSubtreeIntoContainer(null, null, container, () => {
DOMRenderer.unbatchedUpdates(() => {
renderSubtreeIntoContainer(null, null, container, () => {
container._reactRootContainer = null;
});
});
// If you call unmountComponentAtNode twice in quick succession, you'll
// get `true` twice. That's probably fine?
return true;
} else {
return false;
}
},
@@ -46,6 +46,21 @@ describe('ReactMount', () => {
'unmountComponentAtNode(...): Target container is not a DOM element.',
);
});
it('returns false on non-React containers', () => {
var d = document.createElement('div');
d.innerHTML = '<b>hellooo</b>';
expect(ReactDOM.unmountComponentAtNode(d)).toBe(false);
expect(d.textContent).toBe('hellooo');
});
it('returns true on React containers', () => {
var d = document.createElement('div');
ReactDOM.render(<b>hellooo</b>, d);
expect(d.textContent).toBe('hellooo');
expect(ReactDOM.unmountComponentAtNode(d)).toBe(true);
expect(d.textContent).toBe('');
});
});
it('throws when given a string', () => {