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:
Sophie Alpert 2018-05-14 10:07:31 -07:00 committed by GitHub
parent 72542030cf
commit 2a4d2ca7fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 2 deletions

View File

@ -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);