@@ -1341,12 +1341,7 @@ function renderFunctionComponent<Props>(
1341
1341
1342
1342
// Track when we started rendering this component.
1343
1343
if ( enableProfilerTimer && enableComponentPerformanceTrack ) {
1344
- task . timed = true ;
1345
- emitTimingChunk (
1346
- request ,
1347
- componentDebugID ,
1348
- ( task . time = performance . now ( ) ) ,
1349
- ) ;
1344
+ advanceTaskTime ( request , task , performance . now ( ) ) ;
1350
1345
}
1351
1346
1352
1347
emitDebugChunk ( request , componentDebugID , componentDebugInfo ) ;
@@ -2008,7 +2003,7 @@ function visitAsyncNode(
2008
2003
// We log the environment at the time when the last promise pigned ping which may
2009
2004
// be later than what the environment was when we actually started awaiting.
2010
2005
const env = ( 0 , request . environmentName ) ( ) ;
2011
- emitTimingChunk ( request , task . id , startTime ) ;
2006
+ advanceTaskTime ( request , task , startTime ) ;
2012
2007
// Then emit a reference to us awaiting it in the current task.
2013
2008
request . pendingChunks ++ ;
2014
2009
emitDebugChunk ( request , task . id , {
@@ -2017,7 +2012,7 @@ function visitAsyncNode(
2017
2012
owner : node . owner ,
2018
2013
stack : stack ,
2019
2014
} ) ;
2020
- emitTimingChunk ( request , task . id , ( task . time = endTime ) ) ;
2015
+ advanceTaskTime ( request , task , endTime ) ;
2021
2016
}
2022
2017
}
2023
2018
}
@@ -2070,17 +2065,11 @@ function emitAsyncSequence(
2070
2065
const env = ( 0 , request . environmentName ) ( ) ;
2071
2066
// If we don't have any thing awaited, the time we started awaiting was internal
2072
2067
// when we yielded after rendering. The current task time is basically that.
2073
- const awaitStartTime = task . time ;
2074
- // If the end time finished before we started, it could've been a cached thing so
2075
- // we clamp it to the task time. Effectively leading to a zero-time await.
2076
- const awaitEndTime =
2077
- awaitedNode . end < task . time ? task . time : awaitedNode . end ;
2078
- emitTimingChunk ( request , task . id , awaitStartTime ) ;
2079
2068
emitDebugChunk ( request , task . id , {
2080
2069
awaited : ( ( awaitedNode : any ) : ReactIOInfo ) , // This is deduped by this reference.
2081
2070
env : env ,
2082
2071
} ) ;
2083
- emitTimingChunk ( request , task . id , ( task . time = awaitEndTime ) ) ;
2072
+ advanceTaskTime ( request , task , awaitedNode . end ) ;
2084
2073
}
2085
2074
}
2086
2075
@@ -4294,19 +4283,13 @@ function forwardDebugInfo(
4294
4283
debugInfo: ReactDebugInfo,
4295
4284
) {
4296
4285
const id = task . id ;
4297
- const minimumTime =
4298
- enableProfilerTimer && enableComponentPerformanceTrack ? task . time : 0 ;
4299
4286
for ( let i = 0 ; i < debugInfo . length ; i ++ ) {
4300
4287
const info = debugInfo [ i ] ;
4301
4288
if ( typeof info . time === 'number' ) {
4302
4289
// When forwarding time we need to ensure to convert it to the time space of the payload.
4303
4290
// We clamp the time to the starting render of the current component. It's as if it took
4304
4291
// no time to render and await if we reuse cached content.
4305
- emitTimingChunk (
4306
- request ,
4307
- id ,
4308
- info . time < minimumTime ? minimumTime : info . time ,
4309
- ) ;
4292
+ advanceTaskTime ( request , task , info . time ) ;
4310
4293
} else {
4311
4294
if ( typeof info . name === 'string' ) {
4312
4295
// We outline this model eagerly so that we can refer to by reference as an owner.
@@ -4383,6 +4366,24 @@ function emitTimingChunk(
4383
4366
request . completedRegularChunks . push ( processedChunk ) ;
4384
4367
}
4385
4368
4369
+ function advanceTaskTime (
4370
+ request : Request ,
4371
+ task : Task ,
4372
+ timestamp : number ,
4373
+ ) : void {
4374
+ if ( ! enableProfilerTimer || ! enableComponentPerformanceTrack ) {
4375
+ return ;
4376
+ }
4377
+ // Emits a timing chunk, if the new timestamp is higher than the previous timestamp of this task.
4378
+ // If it wasn't timed before, e.g. an outlined object, we need to emit the first timestamp and
4379
+ // it is now timed.
4380
+ if ( ! task . timed || timestamp > task . time ) {
4381
+ emitTimingChunk ( request , task . id , timestamp ) ;
4382
+ task . time = timestamp ;
4383
+ }
4384
+ task . timed = true ;
4385
+ }
4386
+
4386
4387
function emitChunk (
4387
4388
request : Request ,
4388
4389
task : Task ,
@@ -4474,7 +4475,7 @@ function emitChunk(
4474
4475
function erroredTask ( request : Request , task : Task , error : mixed ) : void {
4475
4476
if ( enableProfilerTimer && enableComponentPerformanceTrack ) {
4476
4477
if ( task . timed ) {
4477
- emitTimingChunk ( request , task . id , ( task . time = performance . now ( ) ) ) ;
4478
+ advanceTaskTime ( request , task , performance . now ( ) ) ;
4478
4479
}
4479
4480
}
4480
4481
task . status = ERRORED ;
@@ -4557,7 +4558,7 @@ function retryTask(request: Request, task: Task): void {
4557
4558
// We've finished rendering. Log the end time.
4558
4559
if ( enableProfilerTimer && enableComponentPerformanceTrack ) {
4559
4560
if ( task . timed ) {
4560
- emitTimingChunk ( request , task . id , ( task . time = performance . now ( ) ) ) ;
4561
+ advanceTaskTime ( request , task , performance . now ( ) ) ;
4561
4562
}
4562
4563
}
4563
4564
@@ -4684,7 +4685,7 @@ function abortTask(task: Task, request: Request, errorId: number): void {
4684
4685
// Track when we aborted this task as its end time.
4685
4686
if ( enableProfilerTimer && enableComponentPerformanceTrack ) {
4686
4687
if ( task . timed ) {
4687
- emitTimingChunk ( request , task . id , ( task . time = performance . now ( ) ) ) ;
4688
+ advanceTaskTime ( request , task , performance . now ( ) ) ;
4688
4689
}
4689
4690
}
4690
4691
// Instead of emitting an error per task.id, we emit a model that only
0 commit comments