@@ -13,6 +13,7 @@ import type {
1313 ReactComponentInfo ,
1414 ReactEnvironmentInfo ,
1515 ReactAsyncInfo ,
16+ ReactIOInfo ,
1617 ReactTimeInfo ,
1718 ReactStackTrace ,
1819 ReactFunctionLocation ,
@@ -47,6 +48,7 @@ import {
4748 enablePostpone ,
4849 enableProfilerTimer ,
4950 enableComponentPerformanceTrack ,
51+ enableAsyncDebugInfo ,
5052} from 'shared/ReactFeatureFlags' ;
5153
5254import {
@@ -672,6 +674,14 @@ function nullRefGetter() {
672674 }
673675}
674676
677+ function getIOInfoTaskName ( ioInfo : ReactIOInfo ) : string {
678+ return ''; // TODO
679+ }
680+
681+ function getAsyncInfoTaskName(asyncInfo: ReactAsyncInfo): string {
682+ return 'await '; // We could be smarter about this and give it a name like `then` or `Promise.all`.
683+ }
684+
675685function getServerComponentTaskName(componentInfo: ReactComponentInfo): string {
676686 return '<' + ( componentInfo . name || '...' ) + '>' ;
677687}
@@ -2447,30 +2457,27 @@ function getRootTask(
24472457
24482458function initializeFakeTask(
24492459 response: Response,
2450- debugInfo: ReactComponentInfo | ReactAsyncInfo,
2460+ debugInfo: ReactComponentInfo | ReactAsyncInfo | ReactIOInfo ,
24512461 childEnvironmentName: string,
24522462): null | ConsoleTask {
24532463 if ( ! supportsCreateTask ) {
24542464 return null ;
24552465 }
2456- const componentInfo: ReactComponentInfo = (debugInfo: any); // Refined
24572466 if (debugInfo.stack == null) {
24582467 // If this is an error, we should've really already initialized the task.
24592468 // If it's null, we can't initialize a task.
24602469 return null ;
24612470 }
24622471 const stack = debugInfo.stack;
24632472 const env: string =
2464- componentInfo.env == null
2465- ? response._rootEnvironmentName
2466- : componentInfo.env;
2473+ debugInfo.env == null ? response._rootEnvironmentName : debugInfo.env;
24672474 if (env !== childEnvironmentName) {
24682475 // This is the boundary between two environments so we'll annotate the task name.
24692476 // That is unusual so we don't cache it.
24702477 const ownerTask =
2471- componentInfo . owner == null
2478+ debugInfo . owner == null
24722479 ? null
2473- : initializeFakeTask ( response , componentInfo . owner , env ) ;
2480+ : initializeFakeTask ( response , debugInfo . owner , env ) ;
24742481 return buildFakeTask (
24752482 response ,
24762483 ownerTask ,
@@ -2479,20 +2486,27 @@ function initializeFakeTask(
24792486 env ,
24802487 ) ;
24812488 } else {
2482- const cachedEntry = componentInfo . debugTask ;
2489+ const cachedEntry = debugInfo . debugTask ;
24832490 if ( cachedEntry !== undefined ) {
24842491 return cachedEntry ;
24852492 }
24862493 const ownerTask =
2487- componentInfo . owner == null
2494+ debugInfo . owner == null
24882495 ? null
2489- : initializeFakeTask ( response , componentInfo . owner , env ) ;
2496+ : initializeFakeTask ( response , debugInfo . owner , env ) ;
2497+ // Some unfortunate pattern matching to refine the type.
2498+ const taskName =
2499+ debugInfo . key !== undefined
2500+ ? getServerComponentTaskName ( ( ( debugInfo : any ) : ReactComponentInfo ) )
2501+ : debugInfo . name !== undefined
2502+ ? getIOInfoTaskName ( ( ( debugInfo : any ) : ReactIOInfo ) )
2503+ : getAsyncInfoTaskName ( ( ( debugInfo : any ) : ReactAsyncInfo ) ) ;
24902504 // $FlowFixMe[cannot-write]: We consider this part of initialization.
2491- return ( componentInfo . debugTask = buildFakeTask (
2505+ return ( debugInfo . debugTask = buildFakeTask (
24922506 response ,
24932507 ownerTask ,
24942508 stack ,
2495- getServerComponentTaskName ( componentInfo ) ,
2509+ taskName ,
24962510 env ,
24972511 ) ) ;
24982512 }
@@ -2555,7 +2569,7 @@ function fakeJSXCallSite() {
25552569
25562570function initializeFakeStack(
25572571 response: Response,
2558- debugInfo: ReactComponentInfo | ReactAsyncInfo,
2572+ debugInfo: ReactComponentInfo | ReactAsyncInfo | ReactIOInfo ,
25592573): void {
25602574 const cachedEntry = debugInfo . debugStack ;
25612575 if ( cachedEntry !== undefined ) {
@@ -2740,6 +2754,54 @@ function resolveConsoleEntry(
27402754 );
27412755}
27422756
2757+ function initializeIOInfo ( response : Response , ioInfo : ReactIOInfo ) : void {
2758+ const env =
2759+ // TODO: Pass env through I/O info.
2760+ // ioInfo.env !== undefined ? ioInfo.env :
2761+ response . _rootEnvironmentName ;
2762+ if ( ioInfo . stack !== undefined ) {
2763+ initializeFakeTask ( response , ioInfo , env ) ;
2764+ initializeFakeStack ( response , ioInfo ) ;
2765+ }
2766+ // TODO: Initialize owner.
2767+ // Adjust the time to the current environment's time space.
2768+ // $FlowFixMe[cannot-write]
2769+ ioInfo.start += response._timeOrigin;
2770+ // $FlowFixMe[cannot-write]
2771+ ioInfo.end += response._timeOrigin;
2772+ }
2773+
2774+ function resolveIOInfo (
2775+ response : Response ,
2776+ id : number ,
2777+ model : UninitializedModel ,
2778+ ) : void {
2779+ const chunks = response . _chunks ;
2780+ let chunk = chunks . get ( id ) ;
2781+ if ( ! chunk ) {
2782+ chunk = createResolvedModelChunk ( response , model ) ;
2783+ chunks . set ( id , chunk ) ;
2784+ initializeModelChunk ( chunk ) ;
2785+ } else {
2786+ resolveModelChunk ( chunk , model ) ;
2787+ if ( chunk . status === RESOLVED_MODEL ) {
2788+ initializeModelChunk ( chunk ) ;
2789+ }
2790+ }
2791+ if ( chunk . status === INITIALIZED ) {
2792+ initializeIOInfo ( response , chunk . value ) ;
2793+ } else {
2794+ chunk . then (
2795+ v => {
2796+ initializeIOInfo ( response , v ) ;
2797+ } ,
2798+ e => {
2799+ // Ignore debug info errors for now. Unnecessary noise.
2800+ } ,
2801+ ) ;
2802+ }
2803+ }
2804+
27432805function mergeBuffer (
27442806 buffer : Array < Uint8Array > ,
27452807 lastChunk : Uint8Array ,
@@ -2844,7 +2906,7 @@ function flushComponentPerformance(
28442906
28452907 // First find the start time of the first component to know if it was running
28462908 // in parallel with the previous.
2847- const debugInfo = root . _debugInfo ;
2909+ const debugInfo = __DEV__ && root . _debugInfo ;
28482910 if ( debugInfo ) {
28492911 for ( let i = 1 ; i < debugInfo . length ; i ++ ) {
28502912 const info = debugInfo [ i ] ;
@@ -3101,6 +3163,17 @@ function processFullStringRow(
31013163 }
31023164 // Fallthrough to share the error with Console entries.
31033165 }
3166+ case 74 /* "J" */ : {
3167+ if (
3168+ enableProfilerTimer &&
3169+ enableComponentPerformanceTrack &&
3170+ enableAsyncDebugInfo
3171+ ) {
3172+ resolveIOInfo ( response , id , row ) ;
3173+ return ;
3174+ }
3175+ // Fallthrough to share the error with Console entries.
3176+ }
31043177 case 87 /* "W" */ : {
31053178 if ( __DEV__ ) {
31063179 resolveConsoleEntry ( response , row ) ;
0 commit comments