@samitouri / QOS-React / commits / 2a4d2ca7fc

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.

Sophie Alpert committed May 14, 2018 at 10:07 UTC 2a4d2ca7fc2857bf3ca5d3628211747d7885ed6b
1 file changed +21 -2
packages/react-reconciler/src/ReactFiberBeginWork.js
+21 -2
@@ -201,7 +201,17 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
201 return bailoutOnAlreadyFinishedWork(current, workInProgress);
202 }
203 }
204 - const nextChildren = render(nextProps, ref);
204 +
205 + let nextChildren;
206 + if (__DEV__) {
207 + ReactCurrentOwner.current = workInProgress;
208 + ReactDebugCurrentFiber.setCurrentPhase('render');
209 + nextChildren = render(nextProps, ref);
210 + ReactDebugCurrentFiber.setCurrentPhase(null);
211 + } else {
212 + nextChildren = render(nextProps, ref);
213 + }
214 +
215 reconcileChildren(current, workInProgress, nextChildren);
216 memoizeProps(workInProgress, nextProps);
217 return workInProgress.child;
@@ -1101,7 +1111,16 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
1111 );
1112 }
1113
1104 - const newChildren = render(newValue);
1114 + let newChildren;
1115 + if (__DEV__) {
1116 + ReactCurrentOwner.current = workInProgress;
1117 + ReactDebugCurrentFiber.setCurrentPhase('render');
1118 + newChildren = render(newValue);
1119 + ReactDebugCurrentFiber.setCurrentPhase(null);
1120 + } else {
1121 + newChildren = render(newValue);
1122 + }
1123 +
1124 // React DevTools reads this flag.
1125 workInProgress.effectTag |= PerformedWork;
1126 reconcileChildren(current, workInProgress, newChildren);