From 3bbaf1fd77489b0d4a14b9ccba851ee2098e6081 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Mon, 10 Sep 2018 17:54:45 +0100 Subject: [PATCH] Fix a regression related to isReactComponent prototype check (#13608) --- .../src/__tests__/ReactCompositeComponent-test.js | 14 ++++++++++++++ packages/react-reconciler/src/ReactFiber.js | 7 +------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js index 7db34eafa700a..115544170a83e 100644 --- a/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactCompositeComponent-test.js @@ -1762,4 +1762,18 @@ describe('ReactCompositeComponent', () => { {withoutStack: true}, ); }); + + // Regression test for accidental breaking change + // https://github.com/facebook/react/issues/13580 + it('should support classes shadowing isReactComponent', () => { + class Shadow extends React.Component { + isReactComponent() {} + render() { + return
; + } + } + const container = document.createElement('div'); + ReactDOM.render(, container); + expect(container.firstChild.tagName).toBe('DIV'); + }); }); diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index 5fba962eed60a..5ba88f0011c95 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -284,12 +284,7 @@ const createFiber = function( function shouldConstruct(Component: Function) { const prototype = Component.prototype; - return ( - typeof prototype === 'object' && - prototype !== null && - typeof prototype.isReactComponent === 'object' && - prototype.isReactComponent !== null - ); + return !!(prototype && prototype.isReactComponent); } export function resolveLazyComponentTag(