Skip to content

Commit c17bf38

Browse files
authored
Get a few more Fiber tests passing (#8149)
* Get a few more Fiber tests passing * Fix Flow and wrap in __DEV__
1 parent 6d747a7 commit c17bf38

File tree

6 files changed

+53
-8
lines changed

6 files changed

+53
-8
lines changed

src/isomorphic/classic/element/ReactElementValidator.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ var ReactElement = require('ReactElement');
2525
var checkReactTypeSpec = require('checkReactTypeSpec');
2626

2727
var canDefineProperty = require('canDefineProperty');
28+
var getComponentName = require('getComponentName');
2829
var getIteratorFn = require('getIteratorFn');
2930
var warning = require('warning');
3031

3132
function getDeclarationErrorAddendum() {
3233
if (ReactCurrentOwner.current) {
33-
var name = ReactCurrentOwner.current.getName();
34+
var name = getComponentName(ReactCurrentOwner.current);
3435
if (name) {
3536
return ' Check the render method of `' + name + '`.';
3637
}
@@ -94,7 +95,7 @@ function validateExplicitKey(element, parentType) {
9495
element._owner !== ReactCurrentOwner.current) {
9596
// Give the component that originally created this child.
9697
childOwner =
97-
` It was passed a child from ${element._owner.getName()}.`;
98+
` It was passed a child from ${getComponentName(element._owner)}.`;
9899
}
99100

100101
warning(

src/isomorphic/hooks/ReactComponentTreeHook.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
var ReactCurrentOwner = require('ReactCurrentOwner');
1616

17+
var getComponentName = require('getComponentName');
1718
var invariant = require('invariant');
1819
var warning = require('warning');
1920

@@ -310,7 +311,7 @@ var ReactComponentTreeHook = {
310311
info += describeComponentFrame(
311312
name,
312313
topElement._source,
313-
owner && owner.getName()
314+
owner && getComponentName(owner)
314315
);
315316
}
316317

src/renderers/dom/shared/CSSPropertyOperations.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var ReactInstrumentation = require('ReactInstrumentation');
1717

1818
var camelizeStyleName = require('camelizeStyleName');
1919
var dangerousStyleValue = require('dangerousStyleValue');
20+
var getComponentName = require('getComponentName');
2021
var hyphenateStyleName = require('hyphenateStyleName');
2122
var memoizeStringOnly = require('memoizeStringOnly');
2223
var warning = require('warning');
@@ -114,7 +115,7 @@ if (__DEV__) {
114115

115116
var checkRenderMessage = function(owner) {
116117
if (owner) {
117-
var name = owner.getName();
118+
var name = getComponentName(owner);
118119
if (name) {
119120
return ' Check the render method of `' + name + '`.';
120121
}

src/renderers/dom/shared/utils/LinkedValueUtils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
var React = require('React');
1515

16+
var getComponentName = require('getComponentName');
1617
var invariant = require('invariant');
1718
var warning = require('warning');
1819

@@ -88,7 +89,7 @@ var propTypes = {
8889
var loggedTypeFailures = {};
8990
function getDeclarationErrorAddendum(owner) {
9091
if (owner) {
91-
var name = owner.getName();
92+
var name = getComponentName(owner);
9293
if (name) {
9394
return ' Check the render method of `' + name + '`.';
9495
}

src/renderers/dom/shared/validateDOMNesting.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'use strict';
1313

1414
var emptyFunction = require('emptyFunction');
15+
var getComponentName = require('getComponentName');
1516
var warning = require('warning');
1617

1718
var validateDOMNesting = emptyFunction;
@@ -371,16 +372,16 @@ if (__DEV__) {
371372

372373
var UNKNOWN = '(unknown)';
373374
var childOwnerNames = childOwners.slice(deepestCommon + 1).map(
374-
(inst) => inst.getName() || UNKNOWN
375+
(inst) => getComponentName(inst) || UNKNOWN
375376
);
376377
var ancestorOwnerNames = ancestorOwners.slice(deepestCommon + 1).map(
377-
(inst) => inst.getName() || UNKNOWN
378+
(inst) => getComponentName(inst) || UNKNOWN
378379
);
379380
var ownerInfo = [].concat(
380381
// If the parent and child instances have a common owner ancestor, start
381382
// with that -- otherwise we just start with the parent's owners.
382383
deepestCommon !== -1 ?
383-
childOwners[deepestCommon].getName() || UNKNOWN :
384+
getComponentName(childOwners[deepestCommon]) || UNKNOWN :
384385
[],
385386
ancestorOwnerNames,
386387
ancestorTag,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
10+
* @providesModule getComponentName
11+
*/
12+
13+
'use strict';
14+
15+
import type { ReactInstance } from 'ReactInstanceType';
16+
import type { Fiber } from 'ReactFiber';
17+
18+
function getComponentName(instanceOrFiber : ReactInstance | Fiber) : string | null {
19+
if (__DEV__) {
20+
if (typeof instanceOrFiber.getName === 'function') {
21+
// Stack reconciler
22+
const instance = ((instanceOrFiber : any) : ReactInstance);
23+
return instance.getName() || 'Component';
24+
}
25+
if (typeof instanceOrFiber.tag === 'number') {
26+
// Fiber reconciler
27+
const fiber = ((instanceOrFiber : any) : Fiber);
28+
const {type} = fiber;
29+
if (typeof type === 'string') {
30+
return type;
31+
}
32+
if (typeof type === 'function') {
33+
return type.displayName || type.name || null;
34+
}
35+
}
36+
}
37+
return null;
38+
}
39+
40+
module.exports = getComponentName;

0 commit comments

Comments
 (0)