Enable scheduling profiler flag in react-dom/testing builds (#23142)
Brian Vaughn committed
Jan 19, 2022 at 11:20 UTC
d5048247804ad3e6bb8e59dd311a4470affd7811
5 files changed
+33
-23
packages/react-devtools-shared/src/backend/profilingHooks.js
+5
-3
@@ -75,7 +75,7 @@ export function createProfilingHooks({
75
reactVersion,
76
}: {|
77
getDisplayNameForFiber: (fiber: Fiber) => string | null,
78
- getLaneLabelMap?: () => Map<Lane, string>,
78
+ getLaneLabelMap?: () => Map<Lane, string> | null,
79
reactVersion: string,
80
|}): DevToolsProfilingHooks {
81
function markMetadata() {
@@ -108,8 +108,10 @@ export function createProfilingHooks({
108
109
if (typeof getLaneLabelMap === 'function') {
110
const map = getLaneLabelMap();
111
- const labels = Array.from(map.values()).join(',');
112
- markAndClear(`--react-lane-labels-${labels}`);
111
+ if (map != null) {
112
+ const labels = Array.from(map.values()).join(',');
113
+ markAndClear(`--react-lane-labels-${labels}`);
114
+ }
115
}
116
}
117
packages/react-devtools-shared/src/backend/types.js
+1
-1
@@ -152,7 +152,7 @@ export type ReactRenderer = {
152
scheduleRefresh?: Function,
153
// 18.0+
154
injectProfilingHooks?: (profilingHooks: DevToolsProfilingHooks) => void,
155
- getLaneLabelMap?: () => Map<Lane, string>,
155
+ getLaneLabelMap?: () => Map<Lane, string> | null,
156
...
157
};
158
packages/react-reconciler/src/ReactFiberDevToolsHook.new.js
+13
-9
@@ -230,17 +230,21 @@ function injectProfilingHooks(profilingHooks: DevToolsProfilingHooks): void {
230
injectedProfilingHooks = profilingHooks;
231
}
232
233
-function getLaneLabelMap(): Map<Lane, string> {
234
- const map: Map<Lane, string> = new Map();
233
+function getLaneLabelMap(): Map<Lane, string> | null {
234
+ if (enableSchedulingProfiler) {
235
+ const map: Map<Lane, string> = new Map();
236
236
- let lane = 1;
237
- for (let index = 0; index < TotalLanes; index++) {
238
- const label = ((getLabelForLane(lane): any): string);
239
- map.set(lane, label);
240
- lane *= 2;
241
- }
237
+ let lane = 1;
238
+ for (let index = 0; index < TotalLanes; index++) {
239
+ const label = ((getLabelForLane(lane): any): string);
240
+ map.set(lane, label);
241
+ lane *= 2;
242
+ }
243
243
- return map;
244
+ return map;
245
+ } else {
246
+ return null;
247
+ }
248
}
249
250
export function markCommitStarted(lanes: Lanes): void {
packages/react-reconciler/src/ReactFiberDevToolsHook.old.js
+13
-9
@@ -230,17 +230,21 @@ function injectProfilingHooks(profilingHooks: DevToolsProfilingHooks): void {
230
injectedProfilingHooks = profilingHooks;
231
}
232
233
-function getLaneLabelMap(): Map<Lane, string> {
234
- const map: Map<Lane, string> = new Map();
233
+function getLaneLabelMap(): Map<Lane, string> | null {
234
+ if (enableSchedulingProfiler) {
235
+ const map: Map<Lane, string> = new Map();
236
236
- let lane = 1;
237
- for (let index = 0; index < TotalLanes; index++) {
238
- const label = ((getLabelForLane(lane): any): string);
239
- map.set(lane, label);
240
- lane *= 2;
241
- }
237
+ let lane = 1;
238
+ for (let index = 0; index < TotalLanes; index++) {
239
+ const label = ((getLabelForLane(lane): any): string);
240
+ map.set(lane, label);
241
+ lane *= 2;
242
+ }
243
243
- return map;
244
+ return map;
245
+ } else {
246
+ return null;
247
+ }
248
}
249
250
export function markCommitStarted(lanes: Lanes): void {
packages/shared/forks/ReactFeatureFlags.testing.js
+1
-1
@@ -12,7 +12,7 @@ import typeof * as ExportsType from './ReactFeatureFlags.testing';
12
13
export const debugRenderPhaseSideEffectsForStrictMode = false;
14
export const enableDebugTracing = false;
15
-export const enableSchedulingProfiler = false;
15
+export const enableSchedulingProfiler = __PROFILE__;
16
export const warnAboutDeprecatedLifecycles = true;
17
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
18
export const enableProfilerTimer = __PROFILE__;