mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #9096 from trueadm/component-tree-hook-dev
[Fiber] Split dev methods within ReactComponentTreeHook
This commit is contained in:
@@ -20,9 +20,11 @@ const ReactDebugCurrentFrame = {};
|
||||
if (__DEV__) {
|
||||
var {
|
||||
getStackAddendumByID,
|
||||
getStackAddendumByWorkInProgressFiber,
|
||||
getCurrentStackAddendum,
|
||||
} = require('ReactComponentTreeHook');
|
||||
var {
|
||||
getStackAddendumByWorkInProgressFiber,
|
||||
} = require('ReactFiberComponentTreeHook');
|
||||
|
||||
// Component that is being worked on
|
||||
ReactDebugCurrentFrame.current = (null : Fiber | DebugID | null);
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
'use strict';
|
||||
|
||||
var ReactCurrentOwner = require('ReactCurrentOwner');
|
||||
var ReactComponentTreeHook = require('ReactComponentTreeHook');
|
||||
var ReactElement = require('ReactElement');
|
||||
|
||||
var checkReactTypeSpec = require('checkReactTypeSpec');
|
||||
@@ -31,6 +30,9 @@ var getIteratorFn = require('getIteratorFn');
|
||||
if (__DEV__) {
|
||||
var warning = require('fbjs/lib/warning');
|
||||
var ReactDebugCurrentFrame = require('ReactDebugCurrentFrame');
|
||||
var {
|
||||
getCurrentStackAddendum,
|
||||
} = require('ReactComponentTreeHook');
|
||||
}
|
||||
|
||||
function getDeclarationErrorAddendum() {
|
||||
@@ -122,7 +124,7 @@ function validateExplicitKey(element, parentType) {
|
||||
'%s%s See https://fb.me/react-warning-keys for more information.%s',
|
||||
currentComponentErrorInfo,
|
||||
childOwner,
|
||||
ReactComponentTreeHook.getCurrentStackAddendum(element)
|
||||
getCurrentStackAddendum(element)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -225,7 +227,7 @@ var ReactElementValidator = {
|
||||
info += getDeclarationErrorAddendum();
|
||||
}
|
||||
|
||||
info += ReactComponentTreeHook.getCurrentStackAddendum();
|
||||
info += getCurrentStackAddendum();
|
||||
|
||||
warning(
|
||||
false,
|
||||
|
||||
@@ -13,17 +13,13 @@
|
||||
'use strict';
|
||||
|
||||
var ReactCurrentOwner = require('ReactCurrentOwner');
|
||||
var ReactTypeOfWork = require('ReactTypeOfWork');
|
||||
var {
|
||||
IndeterminateComponent,
|
||||
FunctionalComponent,
|
||||
ClassComponent,
|
||||
HostComponent,
|
||||
} = ReactTypeOfWork;
|
||||
|
||||
var getComponentName = require('getComponentName');
|
||||
getStackAddendumByWorkInProgressFiber,
|
||||
describeComponentFrame,
|
||||
} = require('ReactFiberComponentTreeHook');
|
||||
var invariant = require('fbjs/lib/invariant');
|
||||
var warning = require('fbjs/lib/warning');
|
||||
var getComponentName = require('getComponentName');
|
||||
|
||||
import type { ReactElement, Source } from 'ReactElementType';
|
||||
import type { DebugID } from 'ReactInstanceType';
|
||||
@@ -159,17 +155,6 @@ function purgeDeep(id) {
|
||||
}
|
||||
}
|
||||
|
||||
function describeComponentFrame(name, source, ownerName) {
|
||||
return '\n in ' + (name || 'Unknown') + (
|
||||
source ?
|
||||
' (at ' + source.fileName.replace(/^.*[\\\/]/, '') + ':' +
|
||||
source.lineNumber + ')' :
|
||||
ownerName ?
|
||||
' (created by ' + ownerName + ')' :
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
function getDisplayName(element: ?ReactElement): string {
|
||||
if (element == null) {
|
||||
return '#empty';
|
||||
@@ -183,10 +168,11 @@ function getDisplayName(element: ?ReactElement): string {
|
||||
}
|
||||
|
||||
function describeID(id: DebugID): string {
|
||||
var name = ReactComponentTreeHook.getDisplayName(id);
|
||||
var element = ReactComponentTreeHook.getElement(id);
|
||||
var ownerID = ReactComponentTreeHook.getOwnerID(id);
|
||||
var ownerName;
|
||||
const name = ReactComponentTreeHook.getDisplayName(id);
|
||||
const element = ReactComponentTreeHook.getElement(id);
|
||||
const ownerID = ReactComponentTreeHook.getOwnerID(id);
|
||||
let ownerName;
|
||||
|
||||
if (ownerID) {
|
||||
ownerName = ReactComponentTreeHook.getDisplayName(ownerID);
|
||||
}
|
||||
@@ -196,26 +182,7 @@ function describeID(id: DebugID): string {
|
||||
'building stack',
|
||||
id
|
||||
);
|
||||
return describeComponentFrame(name, element && element._source, ownerName);
|
||||
}
|
||||
|
||||
function describeFiber(fiber : Fiber) : string {
|
||||
switch (fiber.tag) {
|
||||
case IndeterminateComponent:
|
||||
case FunctionalComponent:
|
||||
case ClassComponent:
|
||||
case HostComponent:
|
||||
var owner = fiber._debugOwner;
|
||||
var source = fiber._debugSource;
|
||||
var name = getComponentName(fiber);
|
||||
var ownerName = null;
|
||||
if (owner) {
|
||||
ownerName = getComponentName(owner);
|
||||
}
|
||||
return describeComponentFrame(name, source, ownerName);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
return describeComponentFrame(name || '', element && element._source, ownerName || '');
|
||||
}
|
||||
|
||||
var ReactComponentTreeHook = {
|
||||
@@ -356,7 +323,7 @@ var ReactComponentTreeHook = {
|
||||
const workInProgress = ((currentOwner : any) : Fiber);
|
||||
// Safe because if current owner exists, we are reconciling,
|
||||
// and it is guaranteed to be the work-in-progress version.
|
||||
info += ReactComponentTreeHook.getStackAddendumByWorkInProgressFiber(workInProgress);
|
||||
info += getStackAddendumByWorkInProgressFiber(workInProgress);
|
||||
} else if (typeof currentOwner._debugID === 'number') {
|
||||
info += ReactComponentTreeHook.getStackAddendumByID(currentOwner._debugID);
|
||||
}
|
||||
@@ -373,20 +340,6 @@ var ReactComponentTreeHook = {
|
||||
return info;
|
||||
},
|
||||
|
||||
// This function can only be called with a work-in-progress fiber and
|
||||
// only during begin or complete phase. Do not call it under any other
|
||||
// circumstances.
|
||||
getStackAddendumByWorkInProgressFiber(workInProgress : Fiber) : string {
|
||||
var info = '';
|
||||
var node = workInProgress;
|
||||
do {
|
||||
info += describeFiber(node);
|
||||
// Otherwise this return pointer might point to the wrong tree:
|
||||
node = node.return;
|
||||
} while (node);
|
||||
return info;
|
||||
},
|
||||
|
||||
getChildIDs(id: DebugID): Array<DebugID> {
|
||||
var item = getItem(id);
|
||||
return item ? item.childIDs : [];
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
'use strict';
|
||||
|
||||
var DOMProperty = require('DOMProperty');
|
||||
var ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
||||
var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
|
||||
|
||||
var warning = require('fbjs/lib/warning');
|
||||
@@ -20,10 +19,16 @@ var warning = require('fbjs/lib/warning');
|
||||
var warnedProperties = {};
|
||||
var rARIA = new RegExp('^(aria)-[' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$');
|
||||
|
||||
if (__DEV__) {
|
||||
var {
|
||||
getStackAddendumByID,
|
||||
} = require('react/lib/ReactComponentTreeHook');
|
||||
}
|
||||
|
||||
function getStackAddendum(debugID) {
|
||||
if (debugID != null) {
|
||||
// This can only happen on Stack
|
||||
return ReactComponentTreeHook.getStackAddendumByID(debugID);
|
||||
return getStackAddendumByID(debugID);
|
||||
} else {
|
||||
// This can only happen on Fiber
|
||||
return ReactDebugCurrentFiber.getCurrentFiberStackAddendum();
|
||||
|
||||
@@ -11,17 +11,21 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
||||
var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
|
||||
|
||||
var warning = require('fbjs/lib/warning');
|
||||
|
||||
if (__DEV__) {
|
||||
var {
|
||||
getStackAddendumByID,
|
||||
} = require('react/lib/ReactComponentTreeHook');
|
||||
}
|
||||
|
||||
var didWarnValueNull = false;
|
||||
|
||||
function getStackAddendum(debugID) {
|
||||
if (debugID != null) {
|
||||
// This can only happen on Stack
|
||||
return ReactComponentTreeHook.getStackAddendumByID(debugID);
|
||||
return getStackAddendumByID(debugID);
|
||||
} else {
|
||||
// This can only happen on Fiber
|
||||
return ReactDebugCurrentFiber.getCurrentFiberStackAddendum();
|
||||
|
||||
@@ -18,7 +18,7 @@ type LifeCyclePhase = 'render' | 'getChildContext';
|
||||
|
||||
if (__DEV__) {
|
||||
var getComponentName = require('getComponentName');
|
||||
var { getStackAddendumByWorkInProgressFiber } = require('react/lib/ReactComponentTreeHook');
|
||||
var { getStackAddendumByWorkInProgressFiber } = require('ReactFiberComponentTreeHook');
|
||||
}
|
||||
|
||||
function getCurrentFiberOwnerName() : string | null {
|
||||
|
||||
@@ -37,7 +37,7 @@ var {
|
||||
const { reset } = require('ReactFiberStack');
|
||||
var {
|
||||
getStackAddendumByWorkInProgressFiber,
|
||||
} = require('react/lib/ReactComponentTreeHook');
|
||||
} = require('ReactFiberComponentTreeHook');
|
||||
var { logCapturedError } = require('ReactFiberErrorLogger');
|
||||
var { invokeGuardedCallback } = require('ReactErrorUtils');
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright 2016-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
* @providesModule ReactFiberComponentTreeHook
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var ReactTypeOfWork = require('ReactTypeOfWork');
|
||||
var {
|
||||
IndeterminateComponent,
|
||||
FunctionalComponent,
|
||||
ClassComponent,
|
||||
HostComponent,
|
||||
} = ReactTypeOfWork;
|
||||
var getComponentName = require('getComponentName');
|
||||
|
||||
import type { Fiber } from 'ReactFiber';
|
||||
|
||||
function describeComponentFrame(name, source: any, ownerName) {
|
||||
return '\n in ' + (name || 'Unknown') + (
|
||||
source ?
|
||||
' (at ' + source.fileName.replace(/^.*[\\\/]/, '') + ':' +
|
||||
source.lineNumber + ')' :
|
||||
ownerName ?
|
||||
' (created by ' + ownerName + ')' :
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
function describeFiber(fiber : Fiber) : string {
|
||||
switch (fiber.tag) {
|
||||
case IndeterminateComponent:
|
||||
case FunctionalComponent:
|
||||
case ClassComponent:
|
||||
case HostComponent:
|
||||
var owner = fiber._debugOwner;
|
||||
var source = fiber._debugSource;
|
||||
var name = getComponentName(fiber);
|
||||
var ownerName = null;
|
||||
if (owner) {
|
||||
ownerName = getComponentName(owner);
|
||||
}
|
||||
return describeComponentFrame(name, source, ownerName);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// This function can only be called with a work-in-progress fiber and
|
||||
// only during begin or complete phase. Do not call it under any other
|
||||
// circumstances.
|
||||
function getStackAddendumByWorkInProgressFiber(workInProgress : Fiber) : string {
|
||||
var info = '';
|
||||
var node = workInProgress;
|
||||
do {
|
||||
info += describeFiber(node);
|
||||
// Otherwise this return pointer might point to the wrong tree:
|
||||
node = node.return;
|
||||
} while (node);
|
||||
return info;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getStackAddendumByWorkInProgressFiber,
|
||||
describeComponentFrame,
|
||||
};
|
||||
Reference in New Issue
Block a user