Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a context propagation bug #12708

Merged
merged 2 commits into from
Apr 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,8 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
}
let sibling = nextFiber.sibling;
if (sibling !== null) {
// Set the return pointer of the sibling to the work-in-progress fiber.
sibling.return = nextFiber.return;
nextFiber = sibling;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,82 @@ describe('ReactNewContext', () => {
ReactNoop.flush();
});

// This is a regression case for https://github.com/facebook/react/issues/12686
it('does not skip some siblings', () => {
const Context = React.createContext(0);

class App extends React.Component {
state = {
step: 0,
};

render() {
ReactNoop.yield('App');
return (
<Context.Provider value={this.state.step}>
<StaticContent />
{this.state.step > 0 && <Indirection />}
</Context.Provider>
);
}
}

class StaticContent extends React.PureComponent {
render() {
return (
<React.Fragment>
<React.Fragment>
<span prop="static 1" />
<span prop="static 2" />
</React.Fragment>
</React.Fragment>
);
}
}

class Indirection extends React.PureComponent {
render() {
return <Consumer />;
}
}

function Consumer() {
return (
<Context.Consumer>
{value => {
ReactNoop.yield('Consumer');
return <span prop={value} />;
}}
</Context.Consumer>
);
}

// Initial mount
let inst;
ReactNoop.render(<App ref={ref => (inst = ref)} />);
expect(ReactNoop.flush()).toEqual(['App']);
expect(ReactNoop.getChildren()).toEqual([
span('static 1'),
span('static 2'),
]);
// Update the first time
inst.setState({step: 1});
expect(ReactNoop.flush()).toEqual(['App', 'Consumer']);
expect(ReactNoop.getChildren()).toEqual([
span('static 1'),
span('static 2'),
span(1),
]);
// Update the second time
inst.setState({step: 2});
expect(ReactNoop.flush()).toEqual(['App', 'Consumer']);
expect(ReactNoop.getChildren()).toEqual([
span('static 1'),
span('static 2'),
span(2),
]);
});

describe('fuzz test', () => {
const Fragment = React.Fragment;
const contextKeys = ['A', 'B', 'C', 'D', 'E', 'F', 'G'];
Expand Down