From 2fed93d3e07ed62256e491ccda2f5a17eadc21b2 Mon Sep 17 00:00:00 2001 From: Sophie Alpert Date: Thu, 10 May 2018 13:18:07 -0700 Subject: [PATCH] Set owner correctly inside forwardRef and context consumer 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 5aa7ffc446cd3..0d5ac16b30786 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.js @@ -180,7 +180,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); + ReactCurrentOwner.current = null; + } else { + nextChildren = render(nextProps, ref); + } + reconcileChildren(current, workInProgress, nextChildren); memoizeProps(workInProgress, nextProps); return workInProgress.child; @@ -1022,7 +1032,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);