Skip to content

Commit e8394da

Browse files
committed
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.
1 parent a9abd27 commit e8394da

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
@@ -180,7 +180,17 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
180180
return bailoutOnAlreadyFinishedWork(current, workInProgress);
181181
}
182182
}
183-
const nextChildren = render(nextProps, ref);
183+
184+
let nextChildren;
185+
if (__DEV__) {
186+
ReactCurrentOwner.current = workInProgress;
187+
ReactDebugCurrentFiber.setCurrentPhase('render');
188+
nextChildren = render(nextProps, ref);
189+
ReactDebugCurrentFiber.setCurrentPhase(null);
190+
} else {
191+
nextChildren = render(nextProps, ref);
192+
}
193+
184194
reconcileChildren(current, workInProgress, nextChildren);
185195
memoizeProps(workInProgress, nextProps);
186196
return workInProgress.child;
@@ -1022,7 +1032,16 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
10221032
);
10231033
}
10241034

1025-
const newChildren = render(newValue);
1035+
let newChildren;
1036+
if (__DEV__) {
1037+
ReactCurrentOwner.current = workInProgress;
1038+
ReactDebugCurrentFiber.setCurrentPhase('render');
1039+
newChildren = render(newValue);
1040+
ReactDebugCurrentFiber.setCurrentPhase(null);
1041+
} else {
1042+
newChildren = render(newValue);
1043+
}
1044+
10261045
// React DevTools reads this flag.
10271046
workInProgress.effectTag |= PerformedWork;
10281047
reconcileChildren(current, workInProgress, newChildren);

0 commit comments

Comments
 (0)