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 2fed93d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,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);
ReactCurrentOwner.current = null;
} else {
nextChildren = render(nextProps, ref);
}

reconcileChildren(current, workInProgress, nextChildren);
memoizeProps(workInProgress, nextProps);
return workInProgress.child;
Expand Down Expand Up @@ -1022,7 +1032,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);
Expand Down

0 comments on commit 2fed93d

Please sign in to comment.