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

Switch to JSX API for context #12123

Merged
merged 2 commits into from
Jan 30, 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ let React;
let ReactCallReturn;
let ReactDOMServer;
let PropTypes;
let ReactFeatureFlags;

function normalizeCodeLocInfo(str) {
return str && str.replace(/\(at .+?:\d+\)/g, '(at **)');
Expand All @@ -23,8 +22,6 @@ function normalizeCodeLocInfo(str) {
describe('ReactDOMServer', () => {
beforeEach(() => {
jest.resetModules();
ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableNewContextAPI = true;
React = require('react');
ReactCallReturn = require('react-call-return');
PropTypes = require('prop-types');
Expand Down Expand Up @@ -388,36 +385,32 @@ describe('ReactDOMServer', () => {
});

it('renders with new context API', () => {
const Context = React.unstable_createContext(0);

function Provider(props) {
return Context.provide(props.value, props.children);
}
const Context = React.createContext(0);

function Consumer(props) {
return Context.consume(value => {
return 'Result: ' + value;
});
return (
<Context.Consumer>{value => 'Result: ' + value}</Context.Consumer>
);
}

const Indirection = React.Fragment;

function App(props) {
return (
<Provider value={props.value}>
<Provider value={2}>
<Context.Provider value={props.value}>
<Context.Provider value={2}>
<Consumer />
</Provider>
</Context.Provider>
<Indirection>
<Indirection>
<Consumer />
<Provider value={3}>
<Context.Provider value={3}>
<Consumer />
</Provider>
</Context.Provider>
</Indirection>
</Indirection>
<Consumer />
</Provider>
</Context.Provider>
);
}

Expand All @@ -428,16 +421,12 @@ describe('ReactDOMServer', () => {
});

it('renders context API, reentrancy', () => {
const Context = React.unstable_createContext(0);

function Provider(props) {
return Context.provide(props.value, props.children);
}
const Context = React.createContext(0);

function Consumer(props) {
return Context.consume(value => {
return 'Result: ' + value;
});
return (
<Context.Consumer>{value => 'Result: ' + value}</Context.Consumer>
);
}

let reentrantMarkup;
Expand All @@ -452,21 +441,21 @@ describe('ReactDOMServer', () => {

function App(props) {
return (
<Provider value={props.value}>
<Context.Provider value={props.value}>
{props.reentrant && <Reentrant />}
<Provider value={2}>
<Context.Provider value={2}>
<Consumer />
</Provider>
</Context.Provider>
<Indirection>
<Indirection>
<Consumer />
<Provider value={3}>
<Context.Provider value={3}>
<Consumer />
</Provider>
</Context.Provider>
</Indirection>
</Indirection>
<Consumer />
</Provider>
</Context.Provider>
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -860,10 +860,10 @@ class ReactDOMServerRenderer {
}
case REACT_CONTEXT_TYPE: {
const consumer: ReactConsumer<any> = (nextChild: any);
const nextProps = consumer.props;
const nextProps: any = consumer.props;
const nextValue = consumer.type.currentValue;

const nextChildren = toArray(nextProps.render(nextValue));
const nextChildren = toArray(nextProps.children(nextValue));
const frame: Frame = {
type: nextChild,
domNamespace: parentNamespace,
Expand Down