@@ -367,6 +367,7 @@ type Response = {
367367_debugRootStack ?: null | Error , // DEV-only
368368_debugRootTask ?: null | ConsoleTask , // DEV-only
369369_debugStartTime : number , // DEV-only
370+ _debugIOStarted : boolean , // DEV-only
370371_debugFindSourceMapURL ?: void | FindSourceMapURLCallback , // DEV-only
371372_debugChannel ?: void | DebugChannel , // DEV-only
372373_blockedConsole ?: null | SomeChunk < ConsoleEntry > , // DEV-only
@@ -500,7 +501,7 @@ function createErrorChunk<T>(
500501}
501502
502503function moveDebugInfoFromChunkToInnerValue< T > (
503- chunk: InitializedChunk< T > ,
504+ chunk: InitializedChunk< T > | InitializedStreamChunk < any > ,
504505 value: T,
505506): void {
506507// Remove the debug info from the initialized chunk, and add it to the inner
@@ -1569,6 +1570,10 @@ function fulfillReference(
15691570initializedChunk . reason = handler . reason ; // Used by streaming chunks
15701571if ( resolveListeners !== null ) {
15711572wakeChunk ( resolveListeners , handler . value , initializedChunk ) ;
1573+ } else {
1574+ if ( __DEV__ ) {
1575+ moveDebugInfoFromChunkToInnerValue ( initializedChunk , handler . value ) ;
1576+ }
15721577}
15731578}
15741579}
@@ -1818,6 +1823,10 @@ function loadServerReference<A: Iterable<any>, T>(
18181823initializedChunk . value = handler . value ;
18191824if ( resolveListeners !== null ) {
18201825wakeChunk ( resolveListeners , handler . value , initializedChunk ) ;
1826+ } else {
1827+ if ( __DEV__ ) {
1828+ moveDebugInfoFromChunkToInnerValue ( initializedChunk , handler . value ) ;
1829+ }
18211830}
18221831}
18231832}
@@ -2536,6 +2545,10 @@ function missingCall() {
25362545) ;
25372546}
25382547
2548+ function markIOStarted ( this : Response ) {
2549+ this . _debugIOStarted = true ;
2550+ }
2551+
25392552function ResponseInstance (
25402553this : $FlowFixMe ,
25412554bundlerConfig : ServerConsumerModuleMap ,
@@ -2609,6 +2622,10 @@ function ResponseInstance(
26092622// where as if you use createFromReadableStream from the body of the fetch
26102623// then the start time is when the headers resolved.
26112624this . _debugStartTime = performance . now ( ) ;
2625+ this . _debugIOStarted = false ;
2626+ // We consider everything before the first setTimeout task to be cached data
2627+ // and is not considered I/O required to load the stream.
2628+ setTimeout ( markIOStarted . bind ( this ) , 0 ) ;
26122629}
26132630this . _debugFindSourceMapURL = findSourceMapURL ;
26142631this . _debugChannel = debugChannel ;
@@ -2762,7 +2779,7 @@ function incrementChunkDebugInfo(
27622779}
27632780}
27642781
2765- function addDebugInfo ( chunk : SomeChunk < any > , debugInfo : ReactDebugInfo ) : void {
2782+ function addAsyncInfo ( chunk : SomeChunk < any > , asyncInfo : ReactAsyncInfo ) : void {
27662783const value = resolveLazy ( chunk . value ) ;
27672784if (
27682785typeof value === 'object' &&
@@ -2774,34 +2791,39 @@ function addDebugInfo(chunk: SomeChunk<any>, debugInfo: ReactDebugInfo): void {
27742791) {
27752792if ( isArray ( value . _debugInfo ) ) {
27762793// $FlowFixMe[method-unbinding]
2777- value . _debugInfo . push . apply ( value . _debugInfo , debugInfo ) ;
2794+ value . _debugInfo . push ( asyncInfo ) ;
27782795} else {
27792796Object . defineProperty ( ( value : any ) , '_debugInfo' , {
27802797configurable : false ,
27812798enumerable : false ,
27822799writable : true ,
2783- value : debugInfo ,
2800+ value : [ asyncInfo ] ,
27842801} ) ;
27852802}
27862803} else {
27872804// $FlowFixMe[method-unbinding]
2788- chunk . _debugInfo . push . apply ( chunk . _debugInfo , debugInfo ) ;
2805+ chunk . _debugInfo . push ( asyncInfo ) ;
27892806}
27902807}
27912808
27922809function resolveChunkDebugInfo (
2810+ response : Response ,
27932811streamState : StreamState ,
27942812chunk : SomeChunk < any > ,
27952813) : void {
27962814if ( __DEV__ && enableAsyncDebugInfo ) {
2797- // Add the currently resolving chunk's debug info representing the stream
2798- // to the Promise that was waiting on the stream, or its underlying value.
2799- const debugInfo : ReactDebugInfo = [ { awaited : streamState . _debugInfo } ] ;
2800- if ( chunk . status === PENDING || chunk . status === BLOCKED ) {
2801- const boundAddDebugInfo = addDebugInfo . bind ( null , chunk , debugInfo ) ;
2802- chunk . then ( boundAddDebugInfo , boundAddDebugInfo ) ;
2803- } else {
2804- addDebugInfo ( chunk , debugInfo ) ;
2815+ // Only include stream information after a macrotask. Any chunk processed
2816+ // before that is considered cached data.
2817+ if ( response . _debugIOStarted ) {
2818+ // Add the currently resolving chunk's debug info representing the stream
2819+ // to the Promise that was waiting on the stream, or its underlying value.
2820+ const asyncInfo : ReactAsyncInfo = { awaited : streamState . _debugInfo } ;
2821+ if ( chunk . status === PENDING || chunk . status === BLOCKED ) {
2822+ const boundAddAsyncInfo = addAsyncInfo . bind ( null , chunk , asyncInfo ) ;
2823+ chunk . then ( boundAddAsyncInfo , boundAddAsyncInfo ) ;
2824+ } else {
2825+ addAsyncInfo ( chunk , asyncInfo ) ;
2826+ }
28052827}
28062828}
28072829}
@@ -2837,12 +2859,12 @@ function resolveModel(
28372859model ,
28382860) ;
28392861if ( __DEV__ ) {
2840- resolveChunkDebugInfo ( streamState , newChunk ) ;
2862+ resolveChunkDebugInfo ( response , streamState , newChunk ) ;
28412863}
28422864chunks . set ( id , newChunk ) ;
28432865} else {
28442866if ( __DEV__ ) {
2845- resolveChunkDebugInfo ( streamState , chunk ) ;
2867+ resolveChunkDebugInfo ( response , streamState , chunk ) ;
28462868}
28472869resolveModelChunk ( response , chunk , model ) ;
28482870}
@@ -2869,7 +2891,7 @@ function resolveText(
28692891}
28702892const newChunk = createInitializedTextChunk ( response , text ) ;
28712893if ( __DEV__ ) {
2872- resolveChunkDebugInfo ( streamState , newChunk ) ;
2894+ resolveChunkDebugInfo ( response , streamState , newChunk ) ;
28732895}
28742896chunks . set ( id , newChunk ) ;
28752897}
@@ -2895,7 +2917,7 @@ function resolveBuffer(
28952917}
28962918const newChunk = createInitializedBufferChunk ( response , buffer ) ;
28972919if ( __DEV__ ) {
2898- resolveChunkDebugInfo ( streamState , newChunk ) ;
2920+ resolveChunkDebugInfo ( response , streamState , newChunk ) ;
28992921}
29002922chunks . set ( id , newChunk ) ;
29012923}
@@ -2942,7 +2964,7 @@ function resolveModule(
29422964blockedChunk . status = BLOCKED ;
29432965}
29442966if ( __DEV__ ) {
2945- resolveChunkDebugInfo ( streamState , blockedChunk ) ;
2967+ resolveChunkDebugInfo ( response , streamState , blockedChunk ) ;
29462968}
29472969promise . then (
29482970( ) => resolveModuleChunk ( response , blockedChunk , clientReference ) ,
@@ -2952,12 +2974,12 @@ function resolveModule(
29522974if ( ! chunk ) {
29532975const newChunk = createResolvedModuleChunk ( response , clientReference ) ;
29542976if ( __DEV__ ) {
2955- resolveChunkDebugInfo ( streamState , newChunk ) ;
2977+ resolveChunkDebugInfo ( response , streamState , newChunk ) ;
29562978}
29572979chunks . set ( id , newChunk ) ;
29582980} else {
29592981if ( __DEV__ ) {
2960- resolveChunkDebugInfo ( streamState , chunk ) ;
2982+ resolveChunkDebugInfo ( response , streamState , chunk ) ;
29612983}
29622984// This can't actually happen because we don't have any forward
29632985// references to modules.
@@ -2978,13 +3000,13 @@ function resolveStream<T: ReadableStream | $AsyncIterable<any, any, void>>(
29783000if ( ! chunk ) {
29793001const newChunk = createInitializedStreamChunk ( response , stream , controller ) ;
29803002if ( __DEV__ ) {
2981- resolveChunkDebugInfo ( streamState , newChunk ) ;
3003+ resolveChunkDebugInfo ( response , streamState , newChunk ) ;
29823004}
29833005chunks . set ( id , newChunk ) ;
29843006return ;
29853007}
29863008if ( __DEV__ ) {
2987- resolveChunkDebugInfo ( streamState , chunk ) ;
3009+ resolveChunkDebugInfo ( response , streamState , chunk ) ;
29883010}
29893011if ( chunk . status !== PENDING ) {
29903012// We already resolved. We didn't expect to see this.
@@ -3034,6 +3056,10 @@ function resolveStream<T: ReadableStream | $AsyncIterable<any, any, void>>(
30343056 resolvedChunk.reason = controller;
30353057 if (resolveListeners !== null) {
30363058wakeChunk ( resolveListeners , chunk . value , ( chunk : any ) ) ;
3059+ } else {
3060+ if ( __DEV__ ) {
3061+ moveDebugInfoFromChunkToInnerValue ( resolvedChunk , stream ) ;
3062+ }
30373063}
30383064}
30393065
@@ -3433,12 +3459,12 @@ function resolvePostponeDev(
34333459postponeInstance ,
34343460) ;
34353461if ( __DEV__ ) {
3436- resolveChunkDebugInfo ( streamState , newChunk ) ;
3462+ resolveChunkDebugInfo ( response , streamState , newChunk ) ;
34373463}
34383464chunks . set ( id , newChunk ) ;
34393465} else {
34403466if ( __DEV__ ) {
3441- resolveChunkDebugInfo ( streamState , chunk ) ;
3467+ resolveChunkDebugInfo ( response , streamState , chunk ) ;
34423468}
34433469triggerErrorOnChunk ( response , chunk , postponeInstance ) ;
34443470}
@@ -3467,12 +3493,12 @@ function resolveErrorModel(
34673493 errorWithDigest,
34683494 );
34693495 if (__DEV__) {
3470- resolveChunkDebugInfo ( streamState , newChunk ) ;
3496+ resolveChunkDebugInfo ( response , streamState , newChunk ) ;
34713497}
34723498 chunks.set(id, newChunk);
34733499} else {
34743500if ( __DEV__ ) {
3475- resolveChunkDebugInfo ( streamState , chunk ) ;
3501+ resolveChunkDebugInfo ( response , streamState , chunk ) ;
34763502}
34773503 triggerErrorOnChunk(response, chunk, errorWithDigest);
34783504}
0 commit comments