@samitouri / QOS-React-2 / commits / 5ef0b416df

IsMounted should always return a boolean.

Fixes #3814. isMounted used to return undefined if internalInstance was undefined after component was unmounted.

Tomasz Kołodziejski committed May 5, 2015 at 11:32 UTC 5ef0b416df0c0ffe543d3257de1b2a5adf17c0b0
2 files changed +22 -4
src/classic/class/ReactClass.js
+5 -4
@@ -761,10 +761,11 @@ var ReactClassMixin = {
761 }
762 }
763 var internalInstance = ReactInstanceMap.get(this);
764 - return (
765 - internalInstance &&
766 - internalInstance !== ReactLifeCycle.currentlyMountingInstance
767 - );
764 + if (internalInstance) {
765 + return internalInstance !== ReactLifeCycle.currentlyMountingInstance;
766 + } else {
767 + return false;
768 + }
769 },
770
771 /**
src/core/__tests__/ReactComponentLifeCycle-test.js
+17
@@ -287,6 +287,23 @@ describe('ReactComponentLifeCycle', function() {
287 );
288 });
289
290 + it('isMounted should return false when unmounted', function () {
291 + var Component = React.createClass({
292 + render: function() {
293 + return <div/>;
294 + }
295 + });
296 +
297 + var container = document.createElement('div');
298 + var instance = React.render(<Component />, container);
299 +
300 + expect(instance.isMounted()).toBe(true);
301 +
302 + React.unmountComponentAtNode(container);
303 +
304 + expect(instance.isMounted()).toBe(false);
305 + });
306 +
307 it('warns if findDOMNode is used inside render', function() {
308 spyOn(console, 'error');
309 var Component = React.createClass({