Skip to content

Commit 2a4d2ca

Browse files
authored
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.
1 parent 7254203 commit 2a4d2ca

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,17 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
201201
return bailoutOnAlreadyFinishedWork(current, workInProgress);
202202
}
203203
}
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+
205215
reconcileChildren(current, workInProgress, nextChildren);
206216
memoizeProps(workInProgress, nextProps);
207217
return workInProgress.child;
@@ -1101,7 +1111,16 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
11011111
);
11021112
}
11031113

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+
11051124
// React DevTools reads this flag.
11061125
workInProgress.effectTag |= PerformedWork;
11071126
reconcileChildren(current, workInProgress, newChildren);

0 commit comments

Comments
 (0)