9
9
10
10
import Agent from 'react-devtools-shared/src/backend/agent' ;
11
11
import { destroy as destroyCanvas , draw } from './canvas' ;
12
- import { getNestedBoundingClientRect } from '../utils' ;
12
+ import { extractHOCNames , getNestedBoundingClientRect } from '../utils' ;
13
13
14
14
import type { HostInstance } from '../../types' ;
15
15
import type { Rect } from '../utils' ;
@@ -24,6 +24,12 @@ const MAX_DISPLAY_DURATION = 3000;
24
24
// How long should a rect be considered valid for?
25
25
const REMEASUREMENT_AFTER_DURATION = 250 ;
26
26
27
+ // Markers for different types of HOCs
28
+ const HOC_MARKERS = new Map ( [
29
+ [ 'Forget' , '✨ń' ] ,
30
+ [ 'Memo' , '🧠' ] ,
31
+ ] ) ;
32
+
27
33
// Some environments (e.g. React Native / Hermes) don't support the performance API yet.
28
34
const getCurrentTime =
29
35
// $FlowFixMe[method-unbinding]
@@ -81,24 +87,33 @@ export function toggleEnabled(value: boolean): void {
81
87
}
82
88
83
89
function traceUpdates ( nodes : Set < HostInstance > ) : void {
84
- if ( ! isEnabled ) {
85
- return ;
86
- }
90
+ if ( ! isEnabled ) return ;
87
91
88
92
nodes . forEach ( node => {
89
93
const data = nodeToData . get ( node ) ;
90
94
const now = getCurrentTime ( ) ;
91
95
92
96
let lastMeasuredAt = data != null ? data . lastMeasuredAt : 0 ;
93
97
let rect = data != null ? data . rect : null ;
98
+
94
99
if ( rect === null || lastMeasuredAt + REMEASUREMENT_AFTER_DURATION < now ) {
95
100
lastMeasuredAt = now ;
96
101
rect = measureNode ( node ) ;
97
102
}
98
103
99
- let displayName = this . showNames && agent . getComponentNameForHostInstance ( node ) ;
100
- if ( displayName != null && displayName . startsWith ( 'Forget(' ) ) {
101
- displayName = '✨' + displayName . slice ( 7 , - 1 ) ;
104
+ let displayName = showNames
105
+ ? agent . getComponentNameForHostInstance ( node )
106
+ : null ;
107
+ if ( displayName ) {
108
+ const { baseComponentName, hocNames} = extractHOCNames ( displayName ) ;
109
+
110
+ const markers = hocNames . map ( hoc => HOC_MARKERS . get ( hoc ) || '' ) . join ( '' ) ;
111
+
112
+ const enhancedDisplayName = markers
113
+ ? `${ markers } ${ baseComponentName } `
114
+ : baseComponentName ;
115
+
116
+ displayName = enhancedDisplayName ;
102
117
}
103
118
104
119
nodeToData . set ( node , {
0 commit comments