@@ -351,6 +351,7 @@ type Response = {
351351 _closedReason : mixed ,
352352 _tempRefs : void | TemporaryReferenceSet , // the set temporary references can be resolved from
353353 _timeOrigin : number , // Profiling-only
354+ _pendingInitialRender : null | TimeoutID , // Profiling-only,
354355 _pendingChunks : number , // DEV-only
355356 _weakResponse : WeakResponse , // DEV-only
356357 _debugRootOwner ?: null | ReactComponentInfo , // DEV-only
@@ -444,8 +445,13 @@ export function getRoot<T>(weakResponse: WeakResponse): Thenable<T> {
444445function createPendingChunk< T > (response: Response): PendingChunk< T > {
445446 if ( __DEV__ ) {
446447 // Retain a strong reference to the Response while we wait for the result.
447- response . _pendingChunks ++ ;
448- response . _weakResponse . response = response ;
448+ if ( response . _pendingChunks ++ === 0 ) {
449+ response . _weakResponse . response = response ;
450+ if ( response . _pendingInitialRender !== null ) {
451+ clearTimeout ( response . _pendingInitialRender ) ;
452+ response . _pendingInitialRender = null ;
453+ }
454+ }
449455 }
450456 // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
451457 return new ReactPromise ( PENDING , null , null ) ;
@@ -457,6 +463,14 @@ function releasePendingChunk(response: Response, chunk: SomeChunk<any>): void {
457463 // We're no longer waiting for any more chunks. We can release the strong reference
458464 // to the response. We'll regain it if we ask for any more data later on.
459465 response . _weakResponse . response = null ;
466+ // Wait a short period to see if any more chunks get asked for. E.g. by a React render.
467+ // These chunks might discover more pending chunks.
468+ // If we don't ask for more then we assume that those chunks weren't blocking initial
469+ // render and are excluded from the performance track.
470+ response . _pendingInitialRender = setTimeout (
471+ flushInitialRenderPerformance . bind ( null , response ) ,
472+ 100 ,
473+ ) ;
460474 }
461475 }
462476}
@@ -868,18 +882,6 @@ export function reportGlobalError(
868882 response . _debugChannel = undefined ;
869883 }
870884 }
871- if ( enableProfilerTimer && enableComponentPerformanceTrack ) {
872- if ( response . _replayConsole ) {
873- markAllTracksInOrder ( ) ;
874- flushComponentPerformance (
875- response ,
876- getChunk ( response , 0 ) ,
877- 0 ,
878- - Infinity ,
879- - Infinity ,
880- ) ;
881- }
882- }
883885}
884886
885887function nullRefGetter ( ) {
@@ -2105,6 +2107,7 @@ function ResponseInstance(
21052107 this . _tempRefs = temporaryReferences ;
21062108 if ( enableProfilerTimer && enableComponentPerformanceTrack ) {
21072109 this . _timeOrigin = 0 ;
2110+ this . _pendingInitialRender = null ;
21082111 }
21092112 if ( __DEV__ ) {
21102113 this . _pendingChunks = 0 ;
@@ -3703,6 +3706,20 @@ function flushComponentPerformance(
37033706 return result ;
37043707}
37053708
3709+ function flushInitialRenderPerformance ( response : Response ) : void {
3710+ if (
3711+ enableProfilerTimer &&
3712+ enableComponentPerformanceTrack &&
3713+ response . _replayConsole
3714+ ) {
3715+ const rootChunk = getChunk ( response , 0 ) ;
3716+ if ( isArray ( rootChunk . _children ) ) {
3717+ markAllTracksInOrder ( ) ;
3718+ flushComponentPerformance ( response , rootChunk , 0 , - Infinity , - Infinity ) ;
3719+ }
3720+ }
3721+ }
3722+
37063723function processFullBinaryRow (
37073724 response : Response ,
37083725 id : number ,
0 commit comments