Skip to content
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

Remove feature flag around 'getDerivedStateFromProps' bug fix #13022

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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