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

add functional components warning about legacy context api #12892

Merged
merged 1 commit into from
May 23, 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
6 changes: 6 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
} from 'shared/ReactFeatureFlags';
import invariant from 'fbjs/lib/invariant';
import getComponentName from 'shared/getComponentName';
import ReactStrictModeWarnings from './ReactStrictModeWarnings';
import warning from 'fbjs/lib/warning';
import ReactDebugCurrentFiber from './ReactDebugCurrentFiber';
import {cancelWorkTimer} from './ReactDebugFiberPerf';
Expand Down Expand Up @@ -600,6 +601,11 @@ function mountIndeterminateComponent(
didWarnAboutBadClass[componentName] = true;
}
}

if (workInProgress.mode & StrictMode) {
ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
}

ReactCurrentOwner.current = workInProgress;
value = fn(props, context);
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactStrictModeWarnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ if (__DEV__) {
let warningsForRoot = pendingLegacyContextWarning.get(strictRoot);

if (
typeof instance.getChildContext === 'function' ||
fiber.type.contextTypes != null ||
fiber.type.childContextTypes != null
fiber.type.childContextTypes != null ||
(instance !== null && typeof instance.getChildContext === 'function')
) {
if (warningsForRoot === undefined) {
warningsForRoot = [];
Expand Down
31 changes: 29 additions & 2 deletions packages/react/src/__tests__/ReactStrictMode-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,28 @@ describe('ReactStrictMode', () => {
}

render() {
return <LegacyContextConsumer />;
return (
<div>
<LegacyContextConsumer />
<FunctionalLegacyContextConsumer />
<FactoryLegacyContextConsumer />
</div>
);
}
}

function FunctionalLegacyContextConsumer() {
return null;
}

function FactoryLegacyContextConsumer() {
return {
render() {
return null;
},
};
}

LegacyContextProvider.childContextTypes = {
color: PropTypes.string,
};
Expand Down Expand Up @@ -856,6 +874,14 @@ describe('ReactStrictMode', () => {
color: PropTypes.string,
};

FunctionalLegacyContextConsumer.contextTypes = {
color: PropTypes.string,
};

FactoryLegacyContextConsumer.contextTypes = {
color: PropTypes.string,
};

let rendered;

expect(() => {
Expand All @@ -864,7 +890,8 @@ describe('ReactStrictMode', () => {
'Warning: Legacy context API has been detected within a strict-mode tree: ' +
'\n in div (at **)' +
'\n in Root (at **)' +
'\n\nPlease update the following components: LegacyContextConsumer, LegacyContextProvider' +
'\n\nPlease update the following components: FactoryLegacyContextConsumer, ' +
'FunctionalLegacyContextConsumer, LegacyContextConsumer, LegacyContextProvider' +
'\n\nLearn more about this warning here:' +
'\nhttps://fb.me/react-strict-mode-warnings',
);
Expand Down