From 2a4d2ca7fc2857bf3ca5d3628211747d7885ed6b Mon Sep 17 00:00:00 2001 From: Sophie Alpert Date: Mon, 14 May 2018 10:07:31 -0700 Subject: [PATCH] Set owner correctly inside forwardRef and context consumer (#12777) Previously, _owner would be null if you create an element inside forwardRef or inside a context consumer. This is used by ReactNativeFiberInspector when traversing the hierarchy and also to give more info in some warning texts. This also means you'll now correctly get a warning if you call setState inside one of these. Test Plan: Tim tried it in the RN inspector. --- .../src/ReactFiberBeginWork.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.js b/packages/react-reconciler/src/ReactFiberBeginWork.js index 14927b2db98e9..d08ebd133024a 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.js @@ -201,7 +201,17 @@ export default function( return bailoutOnAlreadyFinishedWork(current, workInProgress); } } - const nextChildren = render(nextProps, ref); + + let nextChildren; + if (__DEV__) { + ReactCurrentOwner.current = workInProgress; + ReactDebugCurrentFiber.setCurrentPhase('render'); + nextChildren = render(nextProps, ref); + ReactDebugCurrentFiber.setCurrentPhase(null); + } else { + nextChildren = render(nextProps, ref); + } + reconcileChildren(current, workInProgress, nextChildren); memoizeProps(workInProgress, nextProps); return workInProgress.child; @@ -1101,7 +1111,16 @@ export default function( ); } - const newChildren = render(newValue); + let newChildren; + if (__DEV__) { + ReactCurrentOwner.current = workInProgress; + ReactDebugCurrentFiber.setCurrentPhase('render'); + newChildren = render(newValue); + ReactDebugCurrentFiber.setCurrentPhase(null); + } else { + newChildren = render(newValue); + } + // React DevTools reads this flag. workInProgress.effectTag |= PerformedWork; reconcileChildren(current, workInProgress, newChildren);