mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
bailoutOnLowPriority correct pushes context for ClassComponents to mirror complete phase context pop
This commit is contained in:
@@ -1148,6 +1148,7 @@ src/renderers/shared/fiber/__tests__/ReactIncremental-test.js
|
||||
* provides context when reusing work
|
||||
* reads context when setState is below the provider
|
||||
* reads context when setState is above the provider
|
||||
* maintains the correct context index when context proviers are bailed out due to low priority
|
||||
|
||||
src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js
|
||||
* catches render error in a boundary during full deferred mounting
|
||||
|
||||
@@ -462,8 +462,17 @@ module.exports = function<T, P, I, TI, C, CX>(
|
||||
}
|
||||
|
||||
function bailoutOnLowPriority(current, workInProgress) {
|
||||
if (workInProgress.tag === HostPortal) {
|
||||
pushHostContainer(workInProgress.stateNode.containerInfo);
|
||||
// TODO: Handle HostComponent tags here as well and call pushHostContext()?
|
||||
// See PR 8590 discussion for context
|
||||
switch (workInProgress.tag) {
|
||||
case ClassComponent:
|
||||
if (isContextProvider(workInProgress)) {
|
||||
pushContextProvider(workInProgress, false);
|
||||
}
|
||||
break;
|
||||
case HostPortal:
|
||||
pushHostContainer(workInProgress.stateNode.containerInfo);
|
||||
break;
|
||||
}
|
||||
// TODO: What if this is currently in progress?
|
||||
// How can that happen? How is this not being cloned?
|
||||
|
||||
@@ -1932,4 +1932,47 @@ describe('ReactIncremental', () => {
|
||||
'ShowLocaleFn:read {"locale":"gr"}',
|
||||
]);
|
||||
});
|
||||
|
||||
it('maintains the correct context index when context proviers are bailed out due to low priority', () => {
|
||||
class Root extends React.Component {
|
||||
render() {
|
||||
return <Middle {...this.props} />;
|
||||
}
|
||||
}
|
||||
|
||||
let instance;
|
||||
|
||||
class Middle extends React.Component {
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
instance = this;
|
||||
}
|
||||
shouldComponentUpdate() {
|
||||
// Return false so that our child will get a NoWork priority (and get bailed out)
|
||||
return false;
|
||||
}
|
||||
render() {
|
||||
return <Child />;
|
||||
}
|
||||
}
|
||||
|
||||
// Child must be a context provider to trigger the bug
|
||||
class Child extends React.Component {
|
||||
static childContextTypes = {};
|
||||
getChildContext() {
|
||||
return {};
|
||||
}
|
||||
render() {
|
||||
return <div />;
|
||||
}
|
||||
}
|
||||
|
||||
// Init
|
||||
ReactNoop.render(<Root />);
|
||||
ReactNoop.flush();
|
||||
|
||||
// Trigger an update in the middle of the tree
|
||||
instance.setState({});
|
||||
ReactNoop.flush();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user