@@ -13,6 +13,7 @@ import type {
13
13
ReactComponentInfo ,
14
14
ReactEnvironmentInfo ,
15
15
ReactAsyncInfo ,
16
+ ReactIOInfo ,
16
17
ReactTimeInfo ,
17
18
ReactStackTrace ,
18
19
ReactFunctionLocation ,
@@ -47,6 +48,7 @@ import {
47
48
enablePostpone ,
48
49
enableProfilerTimer ,
49
50
enableComponentPerformanceTrack ,
51
+ enableAsyncDebugInfo ,
50
52
} from 'shared/ReactFeatureFlags' ;
51
53
52
54
import {
@@ -672,6 +674,14 @@ function nullRefGetter() {
672
674
}
673
675
}
674
676
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
+
675
685
function getServerComponentTaskName(componentInfo: ReactComponentInfo): string {
676
686
return '<' + ( componentInfo . name || '...' ) + '>' ;
677
687
}
@@ -2447,30 +2457,27 @@ function getRootTask(
2447
2457
2448
2458
function initializeFakeTask(
2449
2459
response: Response,
2450
- debugInfo: ReactComponentInfo | ReactAsyncInfo,
2460
+ debugInfo: ReactComponentInfo | ReactAsyncInfo | ReactIOInfo ,
2451
2461
childEnvironmentName: string,
2452
2462
): null | ConsoleTask {
2453
2463
if ( ! supportsCreateTask ) {
2454
2464
return null ;
2455
2465
}
2456
- const componentInfo: ReactComponentInfo = (debugInfo: any); // Refined
2457
2466
if (debugInfo.stack == null) {
2458
2467
// If this is an error, we should've really already initialized the task.
2459
2468
// If it's null, we can't initialize a task.
2460
2469
return null ;
2461
2470
}
2462
2471
const stack = debugInfo.stack;
2463
2472
const env: string =
2464
- componentInfo.env == null
2465
- ? response._rootEnvironmentName
2466
- : componentInfo.env;
2473
+ debugInfo.env == null ? response._rootEnvironmentName : debugInfo.env;
2467
2474
if (env !== childEnvironmentName) {
2468
2475
// This is the boundary between two environments so we'll annotate the task name.
2469
2476
// That is unusual so we don't cache it.
2470
2477
const ownerTask =
2471
- componentInfo . owner == null
2478
+ debugInfo . owner == null
2472
2479
? null
2473
- : initializeFakeTask ( response , componentInfo . owner , env ) ;
2480
+ : initializeFakeTask ( response , debugInfo . owner , env ) ;
2474
2481
return buildFakeTask (
2475
2482
response ,
2476
2483
ownerTask ,
@@ -2479,20 +2486,27 @@ function initializeFakeTask(
2479
2486
env ,
2480
2487
) ;
2481
2488
} else {
2482
- const cachedEntry = componentInfo . debugTask ;
2489
+ const cachedEntry = debugInfo . debugTask ;
2483
2490
if ( cachedEntry !== undefined ) {
2484
2491
return cachedEntry ;
2485
2492
}
2486
2493
const ownerTask =
2487
- componentInfo . owner == null
2494
+ debugInfo . owner == null
2488
2495
? 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 ) ) ;
2490
2504
// $FlowFixMe[cannot-write]: We consider this part of initialization.
2491
- return ( componentInfo . debugTask = buildFakeTask (
2505
+ return ( debugInfo . debugTask = buildFakeTask (
2492
2506
response ,
2493
2507
ownerTask ,
2494
2508
stack ,
2495
- getServerComponentTaskName ( componentInfo ) ,
2509
+ taskName ,
2496
2510
env ,
2497
2511
) ) ;
2498
2512
}
@@ -2555,7 +2569,7 @@ function fakeJSXCallSite() {
2555
2569
2556
2570
function initializeFakeStack(
2557
2571
response: Response,
2558
- debugInfo: ReactComponentInfo | ReactAsyncInfo,
2572
+ debugInfo: ReactComponentInfo | ReactAsyncInfo | ReactIOInfo ,
2559
2573
): void {
2560
2574
const cachedEntry = debugInfo . debugStack ;
2561
2575
if ( cachedEntry !== undefined ) {
@@ -2740,6 +2754,54 @@ function resolveConsoleEntry(
2740
2754
);
2741
2755
}
2742
2756
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
+
2743
2805
function mergeBuffer (
2744
2806
buffer : Array < Uint8Array > ,
2745
2807
lastChunk : Uint8Array ,
@@ -2844,7 +2906,7 @@ function flushComponentPerformance(
2844
2906
2845
2907
// First find the start time of the first component to know if it was running
2846
2908
// in parallel with the previous.
2847
- const debugInfo = root . _debugInfo ;
2909
+ const debugInfo = __DEV__ && root . _debugInfo ;
2848
2910
if ( debugInfo ) {
2849
2911
for ( let i = 1 ; i < debugInfo . length ; i ++ ) {
2850
2912
const info = debugInfo [ i ] ;
@@ -3101,6 +3163,17 @@ function processFullStringRow(
3101
3163
}
3102
3164
// Fallthrough to share the error with Console entries.
3103
3165
}
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
+ }
3104
3177
case 87 /* "W" */ : {
3105
3178
if ( __DEV__ ) {
3106
3179
resolveConsoleEntry ( response , row ) ;
0 commit comments