Skip to content

Commit b2cd16a

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 b2cd16a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,12 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
180180
return bailoutOnAlreadyFinishedWork(current, workInProgress);
181181
}
182182
}
183+
184+
ReactCurrentOwner.current = workInProgress;
185+
ReactDebugCurrentFiber.setCurrentPhase('render');
183186
const nextChildren = render(nextProps, ref);
187+
ReactCurrentOwner.current = null;
188+
184189
reconcileChildren(current, workInProgress, nextChildren);
185190
memoizeProps(workInProgress, nextProps);
186191
return workInProgress.child;
@@ -1022,7 +1027,11 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
10221027
);
10231028
}
10241029

1030+
ReactCurrentOwner.current = workInProgress;
1031+
ReactDebugCurrentFiber.setCurrentPhase('render');
10251032
const newChildren = render(newValue);
1033+
ReactDebugCurrentFiber.setCurrentPhase(null);
1034+
10261035
// React DevTools reads this flag.
10271036
workInProgress.effectTag |= PerformedWork;
10281037
reconcileChildren(current, workInProgress, newChildren);

0 commit comments

Comments
 (0)