diff --git a/packages/react-reconciler/src/ReactFiberScheduler.js b/packages/react-reconciler/src/ReactFiberScheduler.js
index 5ca08cebc0925..38ef8c44d528e 100644
--- a/packages/react-reconciler/src/ReactFiberScheduler.js
+++ b/packages/react-reconciler/src/ReactFiberScheduler.js
@@ -49,7 +49,6 @@ import {
enableUserTimingAPI,
replayFailedUnitOfWorkWithInvokeGuardedCallback,
warnAboutDeprecatedLifecycles,
- warnAboutLegacyContextAPI,
enableSuspense,
} from 'shared/ReactFeatureFlags';
import getComponentName from 'shared/getComponentName';
@@ -479,14 +478,11 @@ function commitAllLifeCycles(
) {
if (__DEV__) {
ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
+ ReactStrictModeWarnings.flushLegacyContextWarning();
if (warnAboutDeprecatedLifecycles) {
ReactStrictModeWarnings.flushPendingDeprecationWarnings();
}
-
- if (warnAboutLegacyContextAPI) {
- ReactStrictModeWarnings.flushLegacyContextWarning();
- }
}
while (nextEffect !== null) {
const effectTag = nextEffect.effectTag;
diff --git a/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js
index 5260851a9e324..8a53360c7882f 100644
--- a/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js
+++ b/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js
@@ -1936,7 +1936,11 @@ describe('ReactIncremental', () => {
,
);
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Intl, ShowBoth, ShowLocale',
+ {withoutStack: true},
+ );
expect(ops).toEqual([
'Intl {}',
'ShowLocale {"locale":"fr"}',
@@ -1981,7 +1985,11 @@ describe('ReactIncremental', () => {
,
);
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Router, ShowRoute',
+ {withoutStack: true},
+ );
expect(ops).toEqual([
'ShowLocale {"locale":"sv"}',
'ShowBoth {"locale":"sv"}',
@@ -2021,7 +2029,11 @@ describe('ReactIncremental', () => {
}
ReactNoop.render();
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Recurse',
+ {withoutStack: true},
+ );
expect(ops).toEqual([
'Recurse {}',
'Recurse {"n":2}',
@@ -2054,7 +2066,11 @@ describe('ReactIncremental', () => {
};
ReactNoop.render();
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Recurse',
+ {withoutStack: true},
+ );
expect(ops).toEqual([
'Recurse {}',
'Recurse {"n":2}',
@@ -2112,7 +2128,11 @@ describe('ReactIncremental', () => {
]);
ops.length = 0;
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Intl, ShowLocale',
+ {withoutStack: true},
+ );
expect(ops).toEqual([
'ShowLocale {"locale":"fr"}',
'Intl {}',
@@ -2192,7 +2212,11 @@ describe('ReactIncremental', () => {
,
);
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn',
+ {withoutStack: true},
+ );
expect(ops).toEqual([
'Intl:read {}',
'Intl:provide {"locale":"fr"}',
@@ -2280,7 +2304,11 @@ describe('ReactIncremental', () => {
,
);
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn',
+ {withoutStack: true},
+ );
expect(ops).toEqual([
'Intl:read {}',
'Intl:provide {"locale":"fr"}',
@@ -2345,7 +2373,11 @@ describe('ReactIncremental', () => {
// Init
ReactNoop.render();
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Child',
+ {withoutStack: true},
+ );
// Trigger an update in the middle of the tree
instance.setState({});
@@ -2391,7 +2423,11 @@ describe('ReactIncremental', () => {
// Init
ReactNoop.render();
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: ContextProvider',
+ {withoutStack: true},
+ );
// Trigger an update in the middle of the tree
// This is necessary to reproduce the error as it curently exists.
@@ -2437,8 +2473,12 @@ describe('ReactIncremental', () => {
ReactNoop.render();
expect(ReactNoop.flush).toWarnDev(
- 'componentWillReceiveProps: Please update the following components ' +
- 'to use static getDerivedStateFromProps instead: MyComponent',
+ [
+ 'componentWillReceiveProps: Please update the following components ' +
+ 'to use static getDerivedStateFromProps instead: MyComponent',
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: MyComponent',
+ ],
{withoutStack: true},
);
@@ -2582,7 +2622,11 @@ describe('ReactIncremental', () => {
,
);
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Child, TopContextProvider',
+ {withoutStack: true},
+ );
expect(rendered).toEqual(['count:0']);
instance.updateCount();
ReactNoop.flush();
@@ -2640,7 +2684,11 @@ describe('ReactIncremental', () => {
,
);
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
+ {withoutStack: true},
+ );
expect(rendered).toEqual(['count:0']);
instance.updateCount();
ReactNoop.flush();
@@ -2707,7 +2755,11 @@ describe('ReactIncremental', () => {
,
);
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
+ {withoutStack: true},
+ );
expect(rendered).toEqual(['count:0']);
instance.updateCount();
ReactNoop.flush();
@@ -2784,7 +2836,11 @@ describe('ReactIncremental', () => {
,
);
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
+ {withoutStack: true},
+ );
expect(rendered).toEqual(['count:0, name:brian']);
topInstance.updateCount();
ReactNoop.flush();
diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js
index eab804cedb39e..345c5b537f2c5 100644
--- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js
+++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js
@@ -1092,7 +1092,11 @@ describe('ReactIncrementalErrorHandling', () => {
,
);
- ReactNoop.flush();
+ expect(ReactNoop.flush).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Connector, Provider',
+ {withoutStack: true},
+ );
// If the context stack does not unwind, span will get 'abcde'
expect(ReactNoop.getChildren()).toEqual([span('a')]);
@@ -1581,6 +1585,12 @@ describe('ReactIncrementalErrorHandling', () => {
};
ReactNoop.render();
- expect(() => ReactNoop.flush()).toThrow('Oops!');
+ expect(() => {
+ expect(() => ReactNoop.flush()).toThrow('Oops!');
+ }).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: Provider',
+ {withoutStack: true},
+ );
});
});
diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js
index bc1dca7adf592..801e64b14839c 100644
--- a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js
+++ b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js
@@ -357,12 +357,16 @@ describe('ReactDebugFiberPerf', () => {
ReactNoop.render();
addComment('Mount');
expect(ReactNoop.flush).toWarnDev(
- 'componentWillMount: Please update the following components ' +
- 'to use componentDidMount instead: AllLifecycles' +
- '\n\ncomponentWillReceiveProps: Please update the following components ' +
- 'to use static getDerivedStateFromProps instead: AllLifecycles' +
- '\n\ncomponentWillUpdate: Please update the following components ' +
- 'to use componentDidUpdate instead: AllLifecycles',
+ [
+ 'componentWillMount: Please update the following components ' +
+ 'to use componentDidMount instead: AllLifecycles' +
+ '\n\ncomponentWillReceiveProps: Please update the following components ' +
+ 'to use static getDerivedStateFromProps instead: AllLifecycles' +
+ '\n\ncomponentWillUpdate: Please update the following components ' +
+ 'to use componentDidUpdate instead: AllLifecycles',
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: AllLifecycles',
+ ],
{withoutStack: true},
);
ReactNoop.render();
diff --git a/packages/react-reconciler/src/__tests__/ReactNewContext-test.internal.js b/packages/react-reconciler/src/__tests__/ReactNewContext-test.internal.js
index 8a03208219326..299b6ab10811f 100644
--- a/packages/react-reconciler/src/__tests__/ReactNewContext-test.internal.js
+++ b/packages/react-reconciler/src/__tests__/ReactNewContext-test.internal.js
@@ -1144,7 +1144,13 @@ describe('ReactNewContext', () => {
,
);
- expect(ReactNoop.flush()).toEqual(['LegacyProvider', 'App', 'Child']);
+ expect(() => {
+ expect(ReactNoop.flush()).toEqual(['LegacyProvider', 'App', 'Child']);
+ }).toWarnDev(
+ 'Legacy context API has been detected within a strict-mode tree: \n\n' +
+ 'Please update the following components: LegacyProvider',
+ {withoutStack: true},
+ );
expect(ReactNoop.getChildren()).toEqual([span('Child')]);
// Update App with same value (should bail out)
diff --git a/packages/react/src/__tests__/ReactStrictMode-test.internal.js b/packages/react/src/__tests__/ReactStrictMode-test.internal.js
index 896c7c179e301..fc279a50a2301 100644
--- a/packages/react/src/__tests__/ReactStrictMode-test.internal.js
+++ b/packages/react/src/__tests__/ReactStrictMode-test.internal.js
@@ -822,8 +822,6 @@ describe('ReactStrictMode', () => {
React = require('react');
ReactTestRenderer = require('react-test-renderer');
PropTypes = require('prop-types');
- ReactFeatureFlags = require('shared/ReactFeatureFlags');
- ReactFeatureFlags.warnAboutLegacyContextAPI = true;
});
it('should warn if the legacy context API have been used in strict mode', () => {
diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js
index abd23679539d3..38fafa73a46dd 100644
--- a/packages/shared/ReactFeatureFlags.js
+++ b/packages/shared/ReactFeatureFlags.js
@@ -28,9 +28,6 @@ export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
// Warn about deprecated, async-unsafe lifecycles; relates to RFC #6:
export const warnAboutDeprecatedLifecycles = false;
-// Warn about legacy context API
-export const warnAboutLegacyContextAPI = false;
-
// Gather advanced timing metrics for Profiler subtrees.
export const enableProfilerTimer = __PROFILE__;
diff --git a/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js
index 566d271222701..9a03b482d24fb 100644
--- a/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js
+++ b/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js
@@ -17,7 +17,6 @@ export const debugRenderPhaseSideEffectsForStrictMode = false;
export const enableUserTimingAPI = __DEV__;
export const enableSuspense = false;
export const warnAboutDeprecatedLifecycles = false;
-export const warnAboutLegacyContextAPI = __DEV__;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
diff --git a/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js b/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js
index f9b6576d4f464..9a2c8dfc7c235 100644
--- a/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js
+++ b/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js
@@ -17,7 +17,6 @@ export const debugRenderPhaseSideEffectsForStrictMode = false;
export const enableUserTimingAPI = __DEV__;
export const enableSuspense = false;
export const warnAboutDeprecatedLifecycles = false;
-export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js
index 4b12e739183d0..1ea9549a1a81e 100644
--- a/packages/shared/forks/ReactFeatureFlags.native-fb.js
+++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js
@@ -24,7 +24,6 @@ export const {
// The rest of the flags are static for better dead code elimination.
export const enableUserTimingAPI = __DEV__;
-export const warnAboutLegacyContextAPI = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableSuspenseServerRenderer = false;
diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js
index a92e3c0f953f5..780563724d8b9 100644
--- a/packages/shared/forks/ReactFeatureFlags.native-oss.js
+++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js
@@ -18,7 +18,6 @@ export const enableSuspense = false;
export const enableUserTimingAPI = __DEV__;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const warnAboutDeprecatedLifecycles = false;
-export const warnAboutLegacyContextAPI = false;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableSuspenseServerRenderer = false;
diff --git a/packages/shared/forks/ReactFeatureFlags.persistent.js b/packages/shared/forks/ReactFeatureFlags.persistent.js
index 1fb299db333fb..ebe62b122cfd1 100644
--- a/packages/shared/forks/ReactFeatureFlags.persistent.js
+++ b/packages/shared/forks/ReactFeatureFlags.persistent.js
@@ -17,7 +17,6 @@ export const debugRenderPhaseSideEffectsForStrictMode = false;
export const enableUserTimingAPI = __DEV__;
export const enableSuspense = false;
export const warnAboutDeprecatedLifecycles = false;
-export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js
index 07fde5086acc3..922771420b57e 100644
--- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js
+++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js
@@ -17,7 +17,6 @@ export const debugRenderPhaseSideEffectsForStrictMode = false;
export const enableUserTimingAPI = __DEV__;
export const enableSuspense = false;
export const warnAboutDeprecatedLifecycles = false;
-export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
export const enableProfilerTimer = false;
export const enableSchedulerTracing = false;
diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
index 20e510afa1b9a..dcd4b70ae0fa2 100644
--- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
+++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
@@ -17,7 +17,6 @@ export const debugRenderPhaseSideEffectsForStrictMode = false;
export const enableUserTimingAPI = __DEV__;
export const enableSuspense = true;
export const warnAboutDeprecatedLifecycles = false;
-export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
export const enableProfilerTimer = false;
export const enableSchedulerTracing = false;
diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js
index 414bc4052b2ae..a0c8931a5c21d 100644
--- a/packages/shared/forks/ReactFeatureFlags.www.js
+++ b/packages/shared/forks/ReactFeatureFlags.www.js
@@ -21,9 +21,6 @@ export const {
disableInputAttributeSyncing,
} = require('ReactFeatureFlags');
-// The rest of the flags are static for better dead code elimination.
-export const warnAboutLegacyContextAPI = __DEV__;
-
// In www, we have experimental support for gathering data
// from User Timing API calls in production. By default, we
// only emit performance.mark/measure calls in __DEV__. But if
diff --git a/scripts/rollup/shims/react-native-fb/ReactFeatureFlags.js b/scripts/rollup/shims/react-native-fb/ReactFeatureFlags.js
index df11ce7303929..55ef3d80b1964 100644
--- a/scripts/rollup/shims/react-native-fb/ReactFeatureFlags.js
+++ b/scripts/rollup/shims/react-native-fb/ReactFeatureFlags.js
@@ -14,7 +14,6 @@ const ReactFeatureFlags = {
debugRenderPhaseSideEffects: false,
debugRenderPhaseSideEffectsForStrictMode: false,
warnAboutDeprecatedLifecycles: true,
- warnAboutLegacyContextAPI: true,
};
module.exports = ReactFeatureFlags;