From e4345134b099a5469de9ac13423bc1e64b3e1e84 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 15 Jun 2018 17:28:21 -0700 Subject: [PATCH 01/13] react-test-renderer injects itself into DevTools if present --- .../src/ReactTestHostConfig.js | 9 +- .../src/ReactTestRenderer.js | 15 +++ .../src/ReactTestRendererComponentTree.js | 19 +++ ...ofilerDevToolsIntegration-test.internal.js | 108 ++++++++++++++++++ 4 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 packages/react-test-renderer/src/ReactTestRendererComponentTree.js create mode 100644 packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js diff --git a/packages/react-test-renderer/src/ReactTestHostConfig.js b/packages/react-test-renderer/src/ReactTestHostConfig.js index 1a1e74a1e27df..8215f2653f16b 100644 --- a/packages/react-test-renderer/src/ReactTestHostConfig.js +++ b/packages/react-test-renderer/src/ReactTestHostConfig.js @@ -7,6 +7,7 @@ * @flow */ +import {precacheFiberNode} from './ReactTestRendererComponentTree'; import * as TestRendererScheduling from './ReactTestRendererScheduling'; export type Type = string; @@ -117,13 +118,15 @@ export function createInstance( hostContext: Object, internalInstanceHandle: Object, ): Instance { - return { + const instance = { type, props, children: [], rootContainerInstance, tag: 'INSTANCE', }; + precacheFiberNode(internalInstanceHandle, instance); + return instance; } export function appendInitialChild( @@ -172,10 +175,12 @@ export function createTextInstance( hostContext: Object, internalInstanceHandle: Object, ): TextInstance { - return { + const textInstance = { text, tag: 'TEXT', }; + precacheFiberNode(internalInstanceHandle, textInstance); + return textInstance; } export const isPrimaryRenderer = true; diff --git a/packages/react-test-renderer/src/ReactTestRenderer.js b/packages/react-test-renderer/src/ReactTestRenderer.js index 669e1e7abd5f8..993e272230711 100644 --- a/packages/react-test-renderer/src/ReactTestRenderer.js +++ b/packages/react-test-renderer/src/ReactTestRenderer.js @@ -29,9 +29,11 @@ import { Profiler, } from 'shared/ReactTypeOfWork'; import invariant from 'shared/invariant'; +import ReactVersion from 'shared/ReactVersion'; import * as ReactTestHostConfig from './ReactTestHostConfig'; import * as TestRendererScheduling from './ReactTestRendererScheduling'; +import {findFiberByHostInstance} from './ReactTestRendererComponentTree'; type TestRendererOptions = { createNodeMock: (element: React$Element) => any, @@ -279,6 +281,10 @@ class ReactTestInstance { return this._currentFiber().memoizedProps; } + get treeBaseTime(): number { + return this._currentFiber().treeBaseTime || 0; + } + get parent(): ?ReactTestInstance { let parent = this._fiber.return; while (parent !== null) { @@ -510,4 +516,13 @@ const ReactTestRendererFiber = { unstable_setNowImplementation: TestRendererScheduling.setNowImplementation, }; +// Enable ReactTestRenderer to be used to test DevTools integration. +// TODO (bvaughn) Perhaps this injection should be hidden behind a feature flag? +TestRenderer.injectIntoDevTools({ + findFiberByHostInstance, + bundleType: __DEV__ ? 1 : 0, + version: ReactVersion, + rendererPackageName: 'react-test-renderer', +}); + export default ReactTestRendererFiber; diff --git a/packages/react-test-renderer/src/ReactTestRendererComponentTree.js b/packages/react-test-renderer/src/ReactTestRendererComponentTree.js new file mode 100644 index 0000000000000..35604686f3909 --- /dev/null +++ b/packages/react-test-renderer/src/ReactTestRendererComponentTree.js @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +const randomKey = Math.random() + .toString(36) + .slice(2); +const internalInstanceKey = '__reactInternalInstance$' + randomKey; + +export function findFiberByHostInstance(node) { + return node[internalInstanceKey]; +} + +export function precacheFiberNode(hostInst, node) { + node[internalInstanceKey] = hostInst; +} diff --git a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js new file mode 100644 index 0000000000000..8da55c43e414b --- /dev/null +++ b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @emails react-core + */ + +'use strict'; + +describe('ReactProfiler DevTools integrate', () => { + let React; + let ReactTestRenderer; + let AdvanceTime; + let advanceTimeBy; + let hook; + let mockNow; + + const mockNowForTests = () => { + let currentTime = 0; + + mockNow = jest.fn().mockImplementation(() => currentTime); + + ReactTestRenderer.unstable_setNowImplementation(mockNow); + advanceTimeBy = amount => { + currentTime += amount; + }; + }; + + beforeEach(() => { + global.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook = { + inject: () => {}, + onCommitFiberRoot: jest.fn((rendererId, root) => {}), + onCommitFiberUnmount: () => {}, + supportsFiber: true, + }; + + jest.resetModules(); + + React = require('react'); + ReactTestRenderer = require('react-test-renderer'); + + mockNowForTests(); + + AdvanceTime = class extends React.Component { + static defaultProps = { + byAmount: 10, + shouldComponentUpdate: true, + }; + shouldComponentUpdate(nextProps) { + return nextProps.shouldComponentUpdate; + } + render() { + // Simulate time passing when this component is rendered + advanceTimeBy(this.props.byAmount); + return this.props.children || null; + } + }; + }); + + it('should automatically profile all fibers if the DevTools hook is detected', () => { + const App = ({multiplier}) => { + advanceTimeBy(2); + return ( + + + + + ); + }; + + const onRender = jest.fn(() => {}); + const rendered = ReactTestRenderer.create(); + + expect(hook.onCommitFiberRoot).toHaveBeenCalledTimes(1); + + // Measure observable timing using the Profiler component. + // The time spent in App (above the Profiler) won't be included in the durations, + // But needs to be acocunted for in the offset times. + expect(onRender).toHaveBeenCalledTimes(1); + expect(onRender).toHaveBeenCalledWith('Profiler', 'mount', 10, 10, 2, 12); + onRender.mockClear(); + + // Measure unobservable timing required by the DevTools profiler. + // At this point, the base time should include both: + // The time 2ms in the App component itself, and + // The 10ms spend in the Profiler sub-tree beneath. + expect(rendered.root.findByType(App).treeBaseTime).toBe(12); + + rendered.update(); + + // Measure observable timing using the Profiler component. + // The time spent in App (above the Profiler) won't be included in the durations, + // But needs to be acocunted for in the offset times. + expect(onRender).toHaveBeenCalledTimes(1); + expect(onRender).toHaveBeenCalledWith('Profiler', 'update', 6, 13, 14, 20); + + // Measure unobservable timing required by the DevTools profiler. + // At this point, the base time should include both: + // The initial 9ms for the components that do not re-render, and + // The updated 6ms for the component that does. + expect(rendered.root.findByType(App).treeBaseTime).toBe(15); + }); +}); From 6a01fc177256ccccf5b6ed4fcff7752d8e60c8c6 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 15 Jun 2018 17:28:53 -0700 Subject: [PATCH 02/13] Fibers are always opted into ProfileMode if DevTools is present --- packages/react-reconciler/src/ReactFiber.js | 8 ++++++++ packages/react-reconciler/src/ReactFiberDevToolsHook.js | 3 +++ 2 files changed, 11 insertions(+) diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index 2b29ea79aae5b..de69a27c03451 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -35,6 +35,7 @@ import { } from 'shared/ReactTypeOfWork'; import getComponentName from 'shared/getComponentName'; +import {isDevToolsPresent} from './ReactFiberDevToolsHook'; import {NoWork} from './ReactFiberExpirationTime'; import {NoContext, AsyncMode, ProfileMode, StrictMode} from './ReactTypeOfMode'; import { @@ -400,6 +401,13 @@ export function createFiberFromElement( } } + if (enableProfilerTimer && isDevToolsPresent) { + // Always collect profile timings when DevTools are present. + // This enables DevTools to start capturing timing at any point– + // Without some nodes in the tree having empty base times. + mode |= ProfileMode; + } + fiber = createFiber(fiberTag, pendingProps, key, mode); fiber.type = type; fiber.expirationTime = expirationTime; diff --git a/packages/react-reconciler/src/ReactFiberDevToolsHook.js b/packages/react-reconciler/src/ReactFiberDevToolsHook.js index dd58854070103..4995978b11d60 100644 --- a/packages/react-reconciler/src/ReactFiberDevToolsHook.js +++ b/packages/react-reconciler/src/ReactFiberDevToolsHook.js @@ -31,6 +31,9 @@ function catchErrors(fn) { }; } +export const isDevToolsPresent = + typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined'; + export function injectInternals(internals: Object): boolean { if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') { // No DevTools From b2a6d5adeda5ede611bcb75bf02a4552639be0f1 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 15 Jun 2018 17:41:45 -0700 Subject: [PATCH 03/13] Added feature flag to control DevTools injection --- packages/react-dom/src/client/ReactDOM.js | 57 ++++++++++--------- .../react-native-renderer/src/ReactFabric.js | 18 +++--- .../src/ReactNativeRenderer.js | 18 +++--- .../src/ReactFiberReconciler.js | 4 ++ .../src/ReactTestHostConfig.js | 9 +-- .../src/ReactTestRenderer.js | 16 +++--- .../src/ReactTestRendererComponentTree.js | 19 ------- ...ofilerDevToolsIntegration-test.internal.js | 3 + packages/shared/ReactFeatureFlags.js | 3 + .../ReactFeatureFlags.native-fabric-fb.js | 1 + .../ReactFeatureFlags.native-fabric-oss.js | 1 + .../forks/ReactFeatureFlags.native-fb.js | 2 + .../forks/ReactFeatureFlags.native-oss.js | 2 + .../forks/ReactFeatureFlags.persistent.js | 1 + .../forks/ReactFeatureFlags.test-renderer.js | 1 + .../shared/forks/ReactFeatureFlags.www.js | 2 + 16 files changed, 83 insertions(+), 74 deletions(-) diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index 363617fc7e701..c3c484fbed1df 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -32,6 +32,7 @@ import ReactVersion from 'shared/ReactVersion'; import {ReactCurrentOwner} from 'shared/ReactGlobalSharedState'; import getComponentName from 'shared/getComponentName'; import invariant from 'shared/invariant'; +import {supportDevToolsIfPresent} from 'shared/ReactFeatureFlags'; import lowPriorityWarning from 'shared/lowPriorityWarning'; import warning from 'shared/warning'; @@ -760,34 +761,36 @@ ReactDOM.unstable_createRoot = function createRoot( return new ReactRoot(container, true, hydrate); }; -const foundDevTools = DOMRenderer.injectIntoDevTools({ - findFiberByHostInstance: ReactDOMComponentTree.getClosestInstanceFromNode, - bundleType: __DEV__ ? 1 : 0, - version: ReactVersion, - rendererPackageName: 'react-dom', -}); +if (supportDevToolsIfPresent) { + const foundDevTools = DOMRenderer.injectIntoDevTools({ + findFiberByHostInstance: ReactDOMComponentTree.getClosestInstanceFromNode, + bundleType: __DEV__ ? 1 : 0, + version: ReactVersion, + rendererPackageName: 'react-dom', + }); -if (__DEV__) { - if (!foundDevTools && canUseDOM && window.top === window.self) { - // If we're in Chrome or Firefox, provide a download link if not installed. - if ( - (navigator.userAgent.indexOf('Chrome') > -1 && - navigator.userAgent.indexOf('Edge') === -1) || - navigator.userAgent.indexOf('Firefox') > -1 - ) { - const protocol = window.location.protocol; - // Don't warn in exotic cases like chrome-extension://. - if (/^(https?|file):$/.test(protocol)) { - console.info( - '%cDownload the React DevTools ' + - 'for a better development experience: ' + - 'https://fb.me/react-devtools' + - (protocol === 'file:' - ? '\nYou might need to use a local HTTP server (instead of file://): ' + - 'https://fb.me/react-devtools-faq' - : ''), - 'font-weight:bold', - ); + if (__DEV__) { + if (!foundDevTools && canUseDOM && window.top === window.self) { + // If we're in Chrome or Firefox, provide a download link if not installed. + if ( + (navigator.userAgent.indexOf('Chrome') > -1 && + navigator.userAgent.indexOf('Edge') === -1) || + navigator.userAgent.indexOf('Firefox') > -1 + ) { + const protocol = window.location.protocol; + // Don't warn in exotic cases like chrome-extension://. + if (/^(https?|file):$/.test(protocol)) { + console.info( + '%cDownload the React DevTools ' + + 'for a better development experience: ' + + 'https://fb.me/react-devtools' + + (protocol === 'file:' + ? '\nYou might need to use a local HTTP server (instead of file://): ' + + 'https://fb.me/react-devtools-faq' + : ''), + 'font-weight:bold', + ); + } } } } diff --git a/packages/react-native-renderer/src/ReactFabric.js b/packages/react-native-renderer/src/ReactFabric.js index 63cc05480b532..7e449308f14c5 100644 --- a/packages/react-native-renderer/src/ReactFabric.js +++ b/packages/react-native-renderer/src/ReactFabric.js @@ -23,6 +23,7 @@ import ReactNativeComponent from './ReactNativeComponent'; import * as ReactFabricComponentTree from './ReactFabricComponentTree'; import {getInspectorDataForViewTag} from './ReactNativeFiberInspector'; +import {supportDevToolsIfPresent} from 'shared/ReactFeatureFlags'; import {ReactCurrentOwner} from 'shared/ReactGlobalSharedState'; import getComponentName from 'shared/getComponentName'; import warning from 'shared/warning'; @@ -119,12 +120,15 @@ const ReactFabric: ReactFabricType = { }, }; -ReactFabricRenderer.injectIntoDevTools({ - findFiberByHostInstance: ReactFabricComponentTree.getClosestInstanceFromNode, - getInspectorDataForViewTag: getInspectorDataForViewTag, - bundleType: __DEV__ ? 1 : 0, - version: ReactVersion, - rendererPackageName: 'react-native-renderer', -}); +if (supportDevToolsIfPresent) { + ReactFabricRenderer.injectIntoDevTools({ + findFiberByHostInstance: + ReactFabricComponentTree.getClosestInstanceFromNode, + getInspectorDataForViewTag: getInspectorDataForViewTag, + bundleType: __DEV__ ? 1 : 0, + version: ReactVersion, + rendererPackageName: 'react-native-renderer', + }); +} export default ReactFabric; diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 9ff1749c50b84..6cced1c2ff2ac 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -26,6 +26,7 @@ import ReactNativeComponent from './ReactNativeComponent'; import * as ReactNativeComponentTree from './ReactNativeComponentTree'; import {getInspectorDataForViewTag} from './ReactNativeFiberInspector'; +import {supportDevToolsIfPresent} from 'shared/ReactFeatureFlags'; import {ReactCurrentOwner} from 'shared/ReactGlobalSharedState'; import getComponentName from 'shared/getComponentName'; import warning from 'shared/warning'; @@ -142,12 +143,15 @@ const ReactNativeRenderer: ReactNativeType = { }, }; -ReactNativeFiberRenderer.injectIntoDevTools({ - findFiberByHostInstance: ReactNativeComponentTree.getClosestInstanceFromNode, - getInspectorDataForViewTag: getInspectorDataForViewTag, - bundleType: __DEV__ ? 1 : 0, - version: ReactVersion, - rendererPackageName: 'react-native-renderer', -}); +if (supportDevToolsIfPresent) { + ReactNativeFiberRenderer.injectIntoDevTools({ + findFiberByHostInstance: + ReactNativeComponentTree.getClosestInstanceFromNode, + getInspectorDataForViewTag: getInspectorDataForViewTag, + bundleType: __DEV__ ? 1 : 0, + version: ReactVersion, + rendererPackageName: 'react-native-renderer', + }); +} export default ReactNativeRenderer; diff --git a/packages/react-reconciler/src/ReactFiberReconciler.js b/packages/react-reconciler/src/ReactFiberReconciler.js index 3e1c36866fc87..38d2fca8fa44d 100644 --- a/packages/react-reconciler/src/ReactFiberReconciler.js +++ b/packages/react-reconciler/src/ReactFiberReconciler.js @@ -15,6 +15,7 @@ import type { Container, PublicInstance, } from './ReactFiberHostConfig'; +import {supportDevToolsIfPresent} from 'shared/ReactFeatureFlags'; import type {ReactNodeList} from 'shared/ReactTypes'; import type {ExpirationTime} from './ReactFiberExpirationTime'; @@ -261,6 +262,9 @@ export function findHostInstanceWithNoPortals( } export function injectIntoDevTools(devToolsConfig: DevToolsConfig): boolean { + if (!supportDevToolsIfPresent) { + return false; + } const {findFiberByHostInstance} = devToolsConfig; return ReactFiberDevToolsHook.injectInternals({ ...devToolsConfig, diff --git a/packages/react-test-renderer/src/ReactTestHostConfig.js b/packages/react-test-renderer/src/ReactTestHostConfig.js index 8215f2653f16b..1a1e74a1e27df 100644 --- a/packages/react-test-renderer/src/ReactTestHostConfig.js +++ b/packages/react-test-renderer/src/ReactTestHostConfig.js @@ -7,7 +7,6 @@ * @flow */ -import {precacheFiberNode} from './ReactTestRendererComponentTree'; import * as TestRendererScheduling from './ReactTestRendererScheduling'; export type Type = string; @@ -118,15 +117,13 @@ export function createInstance( hostContext: Object, internalInstanceHandle: Object, ): Instance { - const instance = { + return { type, props, children: [], rootContainerInstance, tag: 'INSTANCE', }; - precacheFiberNode(internalInstanceHandle, instance); - return instance; } export function appendInitialChild( @@ -175,12 +172,10 @@ export function createTextInstance( hostContext: Object, internalInstanceHandle: Object, ): TextInstance { - const textInstance = { + return { text, tag: 'TEXT', }; - precacheFiberNode(internalInstanceHandle, textInstance); - return textInstance; } export const isPrimaryRenderer = true; diff --git a/packages/react-test-renderer/src/ReactTestRenderer.js b/packages/react-test-renderer/src/ReactTestRenderer.js index 993e272230711..bdbd6cf81ff6e 100644 --- a/packages/react-test-renderer/src/ReactTestRenderer.js +++ b/packages/react-test-renderer/src/ReactTestRenderer.js @@ -29,6 +29,7 @@ import { Profiler, } from 'shared/ReactTypeOfWork'; import invariant from 'shared/invariant'; +import {supportDevToolsIfPresent} from 'shared/ReactFeatureFlags'; import ReactVersion from 'shared/ReactVersion'; import * as ReactTestHostConfig from './ReactTestHostConfig'; @@ -517,12 +518,13 @@ const ReactTestRendererFiber = { }; // Enable ReactTestRenderer to be used to test DevTools integration. -// TODO (bvaughn) Perhaps this injection should be hidden behind a feature flag? -TestRenderer.injectIntoDevTools({ - findFiberByHostInstance, - bundleType: __DEV__ ? 1 : 0, - version: ReactVersion, - rendererPackageName: 'react-test-renderer', -}); +if (supportDevToolsIfPresent) { + TestRenderer.injectIntoDevTools({ + findFiberByHostInstance, + bundleType: __DEV__ ? 1 : 0, + version: ReactVersion, + rendererPackageName: 'react-test-renderer', + }); +} export default ReactTestRendererFiber; diff --git a/packages/react-test-renderer/src/ReactTestRendererComponentTree.js b/packages/react-test-renderer/src/ReactTestRendererComponentTree.js index 35604686f3909..e69de29bb2d1d 100644 --- a/packages/react-test-renderer/src/ReactTestRendererComponentTree.js +++ b/packages/react-test-renderer/src/ReactTestRendererComponentTree.js @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2013-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -const randomKey = Math.random() - .toString(36) - .slice(2); -const internalInstanceKey = '__reactInternalInstance$' + randomKey; - -export function findFiberByHostInstance(node) { - return node[internalInstanceKey]; -} - -export function precacheFiberNode(hostInst, node) { - node[internalInstanceKey] = hostInst; -} diff --git a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js index 8da55c43e414b..d24934b4b16bc 100644 --- a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js +++ b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js @@ -11,6 +11,7 @@ describe('ReactProfiler DevTools integrate', () => { let React; + let ReactFeatureFlags; let ReactTestRenderer; let AdvanceTime; let advanceTimeBy; @@ -38,6 +39,8 @@ describe('ReactProfiler DevTools integrate', () => { jest.resetModules(); + ReactFeatureFlags = require('shared/ReactFeatureFlags'); + ReactFeatureFlags.supportDevToolsIfPresent = true; React = require('react'); ReactTestRenderer = require('react-test-renderer'); diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index b3d2b48500549..73849ae945143 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -39,6 +39,9 @@ export const warnAboutLegacyContextAPI = false; // Gather advanced timing metrics for Profiler subtrees. export const enableProfilerTimer = __PROFILE__; +// If the DevTools hook is present, inject into it. +export const supportDevToolsIfPresent = false; + // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js index bd557015195fb..7f31595054d8c 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js @@ -21,6 +21,7 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = __DEV__; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; export const enableProfilerTimer = __DEV__; +export const supportDevToolsIfPresent = true; // Only used in www builds. export function addUserTimingListener() { diff --git a/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js b/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js index ea6c7cf6d9ec1..d823ea272e821 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js @@ -21,6 +21,7 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; export const enableProfilerTimer = __PROFILE__; +export const supportDevToolsIfPresent = true; // Only used in www builds. export function addUserTimingListener() { diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index b0fdc77f3a51e..a368144c0d0e2 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -27,6 +27,8 @@ export const { export const enableUserTimingAPI = __DEV__; export const warnAboutLegacyContextAPI = __DEV__; +export const supportDevToolsIfPresent = true; + // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index 3c2b19bf1b580..ba3b3868f5d75 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -22,6 +22,8 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; export const enableProfilerTimer = __PROFILE__; +export const supportDevToolsIfPresent = true; + // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.persistent.js b/packages/shared/forks/ReactFeatureFlags.persistent.js index 88773cf900b3b..2be18c9a186e5 100644 --- a/packages/shared/forks/ReactFeatureFlags.persistent.js +++ b/packages/shared/forks/ReactFeatureFlags.persistent.js @@ -21,6 +21,7 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; export const enableProfilerTimer = false; +export const supportDevToolsIfPresent = false; // Only used in www builds. export function addUserTimingListener() { diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 1bc79a7b3f440..c7199525b096c 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -21,6 +21,7 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false; export const enableProfilerTimer = false; +export const supportDevToolsIfPresent = false; // Only used in www builds. export function addUserTimingListener() { diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index a50191a17607b..2e0fa777c5767 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -32,6 +32,8 @@ export const warnAboutLegacyContextAPI = __DEV__; // as long as there is more than a single listener. export let enableUserTimingAPI = __DEV__; +export const supportDevToolsIfPresent = true; + let refCount = 0; export function addUserTimingListener() { if (__DEV__) { From a12c0bbb001d41af379130a73b7e0d357cb15161 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 15 Jun 2018 17:46:00 -0700 Subject: [PATCH 04/13] Moved DevTools ProfileMode check to create-host function --- packages/react-reconciler/src/ReactFiber.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index de69a27c03451..7e5a9dd3d6194 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -346,7 +346,15 @@ export function createWorkInProgress( } export function createHostRootFiber(isAsync: boolean): Fiber { - const mode = isAsync ? AsyncMode | StrictMode : NoContext; + let mode = isAsync ? AsyncMode | StrictMode : NoContext; + + if (enableProfilerTimer && isDevToolsPresent) { + // Always collect profile timings when DevTools are present. + // This enables DevTools to start capturing timing at any point– + // Without some nodes in the tree having empty base times. + mode |= ProfileMode; + } + return createFiber(HostRoot, null, null, mode); } @@ -401,13 +409,6 @@ export function createFiberFromElement( } } - if (enableProfilerTimer && isDevToolsPresent) { - // Always collect profile timings when DevTools are present. - // This enables DevTools to start capturing timing at any point– - // Without some nodes in the tree having empty base times. - mode |= ProfileMode; - } - fiber = createFiber(fiberTag, pendingProps, key, mode); fiber.type = type; fiber.expirationTime = expirationTime; From 6e9ee844253effa34d9aa44f4d3c472e59ba89d3 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 15 Jun 2018 17:47:11 -0700 Subject: [PATCH 05/13] Renamed test description --- .../ReactProfilerDevToolsIntegration-test.internal.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js index d24934b4b16bc..51398104ae1d6 100644 --- a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js +++ b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js @@ -9,7 +9,7 @@ 'use strict'; -describe('ReactProfiler DevTools integrate', () => { +describe('ReactProfiler DevTools integration', () => { let React; let ReactFeatureFlags; let ReactTestRenderer; @@ -62,7 +62,7 @@ describe('ReactProfiler DevTools integrate', () => { }; }); - it('should automatically profile all fibers if the DevTools hook is detected', () => { + it('should auto-Profile all fibers if the DevTools hook is detected', () => { const App = ({multiplier}) => { advanceTimeBy(2); return ( From 6546e32625778930254eec09eb2a585e59241f1c Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 15 Jun 2018 17:54:45 -0700 Subject: [PATCH 06/13] Removed unsupported method --- packages/react-test-renderer/src/ReactTestRenderer.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/react-test-renderer/src/ReactTestRenderer.js b/packages/react-test-renderer/src/ReactTestRenderer.js index bdbd6cf81ff6e..274871fb8b695 100644 --- a/packages/react-test-renderer/src/ReactTestRenderer.js +++ b/packages/react-test-renderer/src/ReactTestRenderer.js @@ -34,7 +34,6 @@ import ReactVersion from 'shared/ReactVersion'; import * as ReactTestHostConfig from './ReactTestHostConfig'; import * as TestRendererScheduling from './ReactTestRendererScheduling'; -import {findFiberByHostInstance} from './ReactTestRendererComponentTree'; type TestRendererOptions = { createNodeMock: (element: React$Element) => any, @@ -520,7 +519,11 @@ const ReactTestRendererFiber = { // Enable ReactTestRenderer to be used to test DevTools integration. if (supportDevToolsIfPresent) { TestRenderer.injectIntoDevTools({ - findFiberByHostInstance, + findFiberByHostInstance: (() => { + throw new Error( + 'TestRenderer does not support findFiberByHostInstance()', + ); + }: any), bundleType: __DEV__ ? 1 : 0, version: ReactVersion, rendererPackageName: 'react-test-renderer', From 8bfbbe320e335536bf1e5a0944e45ead3019ba2a Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 15 Jun 2018 18:29:38 -0700 Subject: [PATCH 07/13] Added missing feature flag to test --- .../__tests__/ReactProfilerDevToolsIntegration-test.internal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js index 51398104ae1d6..5c9f9ffd89e99 100644 --- a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js +++ b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js @@ -40,6 +40,7 @@ describe('ReactProfiler DevTools integration', () => { jest.resetModules(); ReactFeatureFlags = require('shared/ReactFeatureFlags'); + ReactFeatureFlags.enableProfilerTimer = true; ReactFeatureFlags.supportDevToolsIfPresent = true; React = require('react'); ReactTestRenderer = require('react-test-renderer'); From 7a3750052137a8d3cd1a7be99034b2ce0f0429af Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sat, 16 Jun 2018 07:23:06 -0700 Subject: [PATCH 08/13] supportDevToolsIfPresent true for base feature flags file --- packages/shared/ReactFeatureFlags.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index 73849ae945143..8f6b61715b774 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -40,7 +40,7 @@ export const warnAboutLegacyContextAPI = false; export const enableProfilerTimer = __PROFILE__; // If the DevTools hook is present, inject into it. -export const supportDevToolsIfPresent = false; +export const supportDevToolsIfPresent = true; // Only used in www builds. export function addUserTimingListener() { From 3e22e597f916486c0523c4df4b0114635ac74324 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sat, 16 Jun 2018 07:24:12 -0700 Subject: [PATCH 09/13] Remove treeBaseTime getter from test renderer --- packages/react-test-renderer/src/ReactTestRenderer.js | 4 ---- .../ReactProfilerDevToolsIntegration-test.internal.js | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/react-test-renderer/src/ReactTestRenderer.js b/packages/react-test-renderer/src/ReactTestRenderer.js index 274871fb8b695..563a9610185f5 100644 --- a/packages/react-test-renderer/src/ReactTestRenderer.js +++ b/packages/react-test-renderer/src/ReactTestRenderer.js @@ -281,10 +281,6 @@ class ReactTestInstance { return this._currentFiber().memoizedProps; } - get treeBaseTime(): number { - return this._currentFiber().treeBaseTime || 0; - } - get parent(): ?ReactTestInstance { let parent = this._fiber.return; while (parent !== null) { diff --git a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js index 5c9f9ffd89e99..cc12881fda379 100644 --- a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js +++ b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js @@ -93,7 +93,7 @@ describe('ReactProfiler DevTools integration', () => { // At this point, the base time should include both: // The time 2ms in the App component itself, and // The 10ms spend in the Profiler sub-tree beneath. - expect(rendered.root.findByType(App).treeBaseTime).toBe(12); + expect(rendered.root.findByType(App)._currentFiber().treeBaseTime).toBe(12); rendered.update(); @@ -107,6 +107,6 @@ describe('ReactProfiler DevTools integration', () => { // At this point, the base time should include both: // The initial 9ms for the components that do not re-render, and // The updated 6ms for the component that does. - expect(rendered.root.findByType(App).treeBaseTime).toBe(15); + expect(rendered.root.findByType(App)._currentFiber().treeBaseTime).toBe(15); }); }); From 36151d175c0b0cbcc5de33f2de3636de7f867643 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Tue, 19 Jun 2018 10:21:30 -0700 Subject: [PATCH 10/13] supportDevToolsIfPresent = true for persistent config --- packages/shared/forks/ReactFeatureFlags.persistent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/forks/ReactFeatureFlags.persistent.js b/packages/shared/forks/ReactFeatureFlags.persistent.js index 2be18c9a186e5..d325d42b6b55a 100644 --- a/packages/shared/forks/ReactFeatureFlags.persistent.js +++ b/packages/shared/forks/ReactFeatureFlags.persistent.js @@ -21,7 +21,7 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; export const enableProfilerTimer = false; -export const supportDevToolsIfPresent = false; +export const supportDevToolsIfPresent = true; // Only used in www builds. export function addUserTimingListener() { From 4a68804bc50db8616038d23e9101797fa34b438e Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 20 Jun 2018 08:54:10 -0700 Subject: [PATCH 11/13] Removed supportDevToolsIfPresent feature flag --- packages/react-dom/src/client/ReactDOM.js | 57 +++++++++---------- .../react-native-renderer/src/ReactFabric.js | 18 +++--- .../src/ReactNativeRenderer.js | 18 +++--- .../src/ReactFiberReconciler.js | 4 -- .../src/ReactTestRenderer.js | 21 +++---- ...ofilerDevToolsIntegration-test.internal.js | 1 - packages/shared/ReactFeatureFlags.js | 3 - .../ReactFeatureFlags.native-fabric-fb.js | 1 - .../ReactFeatureFlags.native-fabric-oss.js | 1 - .../forks/ReactFeatureFlags.native-fb.js | 2 - .../forks/ReactFeatureFlags.native-oss.js | 2 - .../forks/ReactFeatureFlags.persistent.js | 1 - .../forks/ReactFeatureFlags.test-renderer.js | 1 - .../shared/forks/ReactFeatureFlags.www.js | 2 - 14 files changed, 49 insertions(+), 83 deletions(-) diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index c3c484fbed1df..363617fc7e701 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -32,7 +32,6 @@ import ReactVersion from 'shared/ReactVersion'; import {ReactCurrentOwner} from 'shared/ReactGlobalSharedState'; import getComponentName from 'shared/getComponentName'; import invariant from 'shared/invariant'; -import {supportDevToolsIfPresent} from 'shared/ReactFeatureFlags'; import lowPriorityWarning from 'shared/lowPriorityWarning'; import warning from 'shared/warning'; @@ -761,36 +760,34 @@ ReactDOM.unstable_createRoot = function createRoot( return new ReactRoot(container, true, hydrate); }; -if (supportDevToolsIfPresent) { - const foundDevTools = DOMRenderer.injectIntoDevTools({ - findFiberByHostInstance: ReactDOMComponentTree.getClosestInstanceFromNode, - bundleType: __DEV__ ? 1 : 0, - version: ReactVersion, - rendererPackageName: 'react-dom', - }); +const foundDevTools = DOMRenderer.injectIntoDevTools({ + findFiberByHostInstance: ReactDOMComponentTree.getClosestInstanceFromNode, + bundleType: __DEV__ ? 1 : 0, + version: ReactVersion, + rendererPackageName: 'react-dom', +}); - if (__DEV__) { - if (!foundDevTools && canUseDOM && window.top === window.self) { - // If we're in Chrome or Firefox, provide a download link if not installed. - if ( - (navigator.userAgent.indexOf('Chrome') > -1 && - navigator.userAgent.indexOf('Edge') === -1) || - navigator.userAgent.indexOf('Firefox') > -1 - ) { - const protocol = window.location.protocol; - // Don't warn in exotic cases like chrome-extension://. - if (/^(https?|file):$/.test(protocol)) { - console.info( - '%cDownload the React DevTools ' + - 'for a better development experience: ' + - 'https://fb.me/react-devtools' + - (protocol === 'file:' - ? '\nYou might need to use a local HTTP server (instead of file://): ' + - 'https://fb.me/react-devtools-faq' - : ''), - 'font-weight:bold', - ); - } +if (__DEV__) { + if (!foundDevTools && canUseDOM && window.top === window.self) { + // If we're in Chrome or Firefox, provide a download link if not installed. + if ( + (navigator.userAgent.indexOf('Chrome') > -1 && + navigator.userAgent.indexOf('Edge') === -1) || + navigator.userAgent.indexOf('Firefox') > -1 + ) { + const protocol = window.location.protocol; + // Don't warn in exotic cases like chrome-extension://. + if (/^(https?|file):$/.test(protocol)) { + console.info( + '%cDownload the React DevTools ' + + 'for a better development experience: ' + + 'https://fb.me/react-devtools' + + (protocol === 'file:' + ? '\nYou might need to use a local HTTP server (instead of file://): ' + + 'https://fb.me/react-devtools-faq' + : ''), + 'font-weight:bold', + ); } } } diff --git a/packages/react-native-renderer/src/ReactFabric.js b/packages/react-native-renderer/src/ReactFabric.js index 7e449308f14c5..63cc05480b532 100644 --- a/packages/react-native-renderer/src/ReactFabric.js +++ b/packages/react-native-renderer/src/ReactFabric.js @@ -23,7 +23,6 @@ import ReactNativeComponent from './ReactNativeComponent'; import * as ReactFabricComponentTree from './ReactFabricComponentTree'; import {getInspectorDataForViewTag} from './ReactNativeFiberInspector'; -import {supportDevToolsIfPresent} from 'shared/ReactFeatureFlags'; import {ReactCurrentOwner} from 'shared/ReactGlobalSharedState'; import getComponentName from 'shared/getComponentName'; import warning from 'shared/warning'; @@ -120,15 +119,12 @@ const ReactFabric: ReactFabricType = { }, }; -if (supportDevToolsIfPresent) { - ReactFabricRenderer.injectIntoDevTools({ - findFiberByHostInstance: - ReactFabricComponentTree.getClosestInstanceFromNode, - getInspectorDataForViewTag: getInspectorDataForViewTag, - bundleType: __DEV__ ? 1 : 0, - version: ReactVersion, - rendererPackageName: 'react-native-renderer', - }); -} +ReactFabricRenderer.injectIntoDevTools({ + findFiberByHostInstance: ReactFabricComponentTree.getClosestInstanceFromNode, + getInspectorDataForViewTag: getInspectorDataForViewTag, + bundleType: __DEV__ ? 1 : 0, + version: ReactVersion, + rendererPackageName: 'react-native-renderer', +}); export default ReactFabric; diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 6cced1c2ff2ac..9ff1749c50b84 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -26,7 +26,6 @@ import ReactNativeComponent from './ReactNativeComponent'; import * as ReactNativeComponentTree from './ReactNativeComponentTree'; import {getInspectorDataForViewTag} from './ReactNativeFiberInspector'; -import {supportDevToolsIfPresent} from 'shared/ReactFeatureFlags'; import {ReactCurrentOwner} from 'shared/ReactGlobalSharedState'; import getComponentName from 'shared/getComponentName'; import warning from 'shared/warning'; @@ -143,15 +142,12 @@ const ReactNativeRenderer: ReactNativeType = { }, }; -if (supportDevToolsIfPresent) { - ReactNativeFiberRenderer.injectIntoDevTools({ - findFiberByHostInstance: - ReactNativeComponentTree.getClosestInstanceFromNode, - getInspectorDataForViewTag: getInspectorDataForViewTag, - bundleType: __DEV__ ? 1 : 0, - version: ReactVersion, - rendererPackageName: 'react-native-renderer', - }); -} +ReactNativeFiberRenderer.injectIntoDevTools({ + findFiberByHostInstance: ReactNativeComponentTree.getClosestInstanceFromNode, + getInspectorDataForViewTag: getInspectorDataForViewTag, + bundleType: __DEV__ ? 1 : 0, + version: ReactVersion, + rendererPackageName: 'react-native-renderer', +}); export default ReactNativeRenderer; diff --git a/packages/react-reconciler/src/ReactFiberReconciler.js b/packages/react-reconciler/src/ReactFiberReconciler.js index 38d2fca8fa44d..3e1c36866fc87 100644 --- a/packages/react-reconciler/src/ReactFiberReconciler.js +++ b/packages/react-reconciler/src/ReactFiberReconciler.js @@ -15,7 +15,6 @@ import type { Container, PublicInstance, } from './ReactFiberHostConfig'; -import {supportDevToolsIfPresent} from 'shared/ReactFeatureFlags'; import type {ReactNodeList} from 'shared/ReactTypes'; import type {ExpirationTime} from './ReactFiberExpirationTime'; @@ -262,9 +261,6 @@ export function findHostInstanceWithNoPortals( } export function injectIntoDevTools(devToolsConfig: DevToolsConfig): boolean { - if (!supportDevToolsIfPresent) { - return false; - } const {findFiberByHostInstance} = devToolsConfig; return ReactFiberDevToolsHook.injectInternals({ ...devToolsConfig, diff --git a/packages/react-test-renderer/src/ReactTestRenderer.js b/packages/react-test-renderer/src/ReactTestRenderer.js index 563a9610185f5..ed4c59fb38534 100644 --- a/packages/react-test-renderer/src/ReactTestRenderer.js +++ b/packages/react-test-renderer/src/ReactTestRenderer.js @@ -29,7 +29,6 @@ import { Profiler, } from 'shared/ReactTypeOfWork'; import invariant from 'shared/invariant'; -import {supportDevToolsIfPresent} from 'shared/ReactFeatureFlags'; import ReactVersion from 'shared/ReactVersion'; import * as ReactTestHostConfig from './ReactTestHostConfig'; @@ -513,17 +512,13 @@ const ReactTestRendererFiber = { }; // Enable ReactTestRenderer to be used to test DevTools integration. -if (supportDevToolsIfPresent) { - TestRenderer.injectIntoDevTools({ - findFiberByHostInstance: (() => { - throw new Error( - 'TestRenderer does not support findFiberByHostInstance()', - ); - }: any), - bundleType: __DEV__ ? 1 : 0, - version: ReactVersion, - rendererPackageName: 'react-test-renderer', - }); -} +TestRenderer.injectIntoDevTools({ + findFiberByHostInstance: (() => { + throw new Error('TestRenderer does not support findFiberByHostInstance()'); + }: any), + bundleType: __DEV__ ? 1 : 0, + version: ReactVersion, + rendererPackageName: 'react-test-renderer', +}); export default ReactTestRendererFiber; diff --git a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js index cc12881fda379..4c209b6d92f52 100644 --- a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js +++ b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js @@ -41,7 +41,6 @@ describe('ReactProfiler DevTools integration', () => { ReactFeatureFlags = require('shared/ReactFeatureFlags'); ReactFeatureFlags.enableProfilerTimer = true; - ReactFeatureFlags.supportDevToolsIfPresent = true; React = require('react'); ReactTestRenderer = require('react-test-renderer'); diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index 8f6b61715b774..b3d2b48500549 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -39,9 +39,6 @@ export const warnAboutLegacyContextAPI = false; // Gather advanced timing metrics for Profiler subtrees. export const enableProfilerTimer = __PROFILE__; -// If the DevTools hook is present, inject into it. -export const supportDevToolsIfPresent = true; - // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js index 7f31595054d8c..bd557015195fb 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fabric-fb.js @@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = __DEV__; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; export const enableProfilerTimer = __DEV__; -export const supportDevToolsIfPresent = true; // Only used in www builds. export function addUserTimingListener() { diff --git a/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js b/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js index d823ea272e821..ea6c7cf6d9ec1 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js @@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; export const enableProfilerTimer = __PROFILE__; -export const supportDevToolsIfPresent = true; // Only used in www builds. export function addUserTimingListener() { diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index a368144c0d0e2..b0fdc77f3a51e 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -27,8 +27,6 @@ export const { export const enableUserTimingAPI = __DEV__; export const warnAboutLegacyContextAPI = __DEV__; -export const supportDevToolsIfPresent = true; - // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index ba3b3868f5d75..3c2b19bf1b580 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -22,8 +22,6 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; export const enableProfilerTimer = __PROFILE__; -export const supportDevToolsIfPresent = true; - // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.persistent.js b/packages/shared/forks/ReactFeatureFlags.persistent.js index d325d42b6b55a..88773cf900b3b 100644 --- a/packages/shared/forks/ReactFeatureFlags.persistent.js +++ b/packages/shared/forks/ReactFeatureFlags.persistent.js @@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; export const enableProfilerTimer = false; -export const supportDevToolsIfPresent = true; // Only used in www builds. export function addUserTimingListener() { diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index c7199525b096c..1bc79a7b3f440 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -21,7 +21,6 @@ export const warnAboutDeprecatedLifecycles = false; export const warnAboutLegacyContextAPI = false; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false; export const enableProfilerTimer = false; -export const supportDevToolsIfPresent = false; // Only used in www builds. export function addUserTimingListener() { diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index 2e0fa777c5767..a50191a17607b 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -32,8 +32,6 @@ export const warnAboutLegacyContextAPI = __DEV__; // as long as there is more than a single listener. export let enableUserTimingAPI = __DEV__; -export const supportDevToolsIfPresent = true; - let refCount = 0; export function addUserTimingListener() { if (__DEV__) { From 2776f6fc879cdb118b1bee13bc4a43017d11ed09 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 20 Jun 2018 08:57:22 -0700 Subject: [PATCH 12/13] Removed unused ReactTestRendererComponentTree --- .../react-test-renderer/src/ReactTestRendererComponentTree.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 packages/react-test-renderer/src/ReactTestRendererComponentTree.js diff --git a/packages/react-test-renderer/src/ReactTestRendererComponentTree.js b/packages/react-test-renderer/src/ReactTestRendererComponentTree.js deleted file mode 100644 index e69de29bb2d1d..0000000000000 From 854ef7efd192ee590ae1253576b406b67482bba6 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 20 Jun 2018 09:08:25 -0700 Subject: [PATCH 13/13] Fixed typo --- .../ReactProfilerDevToolsIntegration-test.internal.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js index 4c209b6d92f52..6fc396405e78f 100644 --- a/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js +++ b/packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js @@ -83,7 +83,7 @@ describe('ReactProfiler DevTools integration', () => { // Measure observable timing using the Profiler component. // The time spent in App (above the Profiler) won't be included in the durations, - // But needs to be acocunted for in the offset times. + // But needs to be accounted for in the offset times. expect(onRender).toHaveBeenCalledTimes(1); expect(onRender).toHaveBeenCalledWith('Profiler', 'mount', 10, 10, 2, 12); onRender.mockClear(); @@ -98,7 +98,7 @@ describe('ReactProfiler DevTools integration', () => { // Measure observable timing using the Profiler component. // The time spent in App (above the Profiler) won't be included in the durations, - // But needs to be acocunted for in the offset times. + // But needs to be accounted for in the offset times. expect(onRender).toHaveBeenCalledTimes(1); expect(onRender).toHaveBeenCalledWith('Profiler', 'update', 6, 13, 14, 20);