99
1010import Agent from 'react-devtools-shared/src/backend/agent' ;
1111import { destroy as destroyCanvas , draw } from './canvas' ;
12- import { getNestedBoundingClientRect } from '../utils' ;
12+ import { extractHOCNames , getNestedBoundingClientRect } from '../utils' ;
1313
1414import type { HostInstance } from '../../types' ;
1515import type { Rect } from '../utils' ;
@@ -24,6 +24,12 @@ const MAX_DISPLAY_DURATION = 3000;
2424// How long should a rect be considered valid for?
2525const REMEASUREMENT_AFTER_DURATION = 250 ;
2626
27+ // Markers for different types of HOCs
28+ const HOC_MARKERS = new Map ( [
29+ [ 'Forget' , '✨ń' ] ,
30+ [ 'Memo' , '🧠' ] ,
31+ ] ) ;
32+
2733// Some environments (e.g. React Native / Hermes) don't support the performance API yet.
2834const getCurrentTime =
2935 // $FlowFixMe[method-unbinding]
@@ -81,25 +87,36 @@ export function toggleEnabled(value: boolean): void {
8187}
8288
8389function traceUpdates ( nodes : Set < HostInstance > ) : void {
84- if ( ! isEnabled ) {
85- return ;
86- }
90+ if ( ! isEnabled ) return ;
8791
8892 nodes . forEach ( node => {
8993 const data = nodeToData . get ( node ) ;
9094 const now = getCurrentTime ( ) ;
9195
9296 let lastMeasuredAt = data != null ? data . lastMeasuredAt : 0 ;
9397 let rect = data != null ? data . rect : null ;
98+
9499 if ( rect === null || lastMeasuredAt + REMEASUREMENT_AFTER_DURATION < now ) {
95100 lastMeasuredAt = now ;
96101 rect = measureNode ( node ) ;
97102 }
98103
99- let displayName = this . showNames && agent . getComponentNameForHostInstance ( node ) ;
100- if ( displayName != null && displayName . startsWith ( 'Forget(' ) ) {
101- displayName = '✨' + displayName . slice ( 7 , - 1 ) ;
102- }
104+ let displayName = showNames
105+ ? agent . getComponentNameForHostInstance ( node )
106+ : null ;
107+ if ( displayName ) {
108+ const { baseComponentName, hocNames } = extractHOCNames ( displayName ) ;
109+
110+ const markers = hocNames
111+ . map ( hoc => HOC_MARKERS . get ( hoc ) || '' )
112+ . join ( '' ) ;
113+
114+ const enhancedDisplayName = markers
115+ ? `${ markers } ${ baseComponentName } `
116+ : baseComponentName ;
117+
118+ displayName = enhancedDisplayName ;
119+ }
103120
104121 nodeToData . set ( node , {
105122 count : data != null ? data . count + 1 : 1 ,
0 commit comments