diff --git a/scripts/fiber/tests-passing-except-dev.txt b/scripts/fiber/tests-passing-except-dev.txt index e177fb9cf8..1f59bb07d9 100644 --- a/scripts/fiber/tests-passing-except-dev.txt +++ b/scripts/fiber/tests-passing-except-dev.txt @@ -1,6 +1,3 @@ -src/renderers/__tests__/ReactComponentLifeCycle-test.js -* warns if findDOMNode is used inside render - src/renderers/__tests__/ReactComponentTreeHook-test.js * uses displayName or Unknown for classic components * uses displayName, name, or ReactComponent for modern components diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index 7d7f50146a..238fe2bde4 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -550,6 +550,7 @@ src/renderers/__tests__/ReactComponentLifeCycle-test.js * should correctly determine if a component is mounted * should correctly determine if a null component is mounted * isMounted should return false when unmounted +* warns if findDOMNode is used inside render * should not throw when updating an auxiliary component * should allow state updates in componentDidMount * should call nested lifecycle methods in the right order diff --git a/src/renderers/dom/shared/findDOMNode.js b/src/renderers/dom/shared/findDOMNode.js index f932f08987..0986c7290e 100644 --- a/src/renderers/dom/shared/findDOMNode.js +++ b/src/renderers/dom/shared/findDOMNode.js @@ -26,10 +26,14 @@ let findStack = function(arg) { const findDOMNode = function(componentOrElement : Element | ?ReactComponent) : null | Element | Text { if (__DEV__) { - var owner = ReactCurrentOwner.current; - if (owner !== null && '_warnedAboutRefsInRender' in owner) { + var owner = (ReactCurrentOwner.current : any); + if (owner !== null) { + var isFiber = typeof owner.tag === 'number'; + var warnedAboutRefsInRender = isFiber ? + owner.stateNode._warnedAboutRefsInRender : + owner._warnedAboutRefsInRender; warning( - (owner: any)._warnedAboutRefsInRender, + warnedAboutRefsInRender, '%s is accessing findDOMNode inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + @@ -37,7 +41,11 @@ const findDOMNode = function(componentOrElement : Element | ?ReactComponent(config : HostConfig