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

Add DEV-only checks for assumption about instance properties #14128

Merged
merged 1 commit into from
Nov 6, 2018
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
65 changes: 65 additions & 0 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
import getComponentName from 'shared/getComponentName';
import invariant from 'shared/invariant';
import warningWithoutStack from 'shared/warningWithoutStack';
import warning from 'shared/warning';

import {NoWork} from './ReactFiberExpirationTime';
import {onCommitUnmount} from './ReactFiberDevToolsHook';
Expand Down Expand Up @@ -232,6 +233,22 @@ function commitBeforeMutationLifeCycles(
// We could update instance props and state here,
// but instead we rely on them being set during last render.
// TODO: revisit this when we implement resuming.
if (__DEV__) {
if (finishedWork.type === finishedWork.elementType) {
warning(
instance.props === finishedWork.memoizedProps,
'Expected instance props to match memoized props before ' +
'getSnapshotBeforeUpdate. This is likely due to a bug in React. ' +
'Please file an issue.',
);
warning(
instance.state === finishedWork.memoizedState,
'Expected instance state to match memoized state before ' +
'getSnapshotBeforeUpdate. This is likely due to a bug in React. ' +
'Please file an issue.',
);
}
}
const snapshot = instance.getSnapshotBeforeUpdate(
finishedWork.elementType === finishedWork.type
? prevProps
Expand Down Expand Up @@ -352,6 +369,22 @@ function commitLifeCycles(
// We could update instance props and state here,
// but instead we rely on them being set during last render.
// TODO: revisit this when we implement resuming.
if (__DEV__) {
if (finishedWork.type === finishedWork.elementType) {
warning(
instance.props === finishedWork.memoizedProps,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the whole point of your previous PR is that memoizedProps does not include the resolved default props, but instance.props does?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh duh, didn't notice the outer check :D

'Expected instance props to match memoized props before ' +
'componentDidMount. This is likely due to a bug in React. ' +
'Please file an issue.',
);
warning(
instance.state === finishedWork.memoizedState,
'Expected instance state to match memoized state before ' +
'componentDidMount. This is likely due to a bug in React. ' +
'Please file an issue.',
);
}
}
instance.componentDidMount();
stopPhaseTimer();
} else {
Expand All @@ -364,6 +397,22 @@ function commitLifeCycles(
// We could update instance props and state here,
// but instead we rely on them being set during last render.
// TODO: revisit this when we implement resuming.
if (__DEV__) {
if (finishedWork.type === finishedWork.elementType) {
warning(
instance.props === finishedWork.memoizedProps,
'Expected instance props to match memoized props before ' +
'componentDidUpdate. This is likely due to a bug in React. ' +
'Please file an issue.',
);
warning(
instance.state === finishedWork.memoizedState,
'Expected instance state to match memoized state before ' +
'componentDidUpdate. This is likely due to a bug in React. ' +
'Please file an issue.',
);
}
}
instance.componentDidUpdate(
prevProps,
prevState,
Expand All @@ -374,6 +423,22 @@ function commitLifeCycles(
}
const updateQueue = finishedWork.updateQueue;
if (updateQueue !== null) {
if (__DEV__) {
if (finishedWork.type === finishedWork.elementType) {
warning(
instance.props === finishedWork.memoizedProps,
'Expected instance props to match memoized props before ' +
'processing the update queue. This is likely due to a bug in React. ' +
'Please file an issue.',
);
warning(
instance.state === finishedWork.memoizedState,
'Expected instance state to match memoized state before ' +
'processing the update queue. This is likely due to a bug in React. ' +
'Please file an issue.',
);
}
}
// We could update instance props and state here,
// but instead we rely on them being set during last render.
// TODO: revisit this when we implement resuming.
Expand Down