Skip to content

Commit 79dcc47

Browse files
authored
chore[DevTools/TraceUpdates]: display names by default (facebook#32019)
Feature was added in facebook#31577, lets enable it by default. Note: for gradual rollout with React Native, we will continue to emit different event, requires some changes on React Native side to support this. I have plans to make this feature to be accessible via browser context menu, which has really limited API. In order to minimize potential divergence, lets make this the default state for the feature.
1 parent d16fe4b commit 79dcc47

File tree

6 files changed

+2
-59
lines changed

6 files changed

+2
-59
lines changed

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ export default class Agent extends EventEmitter<{
148148
getIfHasUnsupportedRendererVersion: [],
149149
updateHookSettings: [$ReadOnly<DevToolsHookSettings>],
150150
getHookSettings: [],
151-
showNamesWhenTracing: [boolean],
152151
}> {
153152
_bridge: BackendBridge;
154153
_isProfiling: boolean = false;
@@ -159,7 +158,6 @@ export default class Agent extends EventEmitter<{
159158
_onReloadAndProfile:
160159
| ((recordChangeDescriptions: boolean, recordTimeline: boolean) => void)
161160
| void;
162-
_showNamesWhenTracing: boolean = true;
163161

164162
constructor(
165163
bridge: BackendBridge,
@@ -204,7 +202,6 @@ export default class Agent extends EventEmitter<{
204202
bridge.addListener('reloadAndProfile', this.reloadAndProfile);
205203
bridge.addListener('renamePath', this.renamePath);
206204
bridge.addListener('setTraceUpdatesEnabled', this.setTraceUpdatesEnabled);
207-
bridge.addListener('setShowNamesWhenTracing', this.setShowNamesWhenTracing);
208205
bridge.addListener('startProfiling', this.startProfiling);
209206
bridge.addListener('stopProfiling', this.stopProfiling);
210207
bridge.addListener('storeAsGlobal', this.storeAsGlobal);
@@ -727,7 +724,6 @@ export default class Agent extends EventEmitter<{
727724
this._traceUpdatesEnabled = traceUpdatesEnabled;
728725

729726
setTraceUpdatesEnabled(traceUpdatesEnabled);
730-
this.emit('showNamesWhenTracing', this._showNamesWhenTracing);
731727

732728
for (const rendererID in this._rendererInterfaces) {
733729
const renderer = ((this._rendererInterfaces[
@@ -737,14 +733,6 @@ export default class Agent extends EventEmitter<{
737733
}
738734
};
739735

740-
setShowNamesWhenTracing: (show: boolean) => void = show => {
741-
if (this._showNamesWhenTracing === show) {
742-
return;
743-
}
744-
this._showNamesWhenTracing = show;
745-
this.emit('showNamesWhenTracing', show);
746-
};
747-
748736
syncSelectionFromBuiltinElementsPanel: () => void = () => {
749737
const target = window.__REACT_DEVTOOLS_GLOBAL_HOOK__.$0;
750738
if (target == null) {

packages/react-devtools-shared/src/backend/views/TraceUpdates/index.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,11 @@ const nodeToData: Map<HostInstance, Data> = new Map();
5050
let agent: Agent = ((null: any): Agent);
5151
let drawAnimationFrameID: AnimationFrameID | null = null;
5252
let isEnabled: boolean = false;
53-
let showNames: boolean = false;
5453
let redrawTimeoutID: TimeoutID | null = null;
5554

5655
export function initialize(injectedAgent: Agent): void {
5756
agent = injectedAgent;
5857
agent.addListener('traceUpdates', traceUpdates);
59-
agent.addListener('showNamesWhenTracing', (shouldShowNames: boolean) => {
60-
showNames = shouldShowNames;
61-
if (isEnabled) {
62-
if (drawAnimationFrameID === null) {
63-
drawAnimationFrameID = requestAnimationFrame(prepareToDraw);
64-
}
65-
}
66-
});
6758
}
6859

6960
export function toggleEnabled(value: boolean): void {
@@ -101,9 +92,7 @@ function traceUpdates(nodes: Set<HostInstance>): void {
10192
rect = measureNode(node);
10293
}
10394

104-
let displayName = showNames
105-
? agent.getComponentNameForHostInstance(node)
106-
: null;
95+
let displayName = agent.getComponentNameForHostInstance(node);
10796
if (displayName) {
10897
const {baseComponentName, hocNames} = extractHOCNames(displayName);
10998

@@ -127,7 +116,7 @@ function traceUpdates(nodes: Set<HostInstance>): void {
127116
: now + DISPLAY_DURATION,
128117
lastMeasuredAt,
129118
rect,
130-
displayName: showNames ? displayName : null,
119+
displayName,
131120
});
132121
});
133122

packages/react-devtools-shared/src/bridge.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ type FrontendEvents = {
234234
renamePath: [RenamePath],
235235
savedPreferences: [SavedPreferencesParams],
236236
setTraceUpdatesEnabled: [boolean],
237-
setShowNamesWhenTracing: [boolean],
238237
shutdown: [],
239238
startInspectingHost: [],
240239
startProfiling: [StartProfilingParams],

packages/react-devtools-shared/src/constants.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ export const LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY =
5050
'React::DevTools::traceUpdatesEnabled';
5151
export const LOCAL_STORAGE_SUPPORTS_PROFILING_KEY =
5252
'React::DevTools::supportsProfiling';
53-
export const LOCAL_STORAGE_SHOW_NAMES_WHEN_TRACING_KEY =
54-
'React::DevTools::showNamesWhenTracing';
5553

5654
export const PROFILER_EXPORT_VERSION = 5;
5755

packages/react-devtools-shared/src/devtools/views/Settings/GeneralSettings.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ export default function GeneralSettings(_: {}): React.Node {
3434
setDisplayDensity,
3535
setTheme,
3636
setTraceUpdatesEnabled,
37-
setShowNamesWhenTracing,
3837
theme,
3938
traceUpdatesEnabled,
40-
showNamesWhenTracing,
4139
} = useContext(SettingsContext);
4240

4341
const {backendVersion, supportsTraceUpdates} = useContext(StoreContext);
@@ -85,19 +83,6 @@ export default function GeneralSettings(_: {}): React.Node {
8583
/>{' '}
8684
Highlight updates when components render.
8785
</label>
88-
<div className={styles.Setting}>
89-
<label>
90-
<input
91-
type="checkbox"
92-
checked={showNamesWhenTracing}
93-
disabled={!traceUpdatesEnabled}
94-
onChange={({currentTarget}) =>
95-
setShowNamesWhenTracing(currentTarget.checked)
96-
}
97-
/>{' '}
98-
Show component names while highlighting.
99-
</label>
100-
</div>
10186
</div>
10287
)}
10388

packages/react-devtools-shared/src/devtools/views/Settings/SettingsContext.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
LOCAL_STORAGE_BROWSER_THEME,
2222
LOCAL_STORAGE_PARSE_HOOK_NAMES_KEY,
2323
LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY,
24-
LOCAL_STORAGE_SHOW_NAMES_WHEN_TRACING_KEY,
2524
} from 'react-devtools-shared/src/constants';
2625
import {
2726
COMFORTABLE_LINE_HEIGHT,
@@ -54,9 +53,6 @@ type Context = {
5453

5554
traceUpdatesEnabled: boolean,
5655
setTraceUpdatesEnabled: (value: boolean) => void,
57-
58-
showNamesWhenTracing: boolean,
59-
setShowNamesWhenTracing: (showNames: boolean) => void,
6056
};
6157

6258
const SettingsContext: ReactContext<Context> = createContext<Context>(
@@ -115,11 +111,6 @@ function SettingsContextController({
115111
LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY,
116112
false,
117113
);
118-
const [showNamesWhenTracing, setShowNamesWhenTracing] =
119-
useLocalStorageWithLog<boolean>(
120-
LOCAL_STORAGE_SHOW_NAMES_WHEN_TRACING_KEY,
121-
true,
122-
);
123114

124115
const documentElements = useMemo<DocumentElements>(() => {
125116
const array: Array<HTMLElement> = [
@@ -173,10 +164,6 @@ function SettingsContextController({
173164
bridge.send('setTraceUpdatesEnabled', traceUpdatesEnabled);
174165
}, [bridge, traceUpdatesEnabled]);
175166

176-
useEffect(() => {
177-
bridge.send('setShowNamesWhenTracing', showNamesWhenTracing);
178-
}, [bridge, showNamesWhenTracing]);
179-
180167
const value: Context = useMemo(
181168
() => ({
182169
displayDensity,
@@ -192,8 +179,6 @@ function SettingsContextController({
192179
theme,
193180
browserTheme,
194181
traceUpdatesEnabled,
195-
showNamesWhenTracing,
196-
setShowNamesWhenTracing,
197182
}),
198183
[
199184
displayDensity,
@@ -205,7 +190,6 @@ function SettingsContextController({
205190
theme,
206191
browserTheme,
207192
traceUpdatesEnabled,
208-
showNamesWhenTracing,
209193
],
210194
);
211195

0 commit comments

Comments
 (0)