mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Add a failing test for context when reusing work
We mistakingly forget to push the context if the parent is being reused but the child is not.
This commit is contained in:
@@ -1698,4 +1698,62 @@ describe('ReactIncremental', () => {
|
||||
'Recurse {"n":0}',
|
||||
]);
|
||||
});
|
||||
|
||||
it('provides context when reusing work', () => {
|
||||
var ops = [];
|
||||
|
||||
class Intl extends React.Component {
|
||||
static childContextTypes = {
|
||||
locale: React.PropTypes.string,
|
||||
};
|
||||
getChildContext() {
|
||||
return {
|
||||
locale: this.props.locale,
|
||||
};
|
||||
}
|
||||
render() {
|
||||
ops.push('Intl ' + JSON.stringify(this.context));
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
class ShowLocale extends React.Component {
|
||||
static contextTypes = {
|
||||
locale: React.PropTypes.string,
|
||||
};
|
||||
|
||||
render() {
|
||||
ops.push('ShowLocale ' + JSON.stringify(this.context));
|
||||
return this.context.locale;
|
||||
}
|
||||
}
|
||||
|
||||
ops.length = 0;
|
||||
ReactNoop.render(
|
||||
<Intl locale="fr">
|
||||
<ShowLocale />
|
||||
<div hidden="true">
|
||||
<ShowLocale />
|
||||
<Intl locale="ru">
|
||||
<ShowLocale />
|
||||
</Intl>
|
||||
</div>
|
||||
<ShowLocale />
|
||||
</Intl>
|
||||
);
|
||||
ReactNoop.flushDeferredPri(40);
|
||||
expect(ops).toEqual([
|
||||
'Intl null',
|
||||
'ShowLocale {"locale":"fr"}',
|
||||
'ShowLocale {"locale":"fr"}',
|
||||
]);
|
||||
|
||||
ops.length = 0;
|
||||
ReactNoop.flush();
|
||||
expect(ops).toEqual([
|
||||
'ShowLocale {"locale":"fr"}',
|
||||
'Intl null',
|
||||
'ShowLocale {"locale":"ru"}',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user