Add a fallback component name for warnings (#12429)
Dan Abramov committed
Mar 22, 2018 at 17:22 UTC
dcbb4301f0a505c8bac72f7beac1604869a3846a
1 file changed
+15
-20
packages/react-reconciler/src/ReactFiberClassComponent.js
+15
-20
@@ -213,7 +213,7 @@ export default function(
213
shouldUpdate !== undefined,
214
'%s.shouldComponentUpdate(): Returned undefined instead of a ' +
215
'boolean value. Make sure to return true or false.',
216
- getComponentName(workInProgress) || 'Unknown',
216
+ getComponentName(workInProgress) || 'Component',
217
);
218
}
219
@@ -364,23 +364,18 @@ export default function(
364
name,
365
name,
366
);
367
- }
368
-
369
- const state = instance.state;
370
- if (state && (typeof state !== 'object' || isArray(state))) {
371
- warning(
372
- false,
373
- '%s.state: must be set to an object or null',
374
- getComponentName(workInProgress),
375
- );
376
- }
377
- if (typeof instance.getChildContext === 'function') {
378
- warning(
379
- typeof type.childContextTypes === 'object',
380
- '%s.getChildContext(): childContextTypes must be defined in order to ' +
381
- 'use getChildContext().',
382
- getComponentName(workInProgress),
383
- );
367
+ const state = instance.state;
368
+ if (state && (typeof state !== 'object' || isArray(state))) {
369
+ warning(false, '%s.state: must be set to an object or null', name);
370
+ }
371
+ if (typeof instance.getChildContext === 'function') {
372
+ warning(
373
+ typeof type.childContextTypes === 'object',
374
+ '%s.getChildContext(): childContextTypes must be defined in order to ' +
375
+ 'use getChildContext().',
376
+ name,
377
+ );
378
+ }
379
}
380
}
381
@@ -491,7 +486,7 @@ export default function(
486
'%s.componentWillMount(): Assigning directly to this.state is ' +
487
"deprecated (except inside a component's " +
488
'constructor). Use setState instead.',
494
- getComponentName(workInProgress),
489
+ getComponentName(workInProgress) || 'Component',
490
);
491
}
492
updater.enqueueReplaceState(instance, instance.state, null);
@@ -549,7 +544,7 @@ export default function(
544
true) ||
545
typeof instance.UNSAFE_componentWillReceiveProps === 'function'
546
) {
552
- const componentName = getComponentName(workInProgress) || 'Unknown';
547
+ const componentName = getComponentName(workInProgress) || 'Component';
548
if (!didWarnAboutWillReceivePropsAndDerivedState[componentName]) {
549
warning(
550
false,