23
import shallowEqual from 'shared/shallowEqual';
24
import getComponentName from 'shared/getComponentName';
25
import invariant from 'shared/invariant';
26
-import warning from 'shared/warning';
26
+import warningWithoutStack from 'shared/warningWithoutStack';
27
28
import {startPhaseTimer, stopPhaseTimer} from './ReactDebugFiberPerf';
29
import {StrictMode} from './ReactTypeOfMode';
82
const key = `${callerName}_${(callback: any)}`;
83
if (!didWarnOnInvalidCallback.has(key)) {
84
didWarnOnInvalidCallback.add(key);
85
- warning(
85
+ warningWithoutStack(
86
false,
87
'%s(...): Expected the last optional `callback` argument to be a ' +
88
'function. Instead received: %s.',
97
const componentName = getComponentName(type) || 'Component';
98
if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
99
didWarnAboutUndefinedDerivedState.add(componentName);
100
- warning(
100
+ warningWithoutStack(
101
false,
102
'%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' +
103
'You have returned undefined.',
245
stopPhaseTimer();
246
247
if (__DEV__) {
248
- warning(
248
+ warningWithoutStack(
249
shouldUpdate !== undefined,
250
'%s.shouldComponentUpdate(): Returned undefined instead of a ' +
251
'boolean value. Make sure to return true or false.',
274
275
if (!renderPresent) {
276
if (type.prototype && typeof type.prototype.render === 'function') {
277
- warning(
277
+ warningWithoutStack(
278
false,
279
'%s(...): No `render` method found on the returned component ' +
280
'instance: did you accidentally return an object from the constructor?',
281
name,
282
);
283
} else {
284
- warning(
284
+ warningWithoutStack(
285
false,
286
'%s(...): No `render` method found on the returned component ' +
287
'instance: you may have forgotten to define `render`.',
294
!instance.getInitialState ||
295
instance.getInitialState.isReactClassApproved ||
296
instance.state;
297
- warning(
297
+ warningWithoutStack(
298
noGetInitialStateOnES6,
299
'getInitialState was defined on %s, a plain JavaScript class. ' +
300
'This is only supported for classes created using React.createClass. ' +
304
const noGetDefaultPropsOnES6 =
305
!instance.getDefaultProps ||
306
instance.getDefaultProps.isReactClassApproved;
307
- warning(
307
+ warningWithoutStack(
308
noGetDefaultPropsOnES6,
309
'getDefaultProps was defined on %s, a plain JavaScript class. ' +
310
'This is only supported for classes created using React.createClass. ' +
312
name,
313
);
314
const noInstancePropTypes = !instance.propTypes;
315
- warning(
315
+ warningWithoutStack(
316
noInstancePropTypes,
317
'propTypes was defined as an instance property on %s. Use a static ' +
318
'property to define propTypes instead.',
319
name,
320
);
321
const noInstanceContextTypes = !instance.contextTypes;
322
- warning(
322
+ warningWithoutStack(
323
noInstanceContextTypes,
324
'contextTypes was defined as an instance property on %s. Use a static ' +
325
'property to define contextTypes instead.',
327
);
328
const noComponentShouldUpdate =
329
typeof instance.componentShouldUpdate !== 'function';
330
- warning(
330
+ warningWithoutStack(
331
noComponentShouldUpdate,
332
'%s has a method called ' +
333
'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
340
type.prototype.isPureReactComponent &&
341
typeof instance.shouldComponentUpdate !== 'undefined'
342
) {
343
- warning(
343
+ warningWithoutStack(
344
false,
345
'%s has a method called shouldComponentUpdate(). ' +
346
'shouldComponentUpdate should not be used when extending React.PureComponent. ' +
350
}
351
const noComponentDidUnmount =
352
typeof instance.componentDidUnmount !== 'function';
353
- warning(
353
+ warningWithoutStack(
354
noComponentDidUnmount,
355
'%s has a method called ' +
356
'componentDidUnmount(). But there is no such lifecycle method. ' +
359
);
360
const noComponentDidReceiveProps =
361
typeof instance.componentDidReceiveProps !== 'function';
362
- warning(
362
+ warningWithoutStack(
363
noComponentDidReceiveProps,
364
'%s has a method called ' +
365
'componentDidReceiveProps(). But there is no such lifecycle method. ' +
370
);
371
const noComponentWillRecieveProps =
372
typeof instance.componentWillRecieveProps !== 'function';
373
- warning(
373
+ warningWithoutStack(
374
noComponentWillRecieveProps,
375
'%s has a method called ' +
376
'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?',
378
);
379
const noUnsafeComponentWillRecieveProps =
380
typeof instance.UNSAFE_componentWillRecieveProps !== 'function';
381
- warning(
381
+ warningWithoutStack(
382
noUnsafeComponentWillRecieveProps,
383
'%s has a method called ' +
384
'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?',
385
name,
386
);
387
const hasMutatedProps = instance.props !== workInProgress.pendingProps;
388
- warning(
388
+ warningWithoutStack(
389
instance.props === undefined || !hasMutatedProps,
390
'%s(...): When calling super() in `%s`, make sure to pass ' +
391
"up the same props that your component's constructor was passed.",
393
name,
394
);
395
const noInstanceDefaultProps = !instance.defaultProps;
396
- warning(
396
+ warningWithoutStack(
397
noInstanceDefaultProps,
398
'Setting defaultProps as an instance property on %s is not supported and will be ignored.' +
399
' Instead, define defaultProps as a static property on %s.',
407
!didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(type)
408
) {
409
didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(type);
410
- warning(
410
+ warningWithoutStack(
411
false,
412
'%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' +
413
'This component defines getSnapshotBeforeUpdate() only.',
417
418
const noInstanceGetDerivedStateFromProps =
419
typeof instance.getDerivedStateFromProps !== 'function';
420
- warning(
420
+ warningWithoutStack(
421
noInstanceGetDerivedStateFromProps,
422
'%s: getDerivedStateFromProps() is defined as an instance method ' +
423
'and will be ignored. Instead, declare it as a static method.',
425
);
426
const noInstanceGetDerivedStateFromCatch =
427
typeof instance.getDerivedStateFromCatch !== 'function';
428
- warning(
428
+ warningWithoutStack(
429
noInstanceGetDerivedStateFromCatch,
430
'%s: getDerivedStateFromCatch() is defined as an instance method ' +
431
'and will be ignored. Instead, declare it as a static method.',
433
);
434
const noStaticGetSnapshotBeforeUpdate =
435
typeof type.getSnapshotBeforeUpdate !== 'function';
436
- warning(
436
+ warningWithoutStack(
437
noStaticGetSnapshotBeforeUpdate,
438
'%s: getSnapshotBeforeUpdate() is defined as a static method ' +
439
'and will be ignored. Instead, declare it as an instance method.',
441
);
442
const state = instance.state;
443
if (state && (typeof state !== 'object' || isArray(state))) {
444
- warning(false, '%s.state: must be set to an object or null', name);
444
+ warningWithoutStack(
445
+ false,
446
+ '%s.state: must be set to an object or null',
447
+ name,
448
+ );
449
}
450
if (typeof instance.getChildContext === 'function') {
447
- warning(
451
+ warningWithoutStack(
452
typeof type.childContextTypes === 'object',
453
'%s.getChildContext(): childContextTypes must be defined in order to ' +
454
'use getChildContext().',
503
const componentName = getComponentName(ctor) || 'Component';
504
if (!didWarnAboutUninitializedState.has(componentName)) {
505
didWarnAboutUninitializedState.add(componentName);
502
- warning(
506
+ warningWithoutStack(
507
false,
508
'%s: Did not properly initialize state during construction. ' +
509
'Expected state to be an object, but it was %s.',
561
: 'getSnapshotBeforeUpdate()';
562
if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(componentName)) {
563
didWarnAboutLegacyLifecyclesAndDerivedState.add(componentName);
560
- warning(
564
+ warningWithoutStack(
565
false,
566
'Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' +
567
'%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n' +
604
605
if (oldState !== instance.state) {
606
if (__DEV__) {
603
- warning(
607
+ warningWithoutStack(
608
false,
609
'%s.componentWillMount(): Assigning directly to this.state is ' +
610
"deprecated (except inside a component's " +
638
getComponentName(workInProgress.type) || 'Component';
639
if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
640
didWarnAboutStateAssignmentForComponent.add(componentName);
637
- warning(
641
+ warningWithoutStack(
642
false,
643
'%s.componentWillReceiveProps(): Assigning directly to ' +
644
"this.state is deprecated (except inside a component's " +