Skip to content

Commit

Permalink
Set owner correctly inside forwardRef and context consumer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sophiebits committed May 10, 2018
1 parent a9abd27 commit b2cd16a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Expand Up @@ -180,7 +180,12 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
return bailoutOnAlreadyFinishedWork(current, workInProgress);
}
}

ReactCurrentOwner.current = workInProgress;
ReactDebugCurrentFiber.setCurrentPhase('render');
const nextChildren = render(nextProps, ref);
ReactCurrentOwner.current = null;

reconcileChildren(current, workInProgress, nextChildren);
memoizeProps(workInProgress, nextProps);
return workInProgress.child;
Expand Down Expand Up @@ -1022,7 +1027,11 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
);
}

ReactCurrentOwner.current = workInProgress;
ReactDebugCurrentFiber.setCurrentPhase('render');
const newChildren = render(newValue);
ReactDebugCurrentFiber.setCurrentPhase(null);

// React DevTools reads this flag.
workInProgress.effectTag |= PerformedWork;
reconcileChildren(current, workInProgress, newChildren);
Expand Down

0 comments on commit b2cd16a

Please sign in to comment.