Remove feature flag around 'getDerivedStateFromProps' bug fix (#13022)
**what is the change?:** Basically undoes https://github.com/facebook/react/commit/4b2e65d32e3adec7d4ef5ddd5fcb35e617e0cde6#diff-904ceabd8a1e9a07ab1d876d843d62e1 **why make this change?:** We rolled out this fix internally and in open source weeks ago, and now we're cleaning up. **test plan:** Ran tests and lint, and really we have been testing this because the flag is open internally as of last week or so. **issue:** Internal task T29948812 has some info.
Flarnie Marchan committed
Jun 11, 2018 at 16:31 UTC
392530104c00c25074ce38e1f7e1dd363018c7ce
10 files changed
+6
-64
packages/react-reconciler/src/ReactFiberClassComponent.js
+6
-9
@@ -15,7 +15,6 @@ import {
15
debugRenderPhaseSideEffects,
16
debugRenderPhaseSideEffectsForStrictMode,
17
warnAboutDeprecatedLifecycles,
18
- fireGetDerivedStateFromPropsOnStateUpdates,
18
} from 'shared/ReactFeatureFlags';
19
import ReactStrictModeWarnings from './ReactStrictModeWarnings';
20
import {isMounted} from 'react-reconciler/reflection';
@@ -949,14 +948,12 @@ function updateClassInstance(
948
}
949
950
if (typeof getDerivedStateFromProps === 'function') {
952
- if (fireGetDerivedStateFromPropsOnStateUpdates || oldProps !== newProps) {
953
- applyDerivedStateFromProps(
954
- workInProgress,
955
- getDerivedStateFromProps,
956
- newProps,
957
- );
958
- newState = workInProgress.memoizedState;
959
- }
951
+ applyDerivedStateFromProps(
952
+ workInProgress,
953
+ getDerivedStateFromProps,
954
+ newProps,
955
+ );
956
+ newState = workInProgress.memoizedState;
957
}
958
959
const shouldUpdate =
packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js
-45
@@ -1520,51 +1520,6 @@ describe('ReactIncremental', () => {
1520
expect(ReactNoop.flush()).toEqual(['Child']);
1521
});
1522
1523
- it('does not call getDerivedStateFromProps for state-only updates if feature flag is disabled', () => {
1524
- jest.resetModules();
1525
- ReactFeatureFlags = require('shared/ReactFeatureFlags');
1526
- ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
1527
- ReactFeatureFlags.fireGetDerivedStateFromPropsOnStateUpdates = false;
1528
- React = require('react');
1529
- ReactNoop = require('react-noop-renderer');
1530
-
1531
- let ops = [];
1532
- let instance;
1533
-
1534
- class LifeCycle extends React.Component {
1535
- state = {};
1536
- static getDerivedStateFromProps(props, prevState) {
1537
- ops.push('getDerivedStateFromProps');
1538
- return {foo: 'foo'};
1539
- }
1540
- changeState() {
1541
- this.setState({foo: 'bar'});
1542
- }
1543
- componentDidUpdate() {
1544
- ops.push('componentDidUpdate');
1545
- }
1546
- render() {
1547
- ops.push('render');
1548
- instance = this;
1549
- return null;
1550
- }
1551
- }
1552
-
1553
- ReactNoop.render(<LifeCycle />);
1554
- ReactNoop.flush();
1555
-
1556
- expect(ops).toEqual(['getDerivedStateFromProps', 'render']);
1557
- expect(instance.state).toEqual({foo: 'foo'});
1558
-
1559
- ops = [];
1560
-
1561
- instance.changeState();
1562
- ReactNoop.flush();
1563
-
1564
- expect(ops).toEqual(['render', 'componentDidUpdate']);
1565
- expect(instance.state).toEqual({foo: 'bar'});
1566
- });
1567
-
1523
xit('does not call componentWillReceiveProps for state-only updates', () => {
1524
let ops = [];
1525
packages/shared/ReactFeatureFlags.js
-3
@@ -39,9 +39,6 @@ export const warnAboutLegacyContextAPI = false;
39
// Gather advanced timing metrics for Profiler subtrees.
40
export const enableProfilerTimer = __PROFILE__;
41
42
-// Fires getDerivedStateFromProps for state *or* props changes
43
-export const fireGetDerivedStateFromPropsOnStateUpdates = true;
44
-
42
// Only used in www builds.
43
export function addUserTimingListener() {
44
invariant(false, 'Not implemented.');
packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js
-1
@@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false;
21
export const warnAboutLegacyContextAPI = __DEV__;
22
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
23
export const enableProfilerTimer = __DEV__;
24
-export const fireGetDerivedStateFromPropsOnStateUpdates = true;
24
25
// Only used in www builds.
26
export function addUserTimingListener() {
packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js
-1
@@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false;
21
export const warnAboutLegacyContextAPI = false;
22
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
23
export const enableProfilerTimer = __PROFILE__;
24
-export const fireGetDerivedStateFromPropsOnStateUpdates = true;
24
25
// Only used in www builds.
26
export function addUserTimingListener() {
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -21,7 +21,6 @@ export const {
21
warnAboutDeprecatedLifecycles,
22
replayFailedUnitOfWorkWithInvokeGuardedCallback,
23
enableProfilerTimer,
24
- fireGetDerivedStateFromPropsOnStateUpdates,
24
} = require('ReactFeatureFlags');
25
26
// The rest of the flags are static for better dead code elimination.
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -21,7 +21,6 @@ export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
21
export const warnAboutDeprecatedLifecycles = false;
22
export const warnAboutLegacyContextAPI = false;
23
export const enableProfilerTimer = __PROFILE__;
24
-export const fireGetDerivedStateFromPropsOnStateUpdates = true;
24
25
// Only used in www builds.
26
export function addUserTimingListener() {
packages/shared/forks/ReactFeatureFlags.persistent.js
-1
@@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false;
21
export const warnAboutLegacyContextAPI = false;
22
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
23
export const enableProfilerTimer = false;
24
-export const fireGetDerivedStateFromPropsOnStateUpdates = true;
24
25
// Only used in www builds.
26
export function addUserTimingListener() {
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false;
21
export const warnAboutLegacyContextAPI = false;
22
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
23
export const enableProfilerTimer = false;
24
-export const fireGetDerivedStateFromPropsOnStateUpdates = true;
24
25
// Only used in www builds.
26
export function addUserTimingListener() {
packages/shared/forks/ReactFeatureFlags.www.js
-1
@@ -19,7 +19,6 @@ export const {
19
replayFailedUnitOfWorkWithInvokeGuardedCallback,
20
warnAboutDeprecatedLifecycles,
21
enableProfilerTimer,
22
- fireGetDerivedStateFromPropsOnStateUpdates,
22
} = require('ReactFeatureFlags');
23
24
// The rest of the flags are static for better dead code elimination.