@@ -125,6 +125,20 @@ let assertConsoleErrorDev;
125
125
126
126
describe ( 'ReactFlight' , ( ) => {
127
127
beforeEach ( ( ) => {
128
+ // Mock performance.now for timing tests
129
+ let time = 10 ;
130
+ const now = jest . fn ( ) . mockImplementation ( ( ) => {
131
+ return time ++ ;
132
+ } ) ;
133
+ Object . defineProperty ( performance , 'timeOrigin' , {
134
+ value : time ,
135
+ configurable : true ,
136
+ } ) ;
137
+ Object . defineProperty ( performance , 'now' , {
138
+ value : now ,
139
+ configurable : true ,
140
+ } ) ;
141
+
128
142
jest . resetModules ( ) ;
129
143
jest . mock ( 'react' , ( ) => require ( 'react/react.react-server' ) ) ;
130
144
ReactServer = require ( 'react' ) ;
@@ -274,6 +288,7 @@ describe('ReactFlight', () => {
274
288
} ) ;
275
289
} ) ;
276
290
291
+ // @gate enableComponentPerformanceTrack
277
292
it ( 'can render a Client Component using a module reference and render there' , async ( ) => {
278
293
function UserClient ( props ) {
279
294
return (
@@ -300,6 +315,7 @@ describe('ReactFlight', () => {
300
315
expect ( getDebugInfo ( greeting ) ) . toEqual (
301
316
__DEV__
302
317
? [
318
+ { time : 11 } ,
303
319
{
304
320
name : 'Greeting' ,
305
321
env : 'Server' ,
@@ -322,6 +338,7 @@ describe('ReactFlight', () => {
322
338
expect ( ReactNoop ) . toMatchRenderedOutput ( < span > Hello, Seb Smith</ span > ) ;
323
339
} ) ;
324
340
341
+ // @gate enableComponentPerformanceTrack
325
342
it ( 'can render a shared forwardRef Component' , async ( ) => {
326
343
const Greeting = React . forwardRef ( function Greeting (
327
344
{ firstName, lastName} ,
@@ -343,6 +360,7 @@ describe('ReactFlight', () => {
343
360
expect ( getDebugInfo ( promise ) ) . toEqual (
344
361
__DEV__
345
362
? [
363
+ { time : 11 } ,
346
364
{
347
365
name : 'Greeting' ,
348
366
env : 'Server' ,
@@ -2659,6 +2677,7 @@ describe('ReactFlight', () => {
2659
2677
) ;
2660
2678
} ) ;
2661
2679
2680
+ // @gate enableComponentPerformanceTrack
2662
2681
it ( 'preserves debug info for server-to-server pass through' , async ( ) => {
2663
2682
function ThirdPartyLazyComponent ( ) {
2664
2683
return < span > !</ span > ;
@@ -2705,6 +2724,7 @@ describe('ReactFlight', () => {
2705
2724
expect ( getDebugInfo ( promise ) ) . toEqual (
2706
2725
__DEV__
2707
2726
? [
2727
+ { time : 15 } ,
2708
2728
{
2709
2729
name : 'ServerComponent' ,
2710
2730
env : 'Server' ,
@@ -2726,6 +2746,7 @@ describe('ReactFlight', () => {
2726
2746
expect ( getDebugInfo ( thirdPartyChildren [ 0 ] ) ) . toEqual (
2727
2747
__DEV__
2728
2748
? [
2749
+ { time : 26 } ,
2729
2750
{
2730
2751
name : 'ThirdPartyComponent' ,
2731
2752
env : 'third-party' ,
@@ -2736,12 +2757,14 @@ describe('ReactFlight', () => {
2736
2757
: undefined ,
2737
2758
props : { } ,
2738
2759
} ,
2760
+ { time : 17 } ,
2739
2761
]
2740
2762
: undefined ,
2741
2763
) ;
2742
2764
expect ( getDebugInfo ( thirdPartyChildren [ 1 ] ) ) . toEqual (
2743
2765
__DEV__
2744
2766
? [
2767
+ { time : 27 } ,
2745
2768
{
2746
2769
name : 'ThirdPartyLazyComponent' ,
2747
2770
env : 'third-party' ,
@@ -2758,6 +2781,7 @@ describe('ReactFlight', () => {
2758
2781
expect ( getDebugInfo ( thirdPartyChildren [ 2 ] ) ) . toEqual (
2759
2782
__DEV__
2760
2783
? [
2784
+ { time : 25 } ,
2761
2785
{
2762
2786
name : 'ThirdPartyFragmentComponent' ,
2763
2787
env : 'third-party' ,
@@ -2833,6 +2857,7 @@ describe('ReactFlight', () => {
2833
2857
expect ( getDebugInfo ( promise ) ) . toEqual (
2834
2858
__DEV__
2835
2859
? [
2860
+ { time : 13 } ,
2836
2861
{
2837
2862
name : 'ServerComponent' ,
2838
2863
env : 'Server' ,
@@ -2853,6 +2878,7 @@ describe('ReactFlight', () => {
2853
2878
expect ( getDebugInfo ( thirdPartyFragment ) ) . toEqual (
2854
2879
__DEV__
2855
2880
? [
2881
+ { time : 14 } ,
2856
2882
{
2857
2883
name : 'Keyed' ,
2858
2884
env : 'Server' ,
@@ -2872,6 +2898,7 @@ describe('ReactFlight', () => {
2872
2898
expect ( getDebugInfo ( thirdPartyFragment . props . children ) ) . toEqual (
2873
2899
__DEV__
2874
2900
? [
2901
+ { time : 23 } ,
2875
2902
{
2876
2903
name : 'ThirdPartyAsyncIterableComponent' ,
2877
2904
env : 'third-party' ,
@@ -3017,6 +3044,7 @@ describe('ReactFlight', () => {
3017
3044
}
3018
3045
} ) ;
3019
3046
3047
+ // @gate enableComponentPerformanceTrack
3020
3048
it ( 'can change the environment name inside a component' , async ( ) => {
3021
3049
let env = 'A' ;
3022
3050
function Component ( props ) {
@@ -3041,6 +3069,7 @@ describe('ReactFlight', () => {
3041
3069
expect ( getDebugInfo ( greeting ) ) . toEqual (
3042
3070
__DEV__
3043
3071
? [
3072
+ { time : 11 } ,
3044
3073
{
3045
3074
name : 'Component' ,
3046
3075
env : 'A' ,
@@ -3205,6 +3234,7 @@ describe('ReactFlight', () => {
3205
3234
) ;
3206
3235
} ) ;
3207
3236
3237
+ // @gate enableComponentPerformanceTrack
3208
3238
it ( 'uses the server component debug info as the element owner in DEV' , async ( ) => {
3209
3239
function Container ( { children} ) {
3210
3240
return children ;
@@ -3244,7 +3274,9 @@ describe('ReactFlight', () => {
3244
3274
} ,
3245
3275
} ;
3246
3276
expect ( getDebugInfo ( greeting ) ) . toEqual ( [
3277
+ { time : 11 } ,
3247
3278
greetInfo ,
3279
+ { time : 12 } ,
3248
3280
{
3249
3281
name : 'Container' ,
3250
3282
env : 'Server' ,
@@ -3265,7 +3297,7 @@ describe('ReactFlight', () => {
3265
3297
] ) ;
3266
3298
// The owner that created the span was the outer server component.
3267
3299
// We expect the debug info to be referentially equal to the owner.
3268
- expect ( greeting . _owner ) . toBe ( greeting . _debugInfo [ 0 ] ) ;
3300
+ expect ( greeting . _owner ) . toBe ( greeting . _debugInfo [ 1 ] ) ;
3269
3301
} else {
3270
3302
expect ( greeting . _debugInfo ) . toBe ( undefined ) ;
3271
3303
expect ( greeting . _owner ) . toBe ( undefined ) ;
@@ -3531,7 +3563,7 @@ describe('ReactFlight', () => {
3531
3563
expect ( caughtError . digest ) . toBe ( 'digest("my-error")' ) ;
3532
3564
} ) ;
3533
3565
3534
- // @gate __DEV__
3566
+ // @gate __DEV__ && enableComponentPerformanceTrack
3535
3567
it ( 'can render deep but cut off JSX in debug info' , async ( ) => {
3536
3568
function createDeepJSX ( n ) {
3537
3569
if ( n <= 0 ) {
@@ -3555,7 +3587,7 @@ describe('ReactFlight', () => {
3555
3587
await act ( async ( ) => {
3556
3588
const rootModel = await ReactNoopFlightClient . read ( transport ) ;
3557
3589
const root = rootModel . root ;
3558
- const children = root . _debugInfo [ 0 ] . props . children ;
3590
+ const children = root . _debugInfo [ 1 ] . props . children ;
3559
3591
expect ( children . type ) . toBe ( 'div' ) ;
3560
3592
expect ( children . props . children . type ) . toBe ( 'div' ) ;
3561
3593
ReactNoop . render ( root ) ;
@@ -3564,7 +3596,7 @@ describe('ReactFlight', () => {
3564
3596
expect ( ReactNoop ) . toMatchRenderedOutput ( < div > not using props</ div > ) ;
3565
3597
} ) ;
3566
3598
3567
- // @gate __DEV__
3599
+ // @gate __DEV__ && enableComponentPerformanceTrack
3568
3600
it ( 'can render deep but cut off Map/Set in debug info' , async ( ) => {
3569
3601
function createDeepMap ( n ) {
3570
3602
if ( n <= 0 ) {
@@ -3603,8 +3635,8 @@ describe('ReactFlight', () => {
3603
3635
3604
3636
await act ( async ( ) => {
3605
3637
const rootModel = await ReactNoopFlightClient . read ( transport ) ;
3606
- const set = rootModel . set . _debugInfo [ 0 ] . props . set ;
3607
- const map = rootModel . map . _debugInfo [ 0 ] . props . map ;
3638
+ const set = rootModel . set . _debugInfo [ 1 ] . props . set ;
3639
+ const map = rootModel . map . _debugInfo [ 1 ] . props . map ;
3608
3640
expect ( set instanceof Set ) . toBe ( true ) ;
3609
3641
expect ( set . size ) . toBe ( 1 ) ;
3610
3642
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
0 commit comments