Skip to content

unify deprecated/unsafe lifecycle warnings, pass tests #16103

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

Merged
merged 1 commit into from
Jul 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 43 additions & 27 deletions packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js
Original file line number Diff line number Diff line change
@@ -709,9 +709,9 @@ describe('ReactComponentLifeCycle', () => {
);
}).toLowPriorityWarnDev(
[
'componentWillMount is deprecated',
'componentWillReceiveProps is deprecated',
'componentWillUpdate is deprecated',
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
'componentWillUpdate has been renamed',
],
{withoutStack: true},
);
@@ -748,9 +748,9 @@ describe('ReactComponentLifeCycle', () => {
);
}).toLowPriorityWarnDev(
[
'componentWillMount is deprecated',
'componentWillReceiveProps is deprecated',
'componentWillUpdate is deprecated',
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
'componentWillUpdate has been renamed',
],
{withoutStack: true},
);
@@ -815,7 +815,10 @@ describe('ReactComponentLifeCycle', () => {
{withoutStack: true},
);
}).toLowPriorityWarnDev(
['componentWillMount is deprecated', 'componentWillUpdate is deprecated'],
[
'componentWillMount has been renamed',
'componentWillUpdate has been renamed',
],
{withoutStack: true},
);

@@ -863,7 +866,7 @@ describe('ReactComponentLifeCycle', () => {
'https://fb.me/react-async-component-lifecycle-hooks',
{withoutStack: true},
);
}).toLowPriorityWarnDev(['componentWillMount is deprecated'], {
}).toLowPriorityWarnDev(['componentWillMount has been renamed'], {
withoutStack: true,
});

@@ -887,7 +890,7 @@ describe('ReactComponentLifeCycle', () => {
'https://fb.me/react-async-component-lifecycle-hooks',
{withoutStack: true},
);
}).toLowPriorityWarnDev(['componentWillReceiveProps is deprecated'], {
}).toLowPriorityWarnDev(['componentWillReceiveProps has been renamed'], {
withoutStack: true,
});
});
@@ -921,7 +924,10 @@ describe('ReactComponentLifeCycle', () => {
{withoutStack: true},
);
}).toLowPriorityWarnDev(
['componentWillMount is deprecated', 'componentWillUpdate is deprecated'],
[
'componentWillMount has been renamed',
'componentWillUpdate has been renamed',
],
{withoutStack: true},
);

@@ -967,7 +973,7 @@ describe('ReactComponentLifeCycle', () => {
'https://fb.me/react-async-component-lifecycle-hooks',
{withoutStack: true},
);
}).toLowPriorityWarnDev(['componentWillMount is deprecated'], {
}).toLowPriorityWarnDev(['componentWillMount has been renamed'], {
withoutStack: true,
});

@@ -990,7 +996,7 @@ describe('ReactComponentLifeCycle', () => {
'https://fb.me/react-async-component-lifecycle-hooks',
{withoutStack: true},
);
}).toLowPriorityWarnDev(['componentWillReceiveProps is deprecated'], {
}).toLowPriorityWarnDev(['componentWillReceiveProps has been renamed'], {
withoutStack: true,
});
});
@@ -1130,9 +1136,9 @@ describe('ReactComponentLifeCycle', () => {
ReactDOM.render(<MyComponent foo="bar" />, div),
).toLowPriorityWarnDev(
[
'componentWillMount is deprecated',
'componentWillReceiveProps is deprecated',
'componentWillUpdate is deprecated',
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
'componentWillUpdate has been renamed',
],
{withoutStack: true},
);
@@ -1403,22 +1409,32 @@ describe('ReactComponentLifeCycle', () => {
ReactDOM.render(<MyComponent x={1} />, container),
).toLowPriorityWarnDev(
[
'componentWillMount is deprecated and will be removed in the next major version. ' +
'Use componentDidMount instead. As a temporary workaround, ' +
'you can rename to UNSAFE_componentWillMount.' +
'\n\nPlease update the following components: MyComponent',
'componentWillReceiveProps is deprecated and will be removed in the next major version. ' +
'Use static getDerivedStateFromProps instead.' +
'\n\nPlease update the following components: MyComponent',
'componentWillUpdate is deprecated and will be removed in the next major version. ' +
'Use componentDidUpdate instead. As a temporary workaround, ' +
'you can rename to UNSAFE_componentWillUpdate.' +
'\n\nPlease update the following components: MyComponent',
/* eslint-disable max-len */
`Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.
* Move code with side effects to componentDidMount, and set initial state in the constructor.
* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.
Please update the following components: MyComponent`,
`Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.
* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.
Please update the following components: MyComponent`,
`Warning: componentWillUpdate has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.
* Move data fetching code or side effects to componentDidUpdate.
* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.
Please update the following components: MyComponent`,
/* eslint-enable max-len */
],
{withoutStack: true},
);

// Dedupe check (update and instantiate new
// Dedupe check (update and instantiate new)
ReactDOM.render(<MyComponent x={2} />, container);
ReactDOM.render(<MyComponent key="new" x={1} />, container);
});
17 changes: 7 additions & 10 deletions packages/react-dom/src/__tests__/ReactDOMServerLifecycles-test.js
Original file line number Diff line number Diff line change
@@ -229,7 +229,7 @@ describe('ReactDOMServerLifecycles', () => {

expect(() =>
ReactDOMServer.renderToString(<Component />),
).toLowPriorityWarnDev('componentWillMount() is deprecated', {
).toLowPriorityWarnDev('componentWillMount has been renamed', {
withoutStack: true,
});
expect(log).toEqual(['componentWillMount', 'UNSAFE_componentWillMount']);
@@ -286,10 +286,9 @@ describe('ReactDOMServerLifecycles', () => {

expect(() =>
ReactDOMServer.renderToString(<Component />),
).toLowPriorityWarnDev(
'Component: componentWillMount() is deprecated and will be removed in the next major version.',
{withoutStack: true},
);
).toLowPriorityWarnDev('componentWillMount has been renamed', {
withoutStack: true,
});
});

it('should warn about deprecated lifecycle hooks', () => {
@@ -302,11 +301,9 @@ describe('ReactDOMServerLifecycles', () => {

expect(() =>
ReactDOMServer.renderToString(<Component />),
).toLowPriorityWarnDev(
'Warning: Component: componentWillMount() is deprecated and will be removed ' +
'in the next major version.',
{withoutStack: true},
);
).toLowPriorityWarnDev('componentWillMount has been renamed', {
withoutStack: true,
});

// De-duped
ReactDOMServer.renderToString(<Component />);
Original file line number Diff line number Diff line change
@@ -362,20 +362,16 @@ describe('ReactDOMServerHydration', () => {
const element = document.createElement('div');
expect(() => {
element.innerHTML = ReactDOMServer.renderToString(markup);
}).toLowPriorityWarnDev(
['componentWillMount() is deprecated and will be removed'],
{withoutStack: true},
);
}).toLowPriorityWarnDev(['componentWillMount has been renamed'], {
withoutStack: true,
});
expect(element.textContent).toBe('Hi');

expect(() => {
expect(() => ReactDOM.hydrate(markup, element)).toWarnDev(
'Please update the following components to use componentDidMount instead: ComponentWithWarning',
);
}).toLowPriorityWarnDev(
['componentWillMount is deprecated and will be removed'],
{withoutStack: true},
);
ReactDOM.hydrate(markup, element);
}).toLowPriorityWarnDev(['componentWillMount has been renamed'], {
withoutStack: true,
});
expect(element.textContent).toBe('Hi');
});

13 changes: 6 additions & 7 deletions packages/react-dom/src/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
@@ -572,13 +572,12 @@ function resolve(
if (!didWarnAboutDeprecatedWillMount[componentName]) {
lowPriorityWarning(
false,
'%s: componentWillMount() is deprecated and will be ' +
'removed in the next major version. Read about the motivations ' +
'behind this change: ' +
'https://fb.me/react-async-component-lifecycle-hooks' +
'\n\n' +
'As a temporary workaround, you can rename to ' +
'UNSAFE_componentWillMount instead.',
// keep this warning in sync with ReactStrictModeWarning.js
'componentWillMount has been renamed, and is not recommended for use. ' +
'See https://fb.me/react-async-component-lifecycle-hooks for details.\n\n' +
'* Move code from componentWillMount to componentDidMount (preferred in most cases) ' +
'or the constructor.\n' +
'\nPlease update the following components: %s',
componentName,
);
didWarnAboutDeprecatedWillMount[componentName] = true;
7 changes: 1 addition & 6 deletions packages/react-reconciler/src/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
@@ -806,19 +806,14 @@ function mountClassInstance(
}

if (workInProgress.mode & StrictMode) {
ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(
workInProgress,
instance,
);

ReactStrictModeWarnings.recordLegacyContextWarning(
workInProgress,
instance,
);
}

if (warnAboutDeprecatedLifecycles) {
ReactStrictModeWarnings.recordDeprecationWarnings(
ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(
workInProgress,
instance,
);
3 changes: 1 addition & 2 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
@@ -2247,11 +2247,10 @@ function checkForNestedUpdates() {

function flushRenderPhaseStrictModeWarningsInDEV() {
if (__DEV__) {
ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
ReactStrictModeWarnings.flushLegacyContextWarning();

if (warnAboutDeprecatedLifecycles) {
ReactStrictModeWarnings.flushPendingDeprecationWarnings();
ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
}
}
}
434 changes: 221 additions & 213 deletions packages/react-reconciler/src/ReactStrictModeWarnings.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -2446,8 +2446,7 @@ describe('ReactIncremental', () => {
ReactNoop.render(<MyComponent />);
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
[
'componentWillReceiveProps: Please update the following components ' +
'to use static getDerivedStateFromProps instead: MyComponent',
'Using UNSAFE_componentWillReceiveProps in strict mode is not recommended',
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Please update the following components: MyComponent',
],
@@ -2887,26 +2886,35 @@ describe('ReactIncremental', () => {
expect(Scheduler).toFlushAndYield([]);
});

// We don't currently use fibers as keys. Re-enable this test if we
// ever do again.
// We sometimes use Maps with Fibers as keys.
it('does not break with a bad Map polyfill', () => {
const realMapSet = Map.prototype.set;

function triggerCodePathThatUsesFibersAsMapKeys() {
function Thing() {
throw new Error('No.');
}
// This class uses legacy context, which triggers warnings,
// the procedures for which use a Map to store fibers.
class Boundary extends React.Component {
state = {didError: false};
componentDidCatch() {
this.setState({didError: true});
}
static contextTypes = {
color: () => null,
};
render() {
return this.state.didError ? null : <Thing />;
}
}
ReactNoop.render(<Boundary />);
expect(Scheduler).toFlushWithoutYielding();
expect(() => {
expect(Scheduler).toFlushWithoutYielding();
}).toWarnDev(
['Legacy context API has been detected within a strict-mode tree'],
{withoutStack: true},
);
}

// First, verify that this code path normally receives Fibers as keys,
@@ -2952,6 +2960,7 @@ describe('ReactIncremental', () => {
};
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
try {
triggerCodePathThatUsesFibersAsMapKeys();
} finally {
Original file line number Diff line number Diff line change
@@ -316,10 +316,8 @@ describe('ReactDebugFiberPerf', () => {
addComment('Should not print a warning');
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
[
'componentWillMount: Please update the following components ' +
'to use componentDidMount instead: NotCascading' +
'\n\ncomponentWillReceiveProps: Please update the following components ' +
'to use static getDerivedStateFromProps instead: NotCascading',
'Using UNSAFE_componentWillMount in strict mode is not recommended',
'Using UNSAFE_componentWillReceiveProps in strict mode is not recommended',
],
{withoutStack: true},
);
@@ -358,14 +356,10 @@ describe('ReactDebugFiberPerf', () => {
addComment('Mount');
expect(() => expect(Scheduler).toFlushWithoutYielding()).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',
'Legacy context API has been detected within a strict-mode tree: \n\n' +
'Please update the following components: AllLifecycles',
'Using UNSAFE_componentWillMount in strict mode is not recommended',
'Using UNSAFE_componentWillReceiveProps in strict mode is not recommended',
'Using UNSAFE_componentWillUpdate in strict mode is not recommended',
'Legacy context API has been detected within a strict-mode tree',
],
{withoutStack: true},
);
Original file line number Diff line number Diff line change
@@ -76,8 +76,7 @@ describe('ReactIncrementalReflection', () => {
expect(() =>
expect(Scheduler).toFlushAndYield(['componentDidMount: true']),
).toWarnDev(
'componentWillMount: Please update the following components ' +
'to use componentDidMount instead: Component',
'Using UNSAFE_componentWillMount in strict mode is not recommended',
{withoutStack: true},
);

@@ -116,8 +115,7 @@ describe('ReactIncrementalReflection', () => {

ReactNoop.render(<Foo mount={true} />);
expect(() => expect(Scheduler).toFlushAndYield(['Component'])).toWarnDev(
'componentWillMount: Please update the following components ' +
'to use componentDidMount instead: Component',
'Using UNSAFE_componentWillMount in strict mode is not recommended',
{withoutStack: true},
);

@@ -222,10 +220,10 @@ describe('ReactIncrementalReflection', () => {
expect(() =>
expect(Scheduler).toFlushAndYield([['componentDidMount', span()]]),
).toWarnDev(
'componentWillMount: Please update the following components ' +
'to use componentDidMount instead: Component' +
'\n\ncomponentWillUpdate: Please update the following components ' +
'to use componentDidUpdate instead: Component',
[
'Using UNSAFE_componentWillMount in strict mode is not recommended',
'Using UNSAFE_componentWillUpdate in strict mode is not recommended',
],
{withoutStack: true},
);

Original file line number Diff line number Diff line change
@@ -346,8 +346,7 @@ describe('ReactIncrementalUpdates', () => {
}
ReactNoop.render(<Foo />);
expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
'componentWillReceiveProps: Please update the following components ' +
'to use static getDerivedStateFromProps instead: Foo',
'Using UNSAFE_componentWillReceiveProps in strict mode is not recommended',
{withoutStack: true},
);

104 changes: 65 additions & 39 deletions packages/react/src/__tests__/ReactStrictMode-test.internal.js
Original file line number Diff line number Diff line change
@@ -349,15 +349,26 @@ describe('ReactStrictMode', () => {
});
root.update(<AsyncRoot />);
expect(() => Scheduler.unstable_flushAll()).toWarnDev(
'Unsafe lifecycle methods were found within a strict-mode tree:' +
'\n\ncomponentWillMount: Please update the following components ' +
'to use componentDidMount instead: AsyncRoot' +
'\n\ncomponentWillReceiveProps: Please update the following components ' +
'to use static getDerivedStateFromProps instead: Bar, Foo' +
'\n\ncomponentWillUpdate: Please update the following components ' +
'to use componentDidUpdate instead: AsyncRoot' +
'\n\nLearn more about this warning here:' +
'\nhttps://fb.me/react-strict-mode-warnings',
[
/* eslint-disable max-len */
`Warning: Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move code with side effects to componentDidMount, and set initial state in the constructor.

Please update the following components: AsyncRoot`,
`Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state

Please update the following components: Bar, Foo`,
`Warning: Using UNSAFE_componentWillUpdate in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move data fetching code or side effects to componentDidUpdate.

Please update the following components: AsyncRoot`,
/* eslint-enable max-len */
],
{withoutStack: true},
);

@@ -396,26 +407,54 @@ describe('ReactStrictMode', () => {

expect(() => {
expect(() => Scheduler.unstable_flushAll()).toWarnDev(
'Unsafe lifecycle methods were found within a strict-mode tree:' +
'\n\ncomponentWillMount: Please update the following components ' +
'to use componentDidMount instead: AsyncRoot, Parent' +
'\n\ncomponentWillReceiveProps: Please update the following components ' +
'to use static getDerivedStateFromProps instead: Child, Parent' +
'\n\ncomponentWillUpdate: Please update the following components ' +
'to use componentDidUpdate instead: AsyncRoot, Parent' +
'\n\nLearn more about this warning here:' +
'\nhttps://fb.me/react-strict-mode-warnings',
[
/* eslint-disable max-len */
`Warning: Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move code with side effects to componentDidMount, and set initial state in the constructor.

Please update the following components: AsyncRoot`,
`Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state

Please update the following components: Child`,
`Warning: Using UNSAFE_componentWillUpdate in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move data fetching code or side effects to componentDidUpdate.

Please update the following components: AsyncRoot`,
/* eslint-enable max-len */
],
{withoutStack: true},
);
}).toLowPriorityWarnDev(
[
'componentWillMount is deprecated',
'componentWillReceiveProps is deprecated',
'componentWillUpdate is deprecated',
/* eslint-disable max-len */
`Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move code with side effects to componentDidMount, and set initial state in the constructor.
* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.

Please update the following components: Parent`,
`Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.

Please update the following components: Parent`,
`Warning: componentWillUpdate has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.

* Move data fetching code or side effects to componentDidUpdate.
* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder.

Please update the following components: Parent`,
/* eslint-enable max-len */
],
{withoutStack: true},
);

// Dedupe
root.update(<AsyncRoot />);
Scheduler.unstable_flushAll();
@@ -445,21 +484,13 @@ describe('ReactStrictMode', () => {
});
root.update(<AsyncRoot foo={true} />);
expect(() => Scheduler.unstable_flushAll()).toWarnDev(
'Unsafe lifecycle methods were found within a strict-mode tree:' +
'\n\ncomponentWillMount: Please update the following components ' +
'to use componentDidMount instead: Foo' +
'\n\nLearn more about this warning here:' +
'\nhttps://fb.me/react-strict-mode-warnings',
'Using UNSAFE_componentWillMount in strict mode is not recommended',
{withoutStack: true},
);

root.update(<AsyncRoot foo={false} />);
expect(() => Scheduler.unstable_flushAll()).toWarnDev(
'Unsafe lifecycle methods were found within a strict-mode tree:' +
'\n\ncomponentWillMount: Please update the following components ' +
'to use componentDidMount instead: Bar' +
'\n\nLearn more about this warning here:' +
'\nhttps://fb.me/react-strict-mode-warnings',
'Using UNSAFE_componentWillMount in strict mode is not recommended',
{withoutStack: true},
);

@@ -507,13 +538,8 @@ describe('ReactStrictMode', () => {
}

expect(() => ReactTestRenderer.create(<SyncRoot />)).toWarnDev(
'Unsafe lifecycle methods were found within a strict-mode tree:' +
'\n in StrictMode (at **)' +
'\n in SyncRoot (at **)' +
'\n\ncomponentWillReceiveProps: Please update the following components ' +
'to use static getDerivedStateFromProps instead: Bar, Foo' +
'\n\nLearn more about this warning here:' +
'\nhttps://fb.me/react-strict-mode-warnings',
'Using UNSAFE_componentWillReceiveProps in strict mode is not recommended',
{withoutStack: true},
);

// Dedupe
Original file line number Diff line number Diff line change
@@ -51,10 +51,7 @@ describe('create-react-class-integration', () => {
});

expect(() => ReactNative.render(<View />, 1)).toLowPriorityWarnDev(
'componentWillMount is deprecated and will be removed in the next major version. ' +
'Use componentDidMount instead. As a temporary workaround, ' +
'you can rename to UNSAFE_componentWillMount.' +
'\n\nPlease update the following components: MyNativeComponent',
'componentWillMount has been renamed',
{withoutStack: true},
);
});
@@ -68,9 +65,7 @@ describe('create-react-class-integration', () => {
});

expect(() => ReactNative.render(<View />, 1)).toLowPriorityWarnDev(
'componentWillReceiveProps is deprecated and will be removed in the next major version. ' +
'Use static getDerivedStateFromProps instead.' +
'\n\nPlease update the following components: MyNativeComponent',
'componentWillReceiveProps has been renamed',
{withoutStack: true},
);
});
18 changes: 9 additions & 9 deletions packages/react/src/__tests__/createReactClassIntegration-test.js
Original file line number Diff line number Diff line change
@@ -560,9 +560,9 @@ describe('create-react-class-integration', () => {
);
}).toLowPriorityWarnDev(
[
'componentWillMount is deprecated',
'componentWillReceiveProps is deprecated',
'componentWillUpdate is deprecated',
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
'componentWillUpdate has been renamed',
],
{withoutStack: true},
);
@@ -604,9 +604,9 @@ describe('create-react-class-integration', () => {
);
}).toLowPriorityWarnDev(
[
'componentWillMount is deprecated',
'componentWillReceiveProps is deprecated',
'componentWillUpdate is deprecated',
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
'componentWillUpdate has been renamed',
],
{withoutStack: true},
);
@@ -649,9 +649,9 @@ describe('create-react-class-integration', () => {
ReactDOM.render(<Component foo="bar" />, div),
).toLowPriorityWarnDev(
[
'componentWillMount is deprecated',
'componentWillReceiveProps is deprecated',
'componentWillUpdate is deprecated',
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
'componentWillUpdate has been renamed',
],
{withoutStack: true},
);
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import typeof * as PersistentFeatureFlagsType from './ReactFeatureFlags.persiste
export const debugRenderPhaseSideEffects = false;
export const debugRenderPhaseSideEffectsForStrictMode = false;
export const enableUserTimingAPI = __DEV__;
export const warnAboutDeprecatedLifecycles = false;
export const warnAboutDeprecatedLifecycles = true;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
export const enableProfilerTimer = false;
export const enableSchedulerTracing = false;
13 changes: 11 additions & 2 deletions scripts/print-warnings/print-warnings.js
Original file line number Diff line number Diff line change
@@ -52,8 +52,17 @@ function transform(file, enc, cb) {

// warning messages can be concatenated (`+`) at runtime, so here's
// a trivial partial evaluator that interprets the literal value
const warningMsgLiteral = evalToString(node.arguments[1]);
warnings.add(JSON.stringify(warningMsgLiteral));
try {
const warningMsgLiteral = evalToString(node.arguments[1]);
warnings.add(JSON.stringify(warningMsgLiteral));
} catch (error) {
console.error(
'Failed to extract warning message from',
file.path
);
console.error(astPath.node.loc);
throw error;
}
}
},
},