@@ -39,6 +39,7 @@ type CurrentDispatcherRef = typeof ReactSharedInternals.ReactCurrentDispatcher;
39
39
// Used to track hooks called during a render
40
40
41
41
type HookLogEntry = {
42
+ displayName : string | null ,
42
43
primitive : string ,
43
44
stackError : Error ,
44
45
value : mixed ,
@@ -164,6 +165,7 @@ function use<T>(usable: Usable<T>): T {
164
165
case 'fulfilled' : {
165
166
const fulfilledValue : T = thenable . value ;
166
167
hookLog . push ( {
168
+ displayName : null ,
167
169
primitive : 'Promise' ,
168
170
stackError : new Error ( ) ,
169
171
value : fulfilledValue ,
@@ -180,6 +182,7 @@ function use<T>(usable: Usable<T>): T {
180
182
// If this was an uncached Promise we have to abandon this attempt
181
183
// but we can still emit anything up until this point.
182
184
hookLog.push({
185
+ displayName : null ,
183
186
primitive : 'Unresolved' ,
184
187
stackError : new Error ( ) ,
185
188
value : thenable ,
@@ -192,6 +195,7 @@ function use<T>(usable: Usable<T>): T {
192
195
const value = readContext ( context ) ;
193
196
194
197
hookLog . push ( {
198
+ displayName : context . displayName || 'Context' ,
195
199
primitive : 'Context (use)' ,
196
200
stackError : new Error ( ) ,
197
201
value,
@@ -208,6 +212,7 @@ function use<T>(usable: Usable<T>): T {
208
212
209
213
function useContext < T > (context: ReactContext< T > ): T {
210
214
hookLog . push ( {
215
+ displayName : context . displayName || null ,
211
216
primitive : 'Context' ,
212
217
stackError : new Error ( ) ,
213
218
value : context . _currentValue ,
@@ -228,6 +233,7 @@ function useState<S>(
228
233
initialState ( )
229
234
: initialState ;
230
235
hookLog . push ( {
236
+ displayName : null ,
231
237
primitive : 'State' ,
232
238
stackError : new Error ( ) ,
233
239
value : state ,
@@ -249,6 +255,7 @@ function useReducer<S, I, A>(
249
255
state = init !== undefined ? init ( initialArg ) : ( ( initialArg : any ) : S ) ;
250
256
}
251
257
hookLog . push ( {
258
+ displayName : null ,
252
259
primitive : 'Reducer' ,
253
260
stackError : new Error ( ) ,
254
261
value : state ,
@@ -261,6 +268,7 @@ function useRef<T>(initialValue: T): {current: T} {
261
268
const hook = nextHook ( ) ;
262
269
const ref = hook !== null ? hook . memoizedState : { current : initialValue } ;
263
270
hookLog . push ( {
271
+ displayName : null ,
264
272
primitive : 'Ref' ,
265
273
stackError : new Error ( ) ,
266
274
value : ref . current ,
@@ -272,6 +280,7 @@ function useRef<T>(initialValue: T): {current: T} {
272
280
function useCacheRefresh(): () => void {
273
281
const hook = nextHook ( ) ;
274
282
hookLog . push ( {
283
+ displayName : null ,
275
284
primitive : 'CacheRefresh' ,
276
285
stackError : new Error ( ) ,
277
286
value : hook !== null ? hook . memoizedState : function refresh ( ) { } ,
@@ -286,6 +295,7 @@ function useLayoutEffect(
286
295
): void {
287
296
nextHook ( ) ;
288
297
hookLog . push ( {
298
+ displayName : null ,
289
299
primitive : 'LayoutEffect' ,
290
300
stackError : new Error ( ) ,
291
301
value : create ,
@@ -299,6 +309,7 @@ function useInsertionEffect(
299
309
): void {
300
310
nextHook ( ) ;
301
311
hookLog . push ( {
312
+ displayName : null ,
302
313
primitive : 'InsertionEffect' ,
303
314
stackError : new Error ( ) ,
304
315
value : create ,
@@ -312,6 +323,7 @@ function useEffect(
312
323
): void {
313
324
nextHook ( ) ;
314
325
hookLog . push ( {
326
+ displayName : null ,
315
327
primitive : 'Effect' ,
316
328
stackError : new Error ( ) ,
317
329
value : create ,
@@ -334,6 +346,7 @@ function useImperativeHandle<T>(
334
346
instance = ref . current ;
335
347
}
336
348
hookLog.push({
349
+ displayName : null ,
337
350
primitive : 'ImperativeHandle' ,
338
351
stackError : new Error ( ) ,
339
352
value : instance ,
@@ -343,6 +356,7 @@ function useImperativeHandle<T>(
343
356
344
357
function useDebugValue ( value : any , formatterFn : ?( value : any ) => any ) {
345
358
hookLog . push ( {
359
+ displayName : null ,
346
360
primitive : 'DebugValue' ,
347
361
stackError : new Error ( ) ,
348
362
value : typeof formatterFn === 'function' ? formatterFn ( value ) : value ,
@@ -353,6 +367,7 @@ function useDebugValue(value: any, formatterFn: ?(value: any) => any) {
353
367
function useCallback< T > (callback: T, inputs: Array< mixed > | void | null): T {
354
368
const hook = nextHook ( ) ;
355
369
hookLog . push ( {
370
+ displayName : null ,
356
371
primitive : 'Callback' ,
357
372
stackError : new Error ( ) ,
358
373
value : hook !== null ? hook . memoizedState [ 0 ] : callback ,
@@ -368,6 +383,7 @@ function useMemo<T>(
368
383
const hook = nextHook ( ) ;
369
384
const value = hook !== null ? hook . memoizedState [ 0 ] : nextCreate ( ) ;
370
385
hookLog . push ( {
386
+ displayName : null ,
371
387
primitive : 'Memo' ,
372
388
stackError : new Error ( ) ,
373
389
value,
@@ -388,6 +404,7 @@ function useSyncExternalStore<T>(
388
404
nextHook ( ) ; // Effect
389
405
const value = getSnapshot ( ) ;
390
406
hookLog . push ( {
407
+ displayName : null ,
391
408
primitive : 'SyncExternalStore' ,
392
409
stackError : new Error ( ) ,
393
410
value,
@@ -406,6 +423,7 @@ function useTransition(): [
406
423
nextHook ( ) ; // State
407
424
nextHook ( ) ; // Callback
408
425
hookLog . push ( {
426
+ displayName : null ,
409
427
primitive : 'Transition' ,
410
428
stackError : new Error ( ) ,
411
429
value : undefined ,
@@ -417,6 +435,7 @@ function useTransition(): [
417
435
function useDeferredValue< T > (value: T, initialValue?: T): T {
418
436
const hook = nextHook ( ) ;
419
437
hookLog . push ( {
438
+ displayName : null ,
420
439
primitive : 'DeferredValue' ,
421
440
stackError : new Error ( ) ,
422
441
value : hook !== null ? hook . memoizedState : value ,
@@ -429,6 +448,7 @@ function useId(): string {
429
448
const hook = nextHook ( ) ;
430
449
const id = hook !== null ? hook . memoizedState : '' ;
431
450
hookLog . push ( {
451
+ displayName : null ,
432
452
primitive : 'Id' ,
433
453
stackError : new Error ( ) ,
434
454
value : id ,
@@ -478,6 +498,7 @@ function useOptimistic<S, A>(
478
498
state = passthrough ;
479
499
}
480
500
hookLog . push ( {
501
+ displayName : null ,
481
502
primitive : 'Optimistic' ,
482
503
stackError : new Error ( ) ,
483
504
value : state ,
@@ -500,6 +521,7 @@ function useFormState<S, P>(
500
521
state = initialState ;
501
522
}
502
523
hookLog.push({
524
+ displayName : null ,
503
525
primitive : 'FormState' ,
504
526
stackError : new Error ( ) ,
505
527
value : state ,
@@ -773,7 +795,7 @@ function buildTree(
773
795
}
774
796
prevStack = stack ;
775
797
}
776
- const { primitive , debugInfo } = hook;
798
+ const { displayName , primitive , debugInfo } = hook;
777
799
778
800
// For now, the "id" of stateful hooks is just the stateful hook index.
779
801
// Custom hooks have no ids, nor do non-stateful native hooks (e.g. Context, DebugValue).
@@ -788,7 +810,7 @@ function buildTree(
788
810
789
811
// For the time being, only State and Reducer hooks support runtime overrides.
790
812
const isStateEditable = primitive === 'Reducer' || primitive === 'State';
791
- const name = primitive === 'Context (use)' ? 'Context' : primitive;
813
+ const name = displayName || primitive;
792
814
const levelChild: HooksNode = {
793
815
id ,
794
816
isStateEditable ,
0 commit comments