Add DEV-only checks for assumption about instance properties (#14128)
Dan Abramov committed
Nov 6, 2018 at 22:28 UTC
b67c1a2ee1720628c6d47cab977aeb38564d2df6
1 file changed
+65
packages/react-reconciler/src/ReactFiberCommitWork.js
+65
@@ -54,6 +54,7 @@ import {
54
import getComponentName from 'shared/getComponentName';
55
import invariant from 'shared/invariant';
56
import warningWithoutStack from 'shared/warningWithoutStack';
57
+import warning from 'shared/warning';
58
59
import {NoWork} from './ReactFiberExpirationTime';
60
import {onCommitUnmount} from './ReactFiberDevToolsHook';
@@ -232,6 +233,22 @@ function commitBeforeMutationLifeCycles(
233
// We could update instance props and state here,
234
// but instead we rely on them being set during last render.
235
// TODO: revisit this when we implement resuming.
236
+ if (__DEV__) {
237
+ if (finishedWork.type === finishedWork.elementType) {
238
+ warning(
239
+ instance.props === finishedWork.memoizedProps,
240
+ 'Expected instance props to match memoized props before ' +
241
+ 'getSnapshotBeforeUpdate. This is likely due to a bug in React. ' +
242
+ 'Please file an issue.',
243
+ );
244
+ warning(
245
+ instance.state === finishedWork.memoizedState,
246
+ 'Expected instance state to match memoized state before ' +
247
+ 'getSnapshotBeforeUpdate. This is likely due to a bug in React. ' +
248
+ 'Please file an issue.',
249
+ );
250
+ }
251
+ }
252
const snapshot = instance.getSnapshotBeforeUpdate(
253
finishedWork.elementType === finishedWork.type
254
? prevProps
@@ -352,6 +369,22 @@ function commitLifeCycles(
369
// We could update instance props and state here,
370
// but instead we rely on them being set during last render.
371
// TODO: revisit this when we implement resuming.
372
+ if (__DEV__) {
373
+ if (finishedWork.type === finishedWork.elementType) {
374
+ warning(
375
+ instance.props === finishedWork.memoizedProps,
376
+ 'Expected instance props to match memoized props before ' +
377
+ 'componentDidMount. This is likely due to a bug in React. ' +
378
+ 'Please file an issue.',
379
+ );
380
+ warning(
381
+ instance.state === finishedWork.memoizedState,
382
+ 'Expected instance state to match memoized state before ' +
383
+ 'componentDidMount. This is likely due to a bug in React. ' +
384
+ 'Please file an issue.',
385
+ );
386
+ }
387
+ }
388
instance.componentDidMount();
389
stopPhaseTimer();
390
} else {
@@ -364,6 +397,22 @@ function commitLifeCycles(
397
// We could update instance props and state here,
398
// but instead we rely on them being set during last render.
399
// TODO: revisit this when we implement resuming.
400
+ if (__DEV__) {
401
+ if (finishedWork.type === finishedWork.elementType) {
402
+ warning(
403
+ instance.props === finishedWork.memoizedProps,
404
+ 'Expected instance props to match memoized props before ' +
405
+ 'componentDidUpdate. This is likely due to a bug in React. ' +
406
+ 'Please file an issue.',
407
+ );
408
+ warning(
409
+ instance.state === finishedWork.memoizedState,
410
+ 'Expected instance state to match memoized state before ' +
411
+ 'componentDidUpdate. This is likely due to a bug in React. ' +
412
+ 'Please file an issue.',
413
+ );
414
+ }
415
+ }
416
instance.componentDidUpdate(
417
prevProps,
418
prevState,
@@ -374,6 +423,22 @@ function commitLifeCycles(
423
}
424
const updateQueue = finishedWork.updateQueue;
425
if (updateQueue !== null) {
426
+ if (__DEV__) {
427
+ if (finishedWork.type === finishedWork.elementType) {
428
+ warning(
429
+ instance.props === finishedWork.memoizedProps,
430
+ 'Expected instance props to match memoized props before ' +
431
+ 'processing the update queue. This is likely due to a bug in React. ' +
432
+ 'Please file an issue.',
433
+ );
434
+ warning(
435
+ instance.state === finishedWork.memoizedState,
436
+ 'Expected instance state to match memoized state before ' +
437
+ 'processing the update queue. This is likely due to a bug in React. ' +
438
+ 'Please file an issue.',
439
+ );
440
+ }
441
+ }
442
// We could update instance props and state here,
443
// but instead we rely on them being set during last render.
444
// TODO: revisit this when we implement resuming.