@@ -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 ,
@@ -171,6 +172,7 @@ function use<T>(usable: Usable<T>): T {
171
172
case 'fulfilled' : {
172
173
const fulfilledValue : T = thenable . value ;
173
174
hookLog . push ( {
175
+ displayName : null ,
174
176
primitive : 'Promise' ,
175
177
stackError : new Error ( ) ,
176
178
value : fulfilledValue ,
@@ -187,6 +189,7 @@ function use<T>(usable: Usable<T>): T {
187
189
// If this was an uncached Promise we have to abandon this attempt
188
190
// but we can still emit anything up until this point.
189
191
hookLog.push({
192
+ displayName : null ,
190
193
primitive : 'Unresolved' ,
191
194
stackError : new Error ( ) ,
192
195
value : thenable ,
@@ -199,6 +202,7 @@ function use<T>(usable: Usable<T>): T {
199
202
const value = readContext ( context ) ;
200
203
201
204
hookLog . push ( {
205
+ displayName : context . displayName || 'Context' ,
202
206
primitive : 'Context (use)' ,
203
207
stackError : new Error ( ) ,
204
208
value,
@@ -215,6 +219,7 @@ function use<T>(usable: Usable<T>): T {
215
219
216
220
function useContext < T > (context: ReactContext< T > ): T {
217
221
hookLog . push ( {
222
+ displayName : context . displayName || null ,
218
223
primitive : 'Context' ,
219
224
stackError : new Error ( ) ,
220
225
value : context . _currentValue ,
@@ -235,6 +240,7 @@ function useState<S>(
235
240
initialState ( )
236
241
: initialState ;
237
242
hookLog . push ( {
243
+ displayName : null ,
238
244
primitive : 'State' ,
239
245
stackError : new Error ( ) ,
240
246
value : state ,
@@ -256,6 +262,7 @@ function useReducer<S, I, A>(
256
262
state = init !== undefined ? init ( initialArg ) : ( ( initialArg : any ) : S ) ;
257
263
}
258
264
hookLog . push ( {
265
+ displayName : null ,
259
266
primitive : 'Reducer' ,
260
267
stackError : new Error ( ) ,
261
268
value : state ,
@@ -268,6 +275,7 @@ function useRef<T>(initialValue: T): {current: T} {
268
275
const hook = nextHook ( ) ;
269
276
const ref = hook !== null ? hook . memoizedState : { current : initialValue } ;
270
277
hookLog . push ( {
278
+ displayName : null ,
271
279
primitive : 'Ref' ,
272
280
stackError : new Error ( ) ,
273
281
value : ref . current ,
@@ -279,6 +287,7 @@ function useRef<T>(initialValue: T): {current: T} {
279
287
function useCacheRefresh(): () => void {
280
288
const hook = nextHook ( ) ;
281
289
hookLog . push ( {
290
+ displayName : null ,
282
291
primitive : 'CacheRefresh' ,
283
292
stackError : new Error ( ) ,
284
293
value : hook !== null ? hook . memoizedState : function refresh ( ) { } ,
@@ -293,6 +302,7 @@ function useLayoutEffect(
293
302
): void {
294
303
nextHook ( ) ;
295
304
hookLog . push ( {
305
+ displayName : null ,
296
306
primitive : 'LayoutEffect' ,
297
307
stackError : new Error ( ) ,
298
308
value : create ,
@@ -306,6 +316,7 @@ function useInsertionEffect(
306
316
): void {
307
317
nextHook ( ) ;
308
318
hookLog . push ( {
319
+ displayName : null ,
309
320
primitive : 'InsertionEffect' ,
310
321
stackError : new Error ( ) ,
311
322
value : create ,
@@ -319,6 +330,7 @@ function useEffect(
319
330
): void {
320
331
nextHook ( ) ;
321
332
hookLog . push ( {
333
+ displayName : null ,
322
334
primitive : 'Effect' ,
323
335
stackError : new Error ( ) ,
324
336
value : create ,
@@ -341,6 +353,7 @@ function useImperativeHandle<T>(
341
353
instance = ref . current ;
342
354
}
343
355
hookLog.push({
356
+ displayName : null ,
344
357
primitive : 'ImperativeHandle' ,
345
358
stackError : new Error ( ) ,
346
359
value : instance ,
@@ -350,6 +363,7 @@ function useImperativeHandle<T>(
350
363
351
364
function useDebugValue ( value : any , formatterFn : ?( value : any ) => any ) {
352
365
hookLog . push ( {
366
+ displayName : null ,
353
367
primitive : 'DebugValue' ,
354
368
stackError : new Error ( ) ,
355
369
value : typeof formatterFn === 'function' ? formatterFn ( value ) : value ,
@@ -360,6 +374,7 @@ function useDebugValue(value: any, formatterFn: ?(value: any) => any) {
360
374
function useCallback< T > (callback: T, inputs: Array< mixed > | void | null): T {
361
375
const hook = nextHook ( ) ;
362
376
hookLog . push ( {
377
+ displayName : null ,
363
378
primitive : 'Callback' ,
364
379
stackError : new Error ( ) ,
365
380
value : hook !== null ? hook . memoizedState [ 0 ] : callback ,
@@ -375,6 +390,7 @@ function useMemo<T>(
375
390
const hook = nextHook ( ) ;
376
391
const value = hook !== null ? hook . memoizedState [ 0 ] : nextCreate ( ) ;
377
392
hookLog . push ( {
393
+ displayName : null ,
378
394
primitive : 'Memo' ,
379
395
stackError : new Error ( ) ,
380
396
value,
@@ -395,6 +411,7 @@ function useSyncExternalStore<T>(
395
411
nextHook ( ) ; // Effect
396
412
const value = getSnapshot ( ) ;
397
413
hookLog . push ( {
414
+ displayName : null ,
398
415
primitive : 'SyncExternalStore' ,
399
416
stackError : new Error ( ) ,
400
417
value,
@@ -413,6 +430,7 @@ function useTransition(): [
413
430
nextHook ( ) ; // State
414
431
nextHook ( ) ; // Callback
415
432
hookLog . push ( {
433
+ displayName : null ,
416
434
primitive : 'Transition' ,
417
435
stackError : new Error ( ) ,
418
436
value : undefined ,
@@ -424,6 +442,7 @@ function useTransition(): [
424
442
function useDeferredValue< T > (value: T, initialValue?: T): T {
425
443
const hook = nextHook ( ) ;
426
444
hookLog . push ( {
445
+ displayName : null ,
427
446
primitive : 'DeferredValue' ,
428
447
stackError : new Error ( ) ,
429
448
value : hook !== null ? hook . memoizedState : value ,
@@ -436,6 +455,7 @@ function useId(): string {
436
455
const hook = nextHook ( ) ;
437
456
const id = hook !== null ? hook . memoizedState : '' ;
438
457
hookLog . push ( {
458
+ displayName : null ,
439
459
primitive : 'Id' ,
440
460
stackError : new Error ( ) ,
441
461
value : id ,
@@ -485,6 +505,7 @@ function useOptimistic<S, A>(
485
505
state = passthrough ;
486
506
}
487
507
hookLog . push ( {
508
+ displayName : null ,
488
509
primitive : 'Optimistic' ,
489
510
stackError : new Error ( ) ,
490
511
value : state ,
@@ -507,6 +528,7 @@ function useFormState<S, P>(
507
528
state = initialState ;
508
529
}
509
530
hookLog.push({
531
+ displayName : null ,
510
532
primitive : 'FormState' ,
511
533
stackError : new Error ( ) ,
512
534
value : state ,
@@ -780,7 +802,7 @@ function buildTree(
780
802
}
781
803
prevStack = stack ;
782
804
}
783
- const { primitive , debugInfo } = hook;
805
+ const { displayName , primitive , debugInfo } = hook;
784
806
785
807
// For now, the "id" of stateful hooks is just the stateful hook index.
786
808
// Custom hooks have no ids, nor do non-stateful native hooks (e.g. Context, DebugValue).
@@ -795,7 +817,7 @@ function buildTree(
795
817
796
818
// For the time being, only State and Reducer hooks support runtime overrides.
797
819
const isStateEditable = primitive === 'Reducer' || primitive === 'State';
798
- const name = primitive === 'Context (use)' ? 'Context' : primitive;
820
+ const name = displayName || primitive;
799
821
const levelChild: HooksNode = {
800
822
id ,
801
823
isStateEditable ,
0 commit comments