@@ -44,6 +44,7 @@ import {
44
44
ComponentMeasuresView ,
45
45
FlamechartView ,
46
46
NativeEventsView ,
47
+ NetworkMeasuresView ,
47
48
ReactMeasuresView ,
48
49
SchedulingEventsView ,
49
50
SnapshotsView ,
@@ -128,6 +129,18 @@ const zoomToBatch = (
128
129
viewState . updateHorizontalScrollState ( scrollState ) ;
129
130
} ;
130
131
132
+ const EMPTY_CONTEXT_INFO : ReactHoverContextInfo = {
133
+ componentMeasure : null ,
134
+ flamechartStackFrame : null ,
135
+ measure : null ,
136
+ nativeEvent : null ,
137
+ networkMeasure : null ,
138
+ schedulingEvent : null ,
139
+ snapshot : null ,
140
+ suspenseEvent : null ,
141
+ userTimingMark : null ,
142
+ } ;
143
+
131
144
type AutoSizedCanvasProps = { |
132
145
data : ReactProfilerData ,
133
146
height : number ,
@@ -150,14 +163,20 @@ function AutoSizedCanvas({
150
163
setHoveredEvent ,
151
164
] = useState < ReactHoverContextInfo | null > ( null ) ;
152
165
153
- const surfaceRef = useRef ( new Surface ( ) ) ;
166
+ const resetHoveredEvent = useCallback (
167
+ ( ) => setHoveredEvent ( EMPTY_CONTEXT_INFO ) ,
168
+ [ ] ,
169
+ ) ;
170
+
171
+ const surfaceRef = useRef ( new Surface ( resetHoveredEvent ) ) ;
154
172
const userTimingMarksViewRef = useRef ( null ) ;
155
173
const nativeEventsViewRef = useRef ( null ) ;
156
174
const schedulingEventsViewRef = useRef ( null ) ;
157
175
const suspenseEventsViewRef = useRef ( null ) ;
158
176
const componentMeasuresViewRef = useRef ( null ) ;
159
177
const reactMeasuresViewRef = useRef ( null ) ;
160
178
const flamechartViewRef = useRef ( null ) ;
179
+ const networkMeasuresViewRef = useRef ( null ) ;
161
180
const snapshotsViewRef = useRef ( null ) ;
162
181
163
182
const { hideMenu : hideContextMenu } = useContext ( RegistryContext ) ;
@@ -318,6 +337,22 @@ function AutoSizedCanvas({
318
337
) ;
319
338
}
320
339
340
+ let networkMeasuresViewWrapper = null ;
341
+ if ( data . snapshots . length > 0 ) {
342
+ const networkMeasuresView = new NetworkMeasuresView (
343
+ surface ,
344
+ defaultFrame ,
345
+ data ,
346
+ ) ;
347
+ networkMeasuresViewRef . current = networkMeasuresView ;
348
+ networkMeasuresViewWrapper = createViewHelper (
349
+ networkMeasuresView ,
350
+ 'network' ,
351
+ true ,
352
+ true ,
353
+ ) ;
354
+ }
355
+
321
356
const flamechartView = new FlamechartView (
322
357
surface ,
323
358
defaultFrame ,
@@ -357,6 +392,9 @@ function AutoSizedCanvas({
357
392
if ( snapshotsViewWrapper !== null ) {
358
393
rootView . addSubview ( snapshotsViewWrapper ) ;
359
394
}
395
+ if ( networkMeasuresViewWrapper !== null ) {
396
+ rootView . addSubview ( networkMeasuresViewWrapper ) ;
397
+ }
360
398
rootView . addSubview ( flamechartViewWrapper ) ;
361
399
362
400
const verticalScrollOverflowView = new VerticalScrollOverflowView (
@@ -395,16 +433,18 @@ function AutoSizedCanvas({
395
433
prevHoverEvent . flamechartStackFrame !== null ||
396
434
prevHoverEvent . measure !== null ||
397
435
prevHoverEvent . nativeEvent !== null ||
436
+ prevHoverEvent . networkMeasure !== null ||
398
437
prevHoverEvent . schedulingEvent !== null ||
438
+ prevHoverEvent . snapshot !== null ||
399
439
prevHoverEvent . suspenseEvent !== null ||
400
440
prevHoverEvent . userTimingMark !== null
401
441
) {
402
442
return {
403
443
componentMeasure : null ,
404
- data : prevHoverEvent . data ,
405
444
flamechartStackFrame : null ,
406
445
measure : null ,
407
446
nativeEvent : null ,
447
+ networkMeasure : null ,
408
448
schedulingEvent : null ,
409
449
snapshot : null ,
410
450
suspenseEvent : null ,
@@ -460,10 +500,10 @@ function AutoSizedCanvas({
460
500
if ( ! hoveredEvent || hoveredEvent . userTimingMark !== userTimingMark ) {
461
501
setHoveredEvent ( {
462
502
componentMeasure : null ,
463
- data,
464
503
flamechartStackFrame : null ,
465
504
measure : null ,
466
505
nativeEvent : null ,
506
+ networkMeasure : null ,
467
507
schedulingEvent : null ,
468
508
snapshot : null ,
469
509
suspenseEvent : null ,
@@ -479,10 +519,10 @@ function AutoSizedCanvas({
479
519
if ( ! hoveredEvent || hoveredEvent . nativeEvent !== nativeEvent ) {
480
520
setHoveredEvent ( {
481
521
componentMeasure : null ,
482
- data,
483
522
flamechartStackFrame : null ,
484
523
measure : null ,
485
524
nativeEvent,
525
+ networkMeasure : null ,
486
526
schedulingEvent : null ,
487
527
snapshot : null ,
488
528
suspenseEvent : null ,
@@ -498,10 +538,10 @@ function AutoSizedCanvas({
498
538
if ( ! hoveredEvent || hoveredEvent . schedulingEvent !== schedulingEvent ) {
499
539
setHoveredEvent ( {
500
540
componentMeasure : null ,
501
- data,
502
541
flamechartStackFrame : null ,
503
542
measure : null ,
504
543
nativeEvent : null ,
544
+ networkMeasure : null ,
505
545
schedulingEvent,
506
546
snapshot : null ,
507
547
suspenseEvent : null ,
@@ -517,10 +557,10 @@ function AutoSizedCanvas({
517
557
if ( ! hoveredEvent || hoveredEvent . suspenseEvent !== suspenseEvent ) {
518
558
setHoveredEvent ( {
519
559
componentMeasure : null ,
520
- data,
521
560
flamechartStackFrame : null ,
522
561
measure : null ,
523
562
nativeEvent : null ,
563
+ networkMeasure : null ,
524
564
schedulingEvent : null ,
525
565
snapshot : null ,
526
566
suspenseEvent,
@@ -536,10 +576,10 @@ function AutoSizedCanvas({
536
576
if ( ! hoveredEvent || hoveredEvent . measure !== measure ) {
537
577
setHoveredEvent ( {
538
578
componentMeasure : null ,
539
- data,
540
579
flamechartStackFrame : null ,
541
580
measure,
542
581
nativeEvent : null ,
582
+ networkMeasure : null ,
543
583
schedulingEvent : null ,
544
584
snapshot : null ,
545
585
suspenseEvent : null ,
@@ -558,10 +598,10 @@ function AutoSizedCanvas({
558
598
) {
559
599
setHoveredEvent ( {
560
600
componentMeasure,
561
- data,
562
601
flamechartStackFrame : null ,
563
602
measure : null ,
564
603
nativeEvent : null ,
604
+ networkMeasure : null ,
565
605
schedulingEvent : null ,
566
606
snapshot : null ,
567
607
suspenseEvent : null ,
@@ -577,10 +617,10 @@ function AutoSizedCanvas({
577
617
if ( ! hoveredEvent || hoveredEvent . snapshot !== snapshot ) {
578
618
setHoveredEvent ( {
579
619
componentMeasure : null ,
580
- data,
581
620
flamechartStackFrame : null ,
582
621
measure : null ,
583
622
nativeEvent : null ,
623
+ networkMeasure : null ,
584
624
schedulingEvent : null ,
585
625
snapshot,
586
626
suspenseEvent : null ,
@@ -599,10 +639,10 @@ function AutoSizedCanvas({
599
639
) {
600
640
setHoveredEvent ( {
601
641
componentMeasure : null ,
602
- data,
603
642
flamechartStackFrame,
604
643
measure : null ,
605
644
nativeEvent : null ,
645
+ networkMeasure : null ,
606
646
schedulingEvent : null ,
607
647
snapshot : null ,
608
648
suspenseEvent : null ,
@@ -611,53 +651,79 @@ function AutoSizedCanvas({
611
651
}
612
652
} ) ;
613
653
}
654
+
655
+ const { current : networkMeasuresView } = networkMeasuresViewRef ;
656
+ if ( networkMeasuresView ) {
657
+ networkMeasuresView . onHover = networkMeasure => {
658
+ if ( ! hoveredEvent || hoveredEvent . networkMeasure !== networkMeasure ) {
659
+ setHoveredEvent ( {
660
+ componentMeasure : null ,
661
+ flamechartStackFrame : null ,
662
+ measure : null ,
663
+ nativeEvent : null ,
664
+ networkMeasure,
665
+ schedulingEvent : null ,
666
+ snapshot : null ,
667
+ suspenseEvent : null ,
668
+ userTimingMark : null ,
669
+ } ) ;
670
+ }
671
+ } ;
672
+ }
614
673
} , [
615
674
hoveredEvent ,
616
675
data , // Attach onHover callbacks when views are re-created on data change
617
676
] ) ;
618
677
619
678
useLayoutEffect ( ( ) => {
620
- const { current : userTimingMarksView } = userTimingMarksViewRef ;
679
+ const userTimingMarksView = userTimingMarksViewRef . current ;
621
680
if ( userTimingMarksView ) {
622
681
userTimingMarksView . setHoveredMark (
623
682
hoveredEvent ? hoveredEvent . userTimingMark : null ,
624
683
) ;
625
684
}
626
685
627
- const { current : nativeEventsView } = nativeEventsViewRef ;
686
+ const nativeEventsView = nativeEventsViewRef . current ;
628
687
if ( nativeEventsView ) {
629
688
nativeEventsView . setHoveredEvent (
630
689
hoveredEvent ? hoveredEvent . nativeEvent : null ,
631
690
) ;
632
691
}
633
692
634
- const { current : schedulingEventsView } = schedulingEventsViewRef ;
693
+ const schedulingEventsView = schedulingEventsViewRef . current ;
635
694
if ( schedulingEventsView ) {
636
695
schedulingEventsView . setHoveredEvent (
637
696
hoveredEvent ? hoveredEvent . schedulingEvent : null ,
638
697
) ;
639
698
}
640
699
641
- const { current : suspenseEventsView } = suspenseEventsViewRef ;
700
+ const suspenseEventsView = suspenseEventsViewRef . current ;
642
701
if ( suspenseEventsView ) {
643
702
suspenseEventsView . setHoveredEvent (
644
703
hoveredEvent ? hoveredEvent . suspenseEvent : null ,
645
704
) ;
646
705
}
647
706
648
- const { current : reactMeasuresView } = reactMeasuresViewRef ;
707
+ const reactMeasuresView = reactMeasuresViewRef . current ;
649
708
if ( reactMeasuresView ) {
650
709
reactMeasuresView . setHoveredMeasure (
651
710
hoveredEvent ? hoveredEvent . measure : null ,
652
711
) ;
653
712
}
654
713
655
- const { current : flamechartView } = flamechartViewRef ;
714
+ const flamechartView = flamechartViewRef . current ;
656
715
if ( flamechartView ) {
657
716
flamechartView . setHoveredFlamechartStackFrame (
658
717
hoveredEvent ? hoveredEvent . flamechartStackFrame : null ,
659
718
) ;
660
719
}
720
+
721
+ const networkMeasuresView = networkMeasuresViewRef . current ;
722
+ if ( networkMeasuresView ) {
723
+ networkMeasuresView . setHoveredEvent (
724
+ hoveredEvent ? hoveredEvent . networkMeasure : null ,
725
+ ) ;
726
+ }
661
727
} , [ hoveredEvent ] ) ;
662
728
663
729
// Draw to canvas in React's commit phase
@@ -677,6 +743,7 @@ function AutoSizedCanvas({
677
743
componentMeasure,
678
744
flamechartStackFrame,
679
745
measure,
746
+ networkMeasure,
680
747
schedulingEvent,
681
748
suspenseEvent,
682
749
} = contextData . hoveredEvent ;
@@ -689,6 +756,13 @@ function AutoSizedCanvas({
689
756
Copy component name
690
757
</ ContextMenuItem >
691
758
) }
759
+ { networkMeasure !== null && (
760
+ < ContextMenuItem
761
+ onClick = { ( ) => copy ( networkMeasure . url ) }
762
+ title = "Copy URL" >
763
+ Copy URL
764
+ </ ContextMenuItem >
765
+ ) }
692
766
{ schedulingEvent !== null && (
693
767
< ContextMenuItem
694
768
onClick = { ( ) => copy ( schedulingEvent . componentName ) }
0 commit comments