diff --git a/src/isomorphic/classic/element/ReactDebugCurrentFrame.js b/src/isomorphic/classic/element/ReactDebugCurrentFrame.js index eb1d1ecaa4..e5e966b706 100644 --- a/src/isomorphic/classic/element/ReactDebugCurrentFrame.js +++ b/src/isomorphic/classic/element/ReactDebugCurrentFrame.js @@ -14,13 +14,13 @@ import type { Fiber } from 'ReactFiber'; import type { DebugID } from 'ReactInstanceType'; -import type { ComponentTreeHookDevType } from '../../hooks/ReactComponentTreeHook'; +import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook'; const ReactDebugCurrentFrame = {}; if (__DEV__) { // how do a state that ReactComponentTreeHook is using the ComponentTreeHookDevType type? - const ReactComponentTreeHook: ComponentTreeHookDevType = require('ReactComponentTreeHook'); + const ReactComponentTreeHook: ComponentTreeHookDevType = (require('ReactComponentTreeHook'): any); const { getStackAddendumByID, getStackAddendumByWorkInProgressFiber, diff --git a/src/isomorphic/hooks/ReactComponentTreeHook.js b/src/isomorphic/hooks/ReactComponentTreeHook.js index c7e2141b34..5d8cdf616d 100644 --- a/src/isomorphic/hooks/ReactComponentTreeHook.js +++ b/src/isomorphic/hooks/ReactComponentTreeHook.js @@ -71,6 +71,7 @@ export type ComponentTreeHookDevType = { getUpdateCount: (DebugID) => any, getChildIDs: (DebugID) => any, getRegisteredIDs: () => any, + getElement: () => any, }; var ReactComponentTreeHook: ComponentTreeHookType = { diff --git a/src/renderers/shared/ReactDebugTool.js b/src/renderers/shared/ReactDebugTool.js index 1d07610ade..b0e91811e0 100644 --- a/src/renderers/shared/ReactDebugTool.js +++ b/src/renderers/shared/ReactDebugTool.js @@ -22,6 +22,7 @@ var warning = require('fbjs/lib/warning'); import type { ReactElement } from 'ReactElementType'; import type { DebugID } from 'ReactInstanceType'; import type { Operation } from 'ReactHostOperationHistoryHook'; +import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook'; type Hook = any; @@ -68,7 +69,7 @@ var ReactDebugTool = ((null: any): typeof ReactDebugTool); if (__DEV__) { const hooks = []; const didHookThrowForEvent = {}; - const ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook'); + const ReactComponentTreeHook: ComponentTreeHookDevType = (require('react/lib/ReactComponentTreeHook'): any); const { purgeUnmountedComponents, getOwnerID, @@ -78,6 +79,7 @@ if (__DEV__) { getUpdateCount, getChildIDs, getRegisteredIDs, + getElement, } = ReactComponentTreeHook; const callHook = function(event, fn, context, arg1, arg2, arg3, arg4, arg5) { @@ -118,24 +120,22 @@ if (__DEV__) { var lifeCycleTimerHasWarned = false; const clearHistory = function() { - if (purgeUnmountedComponents) { - purgeUnmountedComponents(); - } + purgeUnmountedComponents(); ReactHostOperationHistoryHook.clearHistory(); }; const getTreeSnapshot = function(registeredIDs) { - return registeredIDs && registeredIDs.reduce((tree, id) => { - var ownerID = getOwnerID && getOwnerID(id); - var parentID = getParentID && getParentID(id); + return registeredIDs.reduce((tree, id) => { + var ownerID = getOwnerID(id); + var parentID = getParentID(id); tree[id] = { - displayName: getDisplayName && getDisplayName(id), - text: getText && getText(id), - updateCount: getUpdateCount && getUpdateCount(id), - childIDs: getChildIDs && getChildIDs(id), + displayName: getDisplayName(id), + text: getText(id), + updateCount: getUpdateCount(id), + childIDs: getChildIDs(id), // Text nodes don't have owners but this is close enough. ownerID: ownerID || - parentID && getOwnerID && getOwnerID(parentID) || + parentID && getOwnerID(parentID) || 0, parentID, }; @@ -156,16 +156,14 @@ if (__DEV__) { } if (previousMeasurements.length || previousOperations.length) { - var registeredIDs = getRegisteredIDs && getRegisteredIDs(); + var registeredIDs = getRegisteredIDs(); - if (registeredIDs) { - flushHistory.push({ - duration: performanceNow() - previousStartTime, - measurements: previousMeasurements || [], - operations: previousOperations || [], - treeSnapshot: getTreeSnapshot(registeredIDs), - }); - } + flushHistory.push({ + duration: performanceNow() - previousStartTime, + measurements: previousMeasurements || [], + operations: previousOperations || [], + treeSnapshot: getTreeSnapshot(registeredIDs), + }); } clearHistory(); @@ -268,7 +266,7 @@ if (__DEV__) { if (!isProfiling || !canUsePerformanceMeasure) { return false; } - var element = (ReactComponentTreeHook: any).getElement(debugID); + var element = getElement(debugID); if (element == null || typeof element !== 'object') { return false; } @@ -295,7 +293,7 @@ if (__DEV__) { } var markName = `${debugID}::${markType}`; - var displayName = getDisplayName && getDisplayName(debugID) || 'Unknown'; + var displayName = getDisplayName(debugID) || 'Unknown'; // Chrome has an issue of dropping markers recorded too fast: // https://bugs.chromium.org/p/chromium/issues/detail?id=640652 diff --git a/src/renderers/shared/stack/reconciler/ReactRef.js b/src/renderers/shared/stack/reconciler/ReactRef.js index 155dab6c80..7f2e5c4567 100644 --- a/src/renderers/shared/stack/reconciler/ReactRef.js +++ b/src/renderers/shared/stack/reconciler/ReactRef.js @@ -16,6 +16,7 @@ var ReactOwner = require('ReactOwner'); import type { ReactInstance } from 'ReactInstanceType'; import type { ReactElement } from 'ReactElementType'; +import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook'; var ReactRef = {}; @@ -23,7 +24,7 @@ if (__DEV__) { var ReactCompositeComponentTypes = require('ReactCompositeComponentTypes'); var { getStackAddendumByID, - } = require('react/lib/ReactComponentTreeHook'); + }: ComponentTreeHookDevType = (require('react/lib/ReactComponentTreeHook'): any); var warning = require('fbjs/lib/warning'); var warnedAboutStatelessRefs = {}; @@ -55,7 +56,7 @@ function attachRef(ref, component, owner) { 'Stateless function components cannot be given refs. ' + 'Attempts to access this ref will fail.%s%s', info, - getStackAddendumByID && getStackAddendumByID(component._debugID) + getStackAddendumByID(component._debugID) ); } } diff --git a/src/shared/utils/flattenChildren.js b/src/shared/utils/flattenChildren.js index f2992becdf..2a8165c829 100644 --- a/src/shared/utils/flattenChildren.js +++ b/src/shared/utils/flattenChildren.js @@ -12,6 +12,8 @@ 'use strict'; +import type { ComponentTreeHookDevType } from 'ReactComponentTreeHook'; + var KeyEscapeUtils = require('KeyEscapeUtils'); var traverseAllChildren = require('traverseAllChildren'); var warning = require('fbjs/lib/warning'); @@ -51,7 +53,7 @@ function flattenSingleChildIntoContext( if (!ReactComponentTreeHook) { ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook'); } - const { getStackAddendumByID } = ReactComponentTreeHook; + const { getStackAddendumByID }: ComponentTreeHookDevType = (ReactComponentTreeHook: any); if (!keyUnique) { warning( @@ -60,7 +62,7 @@ function flattenSingleChildIntoContext( '`%s`. Child keys must be unique; when two children share a key, only ' + 'the first child will be used.%s', KeyEscapeUtils.unescape(name), - getStackAddendumByID && getStackAddendumByID(selfDebugID) + getStackAddendumByID(selfDebugID) ); } }