Skip to content

Commit e0a89a1

Browse files
hoxyqkassens
authored andcommitted
cleanup[devtools]: remove named hooks & profiler changed hook indices feature flags (#26635)
## Summary Removing `enableNamedHooksFeature`, `enableProfilerChangedHookIndices`, `enableProfilerComponentTree` feature flags, they are the same for all configurations.
1 parent 46d549c commit e0a89a1

File tree

10 files changed

+44
-114
lines changed

10 files changed

+44
-114
lines changed

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ import {
9292
SERVER_CONTEXT_SYMBOL_STRING,
9393
} from './ReactSymbols';
9494
import {format} from './utils';
95-
import {
96-
enableProfilerChangedHookIndices,
97-
enableStyleXFeatures,
98-
} from 'react-devtools-feature-flags';
95+
import {enableStyleXFeatures} from 'react-devtools-feature-flags';
9996
import is from 'shared/objectIs';
10097
import hasOwnProperty from 'shared/hasOwnProperty';
10198
import {getStyleXData} from './StyleX/utils';
@@ -1265,19 +1262,12 @@ export function attach(
12651262
};
12661263

12671264
// Only traverse the hooks list once, depending on what info we're returning.
1268-
if (enableProfilerChangedHookIndices) {
1269-
const indices = getChangedHooksIndices(
1270-
prevFiber.memoizedState,
1271-
nextFiber.memoizedState,
1272-
);
1273-
data.hooks = indices;
1274-
data.didHooksChange = indices !== null && indices.length > 0;
1275-
} else {
1276-
data.didHooksChange = didHooksChange(
1277-
prevFiber.memoizedState,
1278-
nextFiber.memoizedState,
1279-
);
1280-
}
1265+
const indices = getChangedHooksIndices(
1266+
prevFiber.memoizedState,
1267+
nextFiber.memoizedState,
1268+
);
1269+
data.hooks = indices;
1270+
data.didHooksChange = indices !== null && indices.length > 0;
12811271

12821272
return data;
12831273
}
@@ -1458,12 +1448,13 @@ export function attach(
14581448
return false;
14591449
}
14601450

1461-
function didHooksChange(prev: any, next: any): boolean {
1451+
function getChangedHooksIndices(prev: any, next: any): null | Array<number> {
14621452
if (prev == null || next == null) {
1463-
return false;
1453+
return null;
14641454
}
14651455

1466-
// We can't report anything meaningful for hooks changes.
1456+
const indices = [];
1457+
let index = 0;
14671458
if (
14681459
next.hasOwnProperty('baseState') &&
14691460
next.hasOwnProperty('memoizedState') &&
@@ -1472,45 +1463,15 @@ export function attach(
14721463
) {
14731464
while (next !== null) {
14741465
if (didStatefulHookChange(prev, next)) {
1475-
return true;
1476-
} else {
1477-
next = next.next;
1478-
prev = prev.next;
1466+
indices.push(index);
14791467
}
1468+
next = next.next;
1469+
prev = prev.next;
1470+
index++;
14801471
}
14811472
}
14821473

1483-
return false;
1484-
}
1485-
1486-
function getChangedHooksIndices(prev: any, next: any): null | Array<number> {
1487-
if (enableProfilerChangedHookIndices) {
1488-
if (prev == null || next == null) {
1489-
return null;
1490-
}
1491-
1492-
const indices = [];
1493-
let index = 0;
1494-
if (
1495-
next.hasOwnProperty('baseState') &&
1496-
next.hasOwnProperty('memoizedState') &&
1497-
next.hasOwnProperty('next') &&
1498-
next.hasOwnProperty('queue')
1499-
) {
1500-
while (next !== null) {
1501-
if (didStatefulHookChange(prev, next)) {
1502-
indices.push(index);
1503-
}
1504-
next = next.next;
1505-
prev = prev.next;
1506-
index++;
1507-
}
1508-
}
1509-
1510-
return indices;
1511-
}
1512-
1513-
return null;
1474+
return indices;
15141475
}
15151476

15161477
function getChangedKeys(prev: any, next: any): null | Array<string> {

packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-fb.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515

1616
export const consoleManagedByDevToolsDuringStrictMode = false;
1717
export const enableLogger = true;
18-
export const enableNamedHooksFeature = true;
19-
export const enableProfilerChangedHookIndices = true;
2018
export const enableStyleXFeatures = true;
2119
export const isInternalFacebookBuild = true;
22-
export const enableProfilerComponentTree = true;
2320

2421
/************************************************************************
2522
* Do not edit the code below.

packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-oss.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515

1616
export const consoleManagedByDevToolsDuringStrictMode = false;
1717
export const enableLogger = false;
18-
export const enableNamedHooksFeature = true;
19-
export const enableProfilerChangedHookIndices = true;
2018
export const enableStyleXFeatures = false;
2119
export const isInternalFacebookBuild = false;
22-
export const enableProfilerComponentTree = true;
2320

2421
/************************************************************************
2522
* Do not edit the code below.

packages/react-devtools-shared/src/config/DevToolsFeatureFlags.default.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,5 @@
1515

1616
export const consoleManagedByDevToolsDuringStrictMode = true;
1717
export const enableLogger = false;
18-
export const enableNamedHooksFeature = true;
19-
export const enableProfilerChangedHookIndices = true;
2018
export const enableStyleXFeatures = false;
2119
export const isInternalFacebookBuild = false;
22-
export const enableProfilerComponentTree = true;

packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-fb.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515

1616
export const consoleManagedByDevToolsDuringStrictMode = true;
1717
export const enableLogger = true;
18-
export const enableNamedHooksFeature = true;
19-
export const enableProfilerChangedHookIndices = true;
2018
export const enableStyleXFeatures = true;
2119
export const isInternalFacebookBuild = true;
22-
export const enableProfilerComponentTree = true;
2320

2421
/************************************************************************
2522
* Do not edit the code below.

packages/react-devtools-shared/src/config/DevToolsFeatureFlags.extension-oss.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515

1616
export const consoleManagedByDevToolsDuringStrictMode = true;
1717
export const enableLogger = false;
18-
export const enableNamedHooksFeature = true;
19-
export const enableProfilerChangedHookIndices = true;
2018
export const enableStyleXFeatures = false;
2119
export const isInternalFacebookBuild = false;
22-
export const enableProfilerComponentTree = true;
2320

2421
/************************************************************************
2522
* Do not edit the code below.

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementContext.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {loadModule} from 'react-devtools-shared/src/dynamicImportCache';
3636
import FetchFileWithCachingContext from 'react-devtools-shared/src/devtools/views/Components/FetchFileWithCachingContext';
3737
import HookNamesModuleLoaderContext from 'react-devtools-shared/src/devtools/views/Components/HookNamesModuleLoaderContext';
3838
import {SettingsContext} from '../Settings/SettingsContext';
39-
import {enableNamedHooksFeature} from 'react-devtools-feature-flags';
4039

4140
import type {HookNames} from 'react-devtools-shared/src/types';
4241
import type {ReactNodeList} from 'shared/ReactTypes';
@@ -128,28 +127,26 @@ export function InspectedElementContextController({
128127
if (!elementHasChanged && element !== null) {
129128
inspectedElement = inspectElement(element, state.path, store, bridge);
130129

131-
if (enableNamedHooksFeature) {
132-
if (typeof hookNamesModuleLoader === 'function') {
133-
if (parseHookNames || alreadyLoadedHookNames) {
134-
const hookNamesModule = loadModule(hookNamesModuleLoader);
135-
if (hookNamesModule !== null) {
136-
const {parseHookNames: loadHookNamesFunction, purgeCachedMetadata} =
137-
hookNamesModule;
130+
if (typeof hookNamesModuleLoader === 'function') {
131+
if (parseHookNames || alreadyLoadedHookNames) {
132+
const hookNamesModule = loadModule(hookNamesModuleLoader);
133+
if (hookNamesModule !== null) {
134+
const {parseHookNames: loadHookNamesFunction, purgeCachedMetadata} =
135+
hookNamesModule;
138136

139-
purgeCachedMetadataRef.current = purgeCachedMetadata;
137+
purgeCachedMetadataRef.current = purgeCachedMetadata;
140138

141-
if (
142-
inspectedElement !== null &&
143-
inspectedElement.hooks !== null &&
144-
loadHookNamesFunction !== null
145-
) {
146-
hookNames = loadHookNames(
147-
element,
148-
inspectedElement.hooks,
149-
loadHookNamesFunction,
150-
fetchFileWithCaching,
151-
);
152-
}
139+
if (
140+
inspectedElement !== null &&
141+
inspectedElement.hooks !== null &&
142+
loadHookNamesFunction !== null
143+
) {
144+
hookNames = loadHookNames(
145+
element,
146+
inspectedElement.hooks,
147+
loadHookNamesFunction,
148+
fetchFileWithCaching,
149+
);
153150
}
154151
}
155152
}

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementHooksTree.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ import styles from './InspectedElementHooksTree.css';
2222
import useContextMenu from '../../ContextMenu/useContextMenu';
2323
import {meta} from '../../../hydration';
2424
import {getHookSourceLocationKey} from 'react-devtools-shared/src/hookNamesCache';
25-
import {
26-
enableNamedHooksFeature,
27-
enableProfilerChangedHookIndices,
28-
} from 'react-devtools-feature-flags';
2925
import HookNamesModuleLoaderContext from 'react-devtools-shared/src/devtools/views/Components/HookNamesModuleLoaderContext';
3026
import isArray from 'react-devtools-shared/src/isArray';
3127

@@ -90,8 +86,7 @@ export function InspectedElementHooksTree({
9086
data-testname="InspectedElementHooksTree">
9187
<div className={styles.HeaderRow}>
9288
<div className={styles.Header}>hooks</div>
93-
{enableNamedHooksFeature &&
94-
typeof hookNamesModuleLoader === 'function' &&
89+
{typeof hookNamesModuleLoader === 'function' &&
9590
(!parseHookNames || hookParsingFailed) && (
9691
<Toggle
9792
className={hookParsingFailed ? styles.ToggleError : null}
@@ -225,15 +220,13 @@ function HookView({
225220
const isCustomHook = subHooks.length > 0;
226221

227222
let name = hook.name;
228-
if (enableProfilerChangedHookIndices) {
229-
if (hookID !== null) {
230-
name = (
231-
<>
232-
<span className={styles.PrimitiveHookNumber}>{hookID + 1}</span>
233-
{name}
234-
</>
235-
);
236-
}
223+
if (hookID !== null) {
224+
name = (
225+
<>
226+
<span className={styles.PrimitiveHookNumber}>{hookID + 1}</span>
227+
{name}
228+
</>
229+
);
237230
}
238231

239232
const type = typeof value;

packages/react-devtools-shared/src/devtools/views/Profiler/Profiler.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {SettingsModalContextController} from 'react-devtools-shared/src/devtools
3434
import portaledContent from '../portaledContent';
3535
import {StoreContext} from '../context';
3636
import {TimelineContext} from 'react-devtools-timeline/src/TimelineContext';
37-
import {enableProfilerComponentTree} from 'react-devtools-feature-flags';
3837

3938
import styles from './Profiler.css';
4039

@@ -56,8 +55,6 @@ function Profiler(_: {}) {
5655
const {supportsTimeline} = useContext(StoreContext);
5756

5857
const isLegacyProfilerSelected = selectedTabID !== 'timeline';
59-
const isRightColumnVisible =
60-
isLegacyProfilerSelected || enableProfilerComponentTree;
6158

6259
let view = null;
6360
if (didRecordCommits || selectedTabID === 'timeline') {
@@ -151,9 +148,7 @@ function Profiler(_: {}) {
151148
<ModalDialog />
152149
</div>
153150
</div>
154-
{isRightColumnVisible && (
155-
<div className={styles.RightColumn}>{sidebar}</div>
156-
)}
151+
<div className={styles.RightColumn}>{sidebar}</div>
157152
<SettingsModal />
158153
</div>
159154
</SettingsModalContextController>

packages/react-devtools-shared/src/devtools/views/Profiler/WhatChanged.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import * as React from 'react';
1111
import {useContext} from 'react';
12-
import {enableProfilerChangedHookIndices} from 'react-devtools-feature-flags';
1312
import {ProfilerContext} from '../Profiler/ProfilerContext';
1413
import {StoreContext} from '../context';
1514

@@ -103,7 +102,7 @@ export default function WhatChanged({fiberID}: Props): React.Node {
103102
}
104103

105104
if (didHooksChange) {
106-
if (enableProfilerChangedHookIndices && Array.isArray(hooks)) {
105+
if (Array.isArray(hooks)) {
107106
changes.push(
108107
<div key="hooks" className={styles.Item}>
109108
{hookIndicesToString(hooks)}

0 commit comments

Comments
 (0)