Skip to content

Commit 3b1d23c

Browse files
committed
Merge branch 'master' into getSnapshotBeforeUpdate
2 parents 47c7afb + 8c20615 commit 3b1d23c

File tree

3 files changed

+1
-418
lines changed

3 files changed

+1
-418
lines changed

packages/react-test-renderer/src/ReactShallowRenderer.js

Lines changed: 0 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,12 @@
88

99
import React from 'react';
1010
import {isForwardRef} from 'react-is';
11-
import {warnAboutDeprecatedLifecycles} from 'shared/ReactFeatureFlags';
1211
import describeComponentFrame from 'shared/describeComponentFrame';
1312
import getComponentName from 'shared/getComponentName';
1413
import emptyObject from 'fbjs/lib/emptyObject';
1514
import invariant from 'fbjs/lib/invariant';
16-
import lowPriorityWarning from 'shared/lowPriorityWarning';
1715
import shallowEqual from 'fbjs/lib/shallowEqual';
1816
import checkPropTypes from 'prop-types/checkPropTypes';
19-
import warning from 'fbjs/lib/warning';
20-
21-
let didWarnAboutLegacyWillMount;
22-
let didWarnAboutLegacyWillReceiveProps;
23-
let didWarnAboutLegacyWillUpdate;
24-
let didWarnAboutUndefinedDerivedState;
25-
let didWarnAboutUninitializedState;
26-
let didWarnAboutLegacyLifecyclesAndDerivedState;
27-
28-
if (__DEV__) {
29-
if (warnAboutDeprecatedLifecycles) {
30-
didWarnAboutLegacyWillMount = {};
31-
didWarnAboutLegacyWillReceiveProps = {};
32-
didWarnAboutLegacyWillUpdate = {};
33-
}
34-
didWarnAboutUndefinedDerivedState = {};
35-
didWarnAboutUninitializedState = {};
36-
didWarnAboutLegacyLifecyclesAndDerivedState = {};
37-
}
3817

3918
class ReactShallowRenderer {
4019
static createRenderer = function() {
@@ -106,28 +85,6 @@ class ReactShallowRenderer {
10685
this._updater,
10786
);
10887

109-
if (__DEV__) {
110-
if (typeof element.type.getDerivedStateFromProps === 'function') {
111-
if (
112-
this._instance.state === null ||
113-
this._instance.state === undefined
114-
) {
115-
const componentName =
116-
getName(element.type, this._instance) || 'Unknown';
117-
if (!didWarnAboutUninitializedState[componentName]) {
118-
warning(
119-
false,
120-
'%s: Did not properly initialize state during construction. ' +
121-
'Expected state to be an object, but it was %s.',
122-
componentName,
123-
this._instance.state === null ? 'null' : 'undefined',
124-
);
125-
didWarnAboutUninitializedState[componentName] = true;
126-
}
127-
}
128-
}
129-
}
130-
13188
this._updateStateFromStaticLifecycle(element.props);
13289

13390
if (element.type.hasOwnProperty('contextTypes')) {
@@ -183,31 +140,6 @@ class ReactShallowRenderer {
183140
const beforeState = this._newState;
184141

185142
if (typeof this._instance.componentWillMount === 'function') {
186-
if (__DEV__) {
187-
// Don't warn about react-lifecycles-compat polyfilled components
188-
if (
189-
warnAboutDeprecatedLifecycles &&
190-
this._instance.componentWillMount.__suppressDeprecationWarning !==
191-
true
192-
) {
193-
const componentName = getName(element.type, this._instance);
194-
if (!didWarnAboutLegacyWillMount[componentName]) {
195-
lowPriorityWarning(
196-
false,
197-
'%s: componentWillMount() is deprecated and will be ' +
198-
'removed in the next major version. Read about the motivations ' +
199-
'behind this change: ' +
200-
'https://fb.me/react-async-component-lifecycle-hooks' +
201-
'\n\n' +
202-
'As a temporary workaround, you can rename to ' +
203-
'UNSAFE_componentWillMount instead.',
204-
componentName,
205-
);
206-
didWarnAboutLegacyWillMount[componentName] = true;
207-
}
208-
}
209-
}
210-
211143
// In order to support react-lifecycles-compat polyfilled components,
212144
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
213145
if (typeof element.type.getDerivedStateFromProps !== 'function') {
@@ -242,26 +174,6 @@ class ReactShallowRenderer {
242174

243175
if (oldProps !== props) {
244176
if (typeof this._instance.componentWillReceiveProps === 'function') {
245-
if (__DEV__) {
246-
if (warnAboutDeprecatedLifecycles) {
247-
const componentName = getName(element.type, this._instance);
248-
if (!didWarnAboutLegacyWillReceiveProps[componentName]) {
249-
lowPriorityWarning(
250-
false,
251-
'%s: componentWillReceiveProps() is deprecated and ' +
252-
'will be removed in the next major version. Use ' +
253-
'static getDerivedStateFromProps() instead. Read about the ' +
254-
'motivations behind this change: ' +
255-
'https://fb.me/react-async-component-lifecycle-hooks' +
256-
'\n\n' +
257-
'As a temporary workaround, you can rename to ' +
258-
'UNSAFE_componentWillReceiveProps instead.',
259-
componentName,
260-
);
261-
didWarnAboutLegacyWillReceiveProps[componentName] = true;
262-
}
263-
}
264-
}
265177
// In order to support react-lifecycles-compat polyfilled components,
266178
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
267179
if (typeof element.type.getDerivedStateFromProps !== 'function') {
@@ -300,26 +212,6 @@ class ReactShallowRenderer {
300212

301213
if (shouldUpdate) {
302214
if (typeof this._instance.componentWillUpdate === 'function') {
303-
if (__DEV__) {
304-
if (warnAboutDeprecatedLifecycles) {
305-
const componentName = getName(element.type, this._instance);
306-
if (!didWarnAboutLegacyWillUpdate[componentName]) {
307-
lowPriorityWarning(
308-
false,
309-
'%s: componentWillUpdate() is deprecated and will be ' +
310-
'removed in the next major version. Read about the motivations ' +
311-
'behind this change: ' +
312-
'https://fb.me/react-async-component-lifecycle-hooks' +
313-
'\n\n' +
314-
'As a temporary workaround, you can rename to ' +
315-
'UNSAFE_componentWillUpdate instead.',
316-
componentName,
317-
);
318-
didWarnAboutLegacyWillUpdate[componentName] = true;
319-
}
320-
}
321-
}
322-
323215
// In order to support react-lifecycles-compat polyfilled components,
324216
// Unsafe lifecycles should not be invoked for any component with the new gDSFP.
325217
if (typeof type.getDerivedStateFromProps !== 'function') {
@@ -351,87 +243,12 @@ class ReactShallowRenderer {
351243
const {type} = this._element;
352244

353245
if (typeof type.getDerivedStateFromProps === 'function') {
354-
if (__DEV__) {
355-
const instance = this._instance;
356-
357-
// If getDerivedStateFromProps() is defined, "unsafe" lifecycles won't be called.
358-
// Warn about these lifecycles if they are present.
359-
// Don't warn about react-lifecycles-compat polyfilled methods though.
360-
let foundWillMountName = null;
361-
let foundWillReceivePropsName = null;
362-
let foundWillUpdateName = null;
363-
if (
364-
typeof instance.componentWillMount === 'function' &&
365-
instance.componentWillMount.__suppressDeprecationWarning !== true
366-
) {
367-
foundWillMountName = 'componentWillMount';
368-
} else if (typeof instance.UNSAFE_componentWillMount === 'function') {
369-
foundWillMountName = 'UNSAFE_componentWillMount';
370-
}
371-
if (
372-
typeof instance.componentWillReceiveProps === 'function' &&
373-
instance.componentWillReceiveProps.__suppressDeprecationWarning !==
374-
true
375-
) {
376-
foundWillReceivePropsName = 'componentWillReceiveProps';
377-
} else if (
378-
typeof instance.UNSAFE_componentWillReceiveProps === 'function'
379-
) {
380-
foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
381-
}
382-
if (typeof instance.componentWillUpdate === 'function') {
383-
foundWillUpdateName = 'componentWillUpdate';
384-
} else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
385-
foundWillUpdateName = 'UNSAFE_componentWillUpdate';
386-
}
387-
if (
388-
foundWillMountName !== null ||
389-
foundWillReceivePropsName !== null ||
390-
foundWillUpdateName !== null
391-
) {
392-
const componentName = getName(type, instance) || 'Component';
393-
if (!didWarnAboutLegacyLifecyclesAndDerivedState[componentName]) {
394-
warning(
395-
false,
396-
'Unsafe legacy lifecycles will not be called for components using ' +
397-
'the new getDerivedStateFromProps() API.\n\n' +
398-
'%s uses getDerivedStateFromProps() but also contains the following legacy lifecycles:' +
399-
'%s%s%s\n\n' +
400-
'The above lifecycles should be removed. Learn more about this warning here:\n' +
401-
'https://fb.me/react-async-component-lifecycle-hooks',
402-
componentName,
403-
foundWillMountName !== null ? `\n ${foundWillMountName}` : '',
404-
foundWillReceivePropsName !== null
405-
? `\n ${foundWillReceivePropsName}`
406-
: '',
407-
foundWillUpdateName !== null ? `\n ${foundWillUpdateName}` : '',
408-
);
409-
didWarnAboutLegacyLifecyclesAndDerivedState[componentName] = true;
410-
}
411-
}
412-
}
413-
414246
const partialState = type.getDerivedStateFromProps.call(
415247
null,
416248
props,
417249
this._instance.state,
418250
);
419251

420-
if (__DEV__) {
421-
if (partialState === undefined) {
422-
const componentName = getName(type, this._instance);
423-
if (!didWarnAboutUndefinedDerivedState[componentName]) {
424-
warning(
425-
false,
426-
'%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' +
427-
'You have returned undefined.',
428-
componentName,
429-
);
430-
didWarnAboutUndefinedDerivedState[componentName] = componentName;
431-
}
432-
}
433-
}
434-
435252
if (partialState != null) {
436253
const oldState = this._newState || this._instance.state;
437254
const newState = Object.assign({}, oldState, partialState);

packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.internal.js

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)