@samitouri / QOS-React-2 / commits / 542dac4a23

Fix return value of ReactDOMFiber.unmountComponentAtNode (#9619)

Ben Alpert committed May 5, 2017 at 17:54 UTC 542dac4a23780ef8eb8dd0de687143f189fa0cc8
3 files changed +24 -2
scripts/fiber/tests-passing.txt
+2
@@ -1240,6 +1240,8 @@ src/renderers/dom/shared/__tests__/ReactEventListener-test.js
1240
1241 src/renderers/dom/shared/__tests__/ReactMount-test.js
1242 * throws when given a non-node
1243 +* returns false on non-React containers
1244 +* returns true on React containers
1245 * throws when given a string
1246 * throws when given a factory
1247 * should render different components in same root
src/renderers/dom/fiber/ReactDOMFiber.js
+7 -2
@@ -518,11 +518,16 @@ var ReactDOM = {
518 }
519
520 // Unmount should not be batched.
521 - return DOMRenderer.unbatchedUpdates(() => {
522 - return renderSubtreeIntoContainer(null, null, container, () => {
521 + DOMRenderer.unbatchedUpdates(() => {
522 + renderSubtreeIntoContainer(null, null, container, () => {
523 container._reactRootContainer = null;
524 });
525 });
526 + // If you call unmountComponentAtNode twice in quick succession, you'll
527 + // get `true` twice. That's probably fine?
528 + return true;
529 + } else {
530 + return false;
531 }
532 },
533
src/renderers/dom/shared/__tests__/ReactMount-test.js
+15
@@ -46,6 +46,21 @@ describe('ReactMount', () => {
46 'unmountComponentAtNode(...): Target container is not a DOM element.',
47 );
48 });
49 +
50 + it('returns false on non-React containers', () => {
51 + var d = document.createElement('div');
52 + d.innerHTML = '<b>hellooo</b>';
53 + expect(ReactDOM.unmountComponentAtNode(d)).toBe(false);
54 + expect(d.textContent).toBe('hellooo');
55 + });
56 +
57 + it('returns true on React containers', () => {
58 + var d = document.createElement('div');
59 + ReactDOM.render(<b>hellooo</b>, d);
60 + expect(d.textContent).toBe('hellooo');
61 + expect(ReactDOM.unmountComponentAtNode(d)).toBe(true);
62 + expect(d.textContent).toBe('');
63 + });
64 });
65
66 it('throws when given a string', () => {