@@ -722,6 +722,17 @@ function initializeModelChunk<T>(chunk: ResolvedModelChunk<T>): void {
722
722
initializingChunk = cyclicChunk ;
723
723
}
724
724
725
+ if ( __DEV__ ) {
726
+ const blockingDebugChunk = chunk . _blockedDebugInfo ;
727
+ if (
728
+ blockingDebugChunk != null &&
729
+ ( blockingDebugChunk . status === BLOCKED ||
730
+ blockingDebugChunk . status === PENDING )
731
+ ) {
732
+ waitForReference ( blockingDebugChunk , { } , '' , response , ( ) => { } , [ '' ] ) ;
733
+ }
734
+ }
735
+
725
736
try {
726
737
const value : T = parseModel ( response , resolvedModel ) ;
727
738
// Invoke any listeners added while resolving this model. I.e. cyclic
@@ -2239,6 +2250,22 @@ function resolveStream<T: ReadableStream | $AsyncIterable<any, any, void>>(
2239
2250
chunks . set ( id , createInitializedStreamChunk ( response , stream , controller ) ) ;
2240
2251
return ;
2241
2252
}
2253
+ if ( __DEV__ ) {
2254
+ const blockedDebugInfo = chunk . _blockedDebugInfo ;
2255
+ if ( blockedDebugInfo != null ) {
2256
+ // If we're blocked on debug info, wait until it has loaded before we resolve.
2257
+ const unblock = resolveStream . bind (
2258
+ null ,
2259
+ response ,
2260
+ id ,
2261
+ stream ,
2262
+ controller ,
2263
+ ) ;
2264
+ blockedDebugInfo . then ( unblock , unblock ) ;
2265
+ return ;
2266
+ }
2267
+ }
2268
+
2242
2269
if ( chunk . status !== PENDING ) {
2243
2270
// We already resolved. We didn't expect to see this.
2244
2271
return ;
@@ -2622,6 +2649,41 @@ function resolvePostponeDev(
2622
2649
}
2623
2650
}
2624
2651
2652
+ function resolveErrorModel (
2653
+ response : Response ,
2654
+ id : number ,
2655
+ row : UninitializedModel ,
2656
+ ) : void {
2657
+ const chunks = response . _chunks ;
2658
+ const chunk = chunks . get ( id ) ;
2659
+ if ( __DEV__ && chunk ) {
2660
+ if ( __DEV__ ) {
2661
+ const blockedDebugInfo = chunk . _blockedDebugInfo ;
2662
+ if ( blockedDebugInfo != null ) {
2663
+ // If we're blocked on debug info, wait until it has loaded before we resolve.
2664
+ // TODO: Handle cycle if that model depends on this one.
2665
+ const unblock = resolveErrorModel . bind ( null , response , id , row ) ;
2666
+ blockedDebugInfo . then ( unblock , unblock ) ;
2667
+ return ;
2668
+ }
2669
+ }
2670
+ }
2671
+ const errorInfo = JSON . parse ( row ) ;
2672
+ let error ;
2673
+ if ( __DEV__ ) {
2674
+ error = resolveErrorDev ( response , errorInfo ) ;
2675
+ } else {
2676
+ error = resolveErrorProd ( response ) ;
2677
+ }
2678
+ (error: any).digest = errorInfo.digest;
2679
+ const errorWithDigest: ErrorWithDigest = (error: any);
2680
+ if (!chunk) {
2681
+ chunks . set ( id , createErrorChunk ( response , errorWithDigest ) ) ;
2682
+ } else {
2683
+ triggerErrorOnChunk ( chunk , errorWithDigest ) ;
2684
+ }
2685
+ }
2686
+
2625
2687
function resolveHint < Code : HintCode > (
2626
2688
response: Response,
2627
2689
code: Code,
@@ -3081,43 +3143,25 @@ function resolveDebugModel(
3081
3143
json : UninitializedModel ,
3082
3144
) : void {
3083
3145
const parentChunk = getChunk ( response , id ) ;
3084
- const blockedChunk = parentChunk . _blockedDebugInfo ;
3085
- if ( blockedChunk == null ) {
3086
- // If we're not blocked on any other chunks, we can try to eagerly initialize
3087
- // this as a fast-path to avoid awaiting them.
3088
- const chunk : ResolvedModelChunk < ReactDebugInfoEntry > =
3089
- createResolvedModelChunk ( response , json ) ;
3090
- initializeModelChunk ( chunk ) ;
3091
- const initializedChunk : SomeChunk < ReactDebugInfoEntry > = chunk ;
3092
- if ( initializedChunk . status === INITIALIZED ) {
3093
- resolveDebugInfo ( response , parentChunk , initializedChunk . value ) ;
3094
- } else {
3095
- chunk . then (
3096
- v => resolveDebugInfo ( response , parentChunk , v ) ,
3097
- e => {
3098
- // Ignore debug info errors for now. Unnecessary noise.
3099
- } ,
3100
- ) ;
3101
- parentChunk . _blockedDebugInfo = chunk ;
3102
- }
3146
+ // If we're not blocked on any other chunks, we can try to eagerly initialize
3147
+ // this as a fast-path to avoid awaiting them.
3148
+ const chunk : ResolvedModelChunk < ReactDebugInfoEntry > =
3149
+ createResolvedModelChunk ( response , json ) ;
3150
+ // The previous blocked chunk is now blocking this one.
3151
+ chunk . _blockedDebugInfo = parentChunk . _blockedDebugInfo ;
3152
+ initializeModelChunk ( chunk ) ;
3153
+ const initializedChunk : SomeChunk < ReactDebugInfoEntry > = chunk ;
3154
+ if ( initializedChunk . status === INITIALIZED ) {
3155
+ resolveDebugInfo ( response , parentChunk , initializedChunk . value ) ;
3156
+ parentChunk . _blockedDebugInfo = null ;
3103
3157
} else {
3104
- // We're still waiting on a previous chunk so we can't enqueue quite yet.
3105
- const chunk : SomeChunk < ReactDebugInfoEntry > = createPendingChunk ( response ) ;
3106
3158
chunk . then (
3107
3159
v => resolveDebugInfo ( response , parentChunk , v ) ,
3108
3160
e => {
3109
3161
// Ignore debug info errors for now. Unnecessary noise.
3110
3162
} ,
3111
3163
) ;
3112
3164
parentChunk . _blockedDebugInfo = chunk ;
3113
- blockedChunk . then ( function ( ) {
3114
- if ( parentChunk . _blockedDebugInfo === chunk ) {
3115
- // We were still the last chunk so we can now clear the queue and return
3116
- // to synchronous emitting.
3117
- parentChunk . _blockedDebugInfo = null ;
3118
- }
3119
- resolveModelChunk ( response , chunk , json ) ;
3120
- } ) ;
3121
3165
}
3122
3166
}
3123
3167
@@ -3753,22 +3797,7 @@ function processFullStringRow(
3753
3797
return ;
3754
3798
}
3755
3799
case 69 /* "E" */ : {
3756
- const errorInfo = JSON . parse ( row ) ;
3757
- let error ;
3758
- if ( __DEV__ ) {
3759
- error = resolveErrorDev ( response , errorInfo ) ;
3760
- } else {
3761
- error = resolveErrorProd ( response ) ;
3762
- }
3763
- ( error : any ) . digest = errorInfo . digest ;
3764
- const errorWithDigest : ErrorWithDigest = ( error : any ) ;
3765
- const chunks = response . _chunks ;
3766
- const chunk = chunks . get ( id ) ;
3767
- if ( ! chunk ) {
3768
- chunks . set ( id , createErrorChunk ( response , errorWithDigest ) ) ;
3769
- } else {
3770
- triggerErrorOnChunk ( chunk , errorWithDigest ) ;
3771
- }
3800
+ resolveErrorModel ( response , id , row ) ;
3772
3801
return ;
3773
3802
}
3774
3803
case 84 /* "T" */ : {
0 commit comments