diff --git a/packages/react-devtools-shared/src/backend/profilingHooks.js b/packages/react-devtools-shared/src/backend/profilingHooks.js index 9544b72511f6a..2280d6156e683 100644 --- a/packages/react-devtools-shared/src/backend/profilingHooks.js +++ b/packages/react-devtools-shared/src/backend/profilingHooks.js @@ -75,7 +75,7 @@ export function createProfilingHooks({ reactVersion, }: {| getDisplayNameForFiber: (fiber: Fiber) => string | null, - getLaneLabelMap?: () => Map, + getLaneLabelMap?: () => Map | null, reactVersion: string, |}): DevToolsProfilingHooks { function markMetadata() { @@ -108,8 +108,10 @@ export function createProfilingHooks({ if (typeof getLaneLabelMap === 'function') { const map = getLaneLabelMap(); - const labels = Array.from(map.values()).join(','); - markAndClear(`--react-lane-labels-${labels}`); + if (map != null) { + const labels = Array.from(map.values()).join(','); + markAndClear(`--react-lane-labels-${labels}`); + } } } diff --git a/packages/react-devtools-shared/src/backend/types.js b/packages/react-devtools-shared/src/backend/types.js index b751882396955..99a86464236f2 100644 --- a/packages/react-devtools-shared/src/backend/types.js +++ b/packages/react-devtools-shared/src/backend/types.js @@ -152,7 +152,7 @@ export type ReactRenderer = { scheduleRefresh?: Function, // 18.0+ injectProfilingHooks?: (profilingHooks: DevToolsProfilingHooks) => void, - getLaneLabelMap?: () => Map, + getLaneLabelMap?: () => Map | null, ... }; diff --git a/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js b/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js index 2978f7b3279b5..a05cc6933e53d 100644 --- a/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js +++ b/packages/react-reconciler/src/ReactFiberDevToolsHook.new.js @@ -230,17 +230,21 @@ function injectProfilingHooks(profilingHooks: DevToolsProfilingHooks): void { injectedProfilingHooks = profilingHooks; } -function getLaneLabelMap(): Map { - const map: Map = new Map(); +function getLaneLabelMap(): Map | null { + if (enableSchedulingProfiler) { + const map: Map = new Map(); - let lane = 1; - for (let index = 0; index < TotalLanes; index++) { - const label = ((getLabelForLane(lane): any): string); - map.set(lane, label); - lane *= 2; - } + let lane = 1; + for (let index = 0; index < TotalLanes; index++) { + const label = ((getLabelForLane(lane): any): string); + map.set(lane, label); + lane *= 2; + } - return map; + return map; + } else { + return null; + } } export function markCommitStarted(lanes: Lanes): void { diff --git a/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js b/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js index d26d12236c24c..982c46ba44f36 100644 --- a/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js +++ b/packages/react-reconciler/src/ReactFiberDevToolsHook.old.js @@ -230,17 +230,21 @@ function injectProfilingHooks(profilingHooks: DevToolsProfilingHooks): void { injectedProfilingHooks = profilingHooks; } -function getLaneLabelMap(): Map { - const map: Map = new Map(); +function getLaneLabelMap(): Map | null { + if (enableSchedulingProfiler) { + const map: Map = new Map(); - let lane = 1; - for (let index = 0; index < TotalLanes; index++) { - const label = ((getLabelForLane(lane): any): string); - map.set(lane, label); - lane *= 2; - } + let lane = 1; + for (let index = 0; index < TotalLanes; index++) { + const label = ((getLabelForLane(lane): any): string); + map.set(lane, label); + lane *= 2; + } - return map; + return map; + } else { + return null; + } } export function markCommitStarted(lanes: Lanes): void { diff --git a/packages/shared/forks/ReactFeatureFlags.testing.js b/packages/shared/forks/ReactFeatureFlags.testing.js index 163731c01dd29..1d2ff85dd3899 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.js @@ -12,7 +12,7 @@ import typeof * as ExportsType from './ReactFeatureFlags.testing'; export const debugRenderPhaseSideEffectsForStrictMode = false; export const enableDebugTracing = false; -export const enableSchedulingProfiler = false; +export const enableSchedulingProfiler = __PROFILE__; export const warnAboutDeprecatedLifecycles = true; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false; export const enableProfilerTimer = __PROFILE__;