Skip to content

Commit

Permalink
Remove feature flag around 'getDerivedStateFromProps' bug fix (facebo…
Browse files Browse the repository at this point in the history
…ok#13022)

**what is the change?:**
Basically undoes facebook@4b2e65d#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.
  • Loading branch information
flarnie authored Jun 11, 2018
1 parent 1594409 commit 3925301
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 64 deletions.
15 changes: 6 additions & 9 deletions packages/react-reconciler/src/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
debugRenderPhaseSideEffects,
debugRenderPhaseSideEffectsForStrictMode,
warnAboutDeprecatedLifecycles,
fireGetDerivedStateFromPropsOnStateUpdates,
} from 'shared/ReactFeatureFlags';
import ReactStrictModeWarnings from './ReactStrictModeWarnings';
import {isMounted} from 'react-reconciler/reflection';
Expand Down Expand Up @@ -949,14 +948,12 @@ function updateClassInstance(
}

if (typeof getDerivedStateFromProps === 'function') {
if (fireGetDerivedStateFromPropsOnStateUpdates || oldProps !== newProps) {
applyDerivedStateFromProps(
workInProgress,
getDerivedStateFromProps,
newProps,
);
newState = workInProgress.memoizedState;
}
applyDerivedStateFromProps(
workInProgress,
getDerivedStateFromProps,
newProps,
);
newState = workInProgress.memoizedState;
}

const shouldUpdate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1520,51 +1520,6 @@ describe('ReactIncremental', () => {
expect(ReactNoop.flush()).toEqual(['Child']);
});

it('does not call getDerivedStateFromProps for state-only updates if feature flag is disabled', () => {
jest.resetModules();
ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
ReactFeatureFlags.fireGetDerivedStateFromPropsOnStateUpdates = false;
React = require('react');
ReactNoop = require('react-noop-renderer');

let ops = [];
let instance;

class LifeCycle extends React.Component {
state = {};
static getDerivedStateFromProps(props, prevState) {
ops.push('getDerivedStateFromProps');
return {foo: 'foo'};
}
changeState() {
this.setState({foo: 'bar'});
}
componentDidUpdate() {
ops.push('componentDidUpdate');
}
render() {
ops.push('render');
instance = this;
return null;
}
}

ReactNoop.render(<LifeCycle />);
ReactNoop.flush();

expect(ops).toEqual(['getDerivedStateFromProps', 'render']);
expect(instance.state).toEqual({foo: 'foo'});

ops = [];

instance.changeState();
ReactNoop.flush();

expect(ops).toEqual(['render', 'componentDidUpdate']);
expect(instance.state).toEqual({foo: 'bar'});
});

xit('does not call componentWillReceiveProps for state-only updates', () => {
let ops = [];

Expand Down
3 changes: 0 additions & 3 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export const warnAboutLegacyContextAPI = false;
// Gather advanced timing metrics for Profiler subtrees.
export const enableProfilerTimer = __PROFILE__;

// Fires getDerivedStateFromProps for state *or* props changes
export const fireGetDerivedStateFromPropsOnStateUpdates = true;

// Only used in www builds.
export function addUserTimingListener() {
invariant(false, 'Not implemented.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = __DEV__;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = __DEV__;
export const fireGetDerivedStateFromPropsOnStateUpdates = true;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const fireGetDerivedStateFromPropsOnStateUpdates = true;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const {
warnAboutDeprecatedLifecycles,
replayFailedUnitOfWorkWithInvokeGuardedCallback,
enableProfilerTimer,
fireGetDerivedStateFromPropsOnStateUpdates,
} = require('ReactFeatureFlags');

// The rest of the flags are static for better dead code elimination.
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;
export const enableProfilerTimer = __PROFILE__;
export const fireGetDerivedStateFromPropsOnStateUpdates = true;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.persistent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = false;
export const fireGetDerivedStateFromPropsOnStateUpdates = true;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
export const enableProfilerTimer = false;
export const fireGetDerivedStateFromPropsOnStateUpdates = true;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const {
replayFailedUnitOfWorkWithInvokeGuardedCallback,
warnAboutDeprecatedLifecycles,
enableProfilerTimer,
fireGetDerivedStateFromPropsOnStateUpdates,
} = require('ReactFeatureFlags');

// The rest of the flags are static for better dead code elimination.
Expand Down

0 comments on commit 3925301

Please sign in to comment.