mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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.
This commit is contained in:
+21
-2
@@ -201,7 +201,17 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
|
||||
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<T, P, I, TI, HI, PI, C, CC, CX, PL>(
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user