From b2cd16a22b0b7e178a7484d7af8da27c07685ef0 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. --- packages/react-reconciler/src/ReactFiberBeginWork.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.js b/packages/react-reconciler/src/ReactFiberBeginWork.js index 5aa7ffc446cd37..e8bad0e1e011a5 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.js @@ -180,7 +180,12 @@ export default function( return bailoutOnAlreadyFinishedWork(current, workInProgress); } } + + ReactCurrentOwner.current = workInProgress; + ReactDebugCurrentFiber.setCurrentPhase('render'); const nextChildren = render(nextProps, ref); + ReactCurrentOwner.current = null; + reconcileChildren(current, workInProgress, nextChildren); memoizeProps(workInProgress, nextProps); return workInProgress.child; @@ -1022,7 +1027,11 @@ export default function( ); } + ReactCurrentOwner.current = workInProgress; + ReactDebugCurrentFiber.setCurrentPhase('render'); const newChildren = render(newValue); + ReactDebugCurrentFiber.setCurrentPhase(null); + // React DevTools reads this flag. workInProgress.effectTag |= PerformedWork; reconcileChildren(current, workInProgress, newChildren);