@@ -629,21 +629,7 @@ function serializeThenable(
629
629
}
630
630
case 'rejected': {
631
631
const x = thenable . reason ;
632
- if (
633
- enablePostpone &&
634
- typeof x === 'object' &&
635
- x !== null &&
636
- ( x : any ) . $$typeof === REACT_POSTPONE_TYPE
637
- ) {
638
- const postponeInstance : Postpone = ( x : any ) ;
639
- logPostpone ( request , postponeInstance . message , newTask ) ;
640
- emitPostponeChunk ( request , newTask . id , postponeInstance ) ;
641
- } else {
642
- const digest = logRecoverableError ( request , x , null ) ;
643
- emitErrorChunk ( request , newTask . id , digest , x ) ;
644
- }
645
- newTask.status = ERRORED;
646
- request.abortableTasks.delete(newTask);
632
+ erroredTask ( request , newTask , x ) ;
647
633
return newTask . id ;
648
634
}
649
635
default: {
@@ -698,21 +684,7 @@ function serializeThenable(
698
684
// We expect that the only status it might be otherwise is ABORTED.
699
685
// When we abort we emit chunks in each pending task slot and don't need
700
686
// to do so again here.
701
- if (
702
- enablePostpone &&
703
- typeof reason === 'object' &&
704
- reason !== null &&
705
- ( reason : any ) . $$typeof === REACT_POSTPONE_TYPE
706
- ) {
707
- const postponeInstance : Postpone = ( reason : any ) ;
708
- logPostpone ( request , postponeInstance . message , newTask ) ;
709
- emitPostponeChunk ( request , newTask . id , postponeInstance ) ;
710
- } else {
711
- const digest = logRecoverableError ( request , reason , newTask ) ;
712
- emitErrorChunk ( request , newTask . id , digest , reason ) ;
713
- }
714
- newTask.status = ERRORED;
715
- request.abortableTasks.delete(newTask);
687
+ erroredTask ( request , newTask , reason ) ;
716
688
enqueueFlush ( request ) ;
717
689
}
718
690
} ,
@@ -795,8 +767,7 @@ function serializeReadableStream(
795
767
}
796
768
aborted = true ;
797
769
request . abortListeners . delete ( abortStream ) ;
798
- const digest = logRecoverableError ( request , reason , streamTask ) ;
799
- emitErrorChunk ( request , streamTask . id , digest , reason ) ;
770
+ erroredTask ( request , streamTask , reason ) ;
800
771
enqueueFlush ( request ) ;
801
772
802
773
// $FlowFixMe should be able to pass mixed
@@ -810,22 +781,10 @@ function serializeReadableStream(
810
781
request . abortListeners . delete ( abortStream ) ;
811
782
if ( enableHalt && request . type === PRERENDER ) {
812
783
request . pendingChunks -- ;
813
- } else if (
814
- enablePostpone &&
815
- typeof reason === 'object ' &&
816
- reason !== null &&
817
- ( reason : any ) . $$typeof === REACT_POSTPONE_TYPE
818
- ) {
819
- const postponeInstance : Postpone = ( reason : any ) ;
820
- logPostpone ( request , postponeInstance . message , streamTask ) ;
821
- emitPostponeChunk ( request , streamTask . id , postponeInstance ) ;
822
- enqueueFlush ( request ) ;
823
784
} else {
824
- const digest = logRecoverableError ( request , reason , streamTask ) ;
825
- emitErrorChunk ( request , streamTask . id , digest , reason ) ;
785
+ erroredTask ( request , streamTask , reason ) ;
826
786
enqueueFlush ( request ) ;
827
787
}
828
-
829
788
// $FlowFixMe should be able to pass mixed
830
789
reader.cancel(reason).then(error, error);
831
790
}
@@ -931,8 +890,7 @@ function serializeAsyncIterable(
931
890
}
932
891
aborted = true;
933
892
request.abortListeners.delete(abortIterable);
934
- const digest = logRecoverableError(request, reason, streamTask);
935
- emitErrorChunk(request, streamTask.id, digest, reason);
893
+ erroredTask(request, streamTask, reason);
936
894
enqueueFlush(request);
937
895
if (typeof (iterator: any).throw === 'function') {
938
896
// The iterator protocol doesn't necessarily include this but a generator do.
@@ -948,19 +906,8 @@ function serializeAsyncIterable(
948
906
request.abortListeners.delete(abortIterable);
949
907
if (enableHalt && request . type === PRERENDER ) {
950
908
request . pendingChunks -- ;
951
- } else if (
952
- enablePostpone &&
953
- typeof reason === 'object ' &&
954
- reason !== null &&
955
- ( reason : any ) . $$typeof === REACT_POSTPONE_TYPE
956
- ) {
957
- const postponeInstance : Postpone = ( reason : any ) ;
958
- logPostpone ( request , postponeInstance . message , streamTask ) ;
959
- emitPostponeChunk ( request , streamTask . id , postponeInstance ) ;
960
- enqueueFlush ( request ) ;
961
909
} else {
962
- const digest = logRecoverableError ( request , reason , streamTask ) ;
963
- emitErrorChunk ( request , streamTask . id , digest , reason ) ;
910
+ erroredTask ( request , streamTask , reason ) ;
964
911
enqueueFlush ( request ) ;
965
912
}
966
913
if (typeof (iterator: any).throw === 'function') {
@@ -2269,8 +2216,7 @@ function serializeBlob(request: Request, blob: Blob): string {
2269
2216
}
2270
2217
aborted = true ;
2271
2218
request . abortListeners . delete ( abortBlob ) ;
2272
- const digest = logRecoverableError ( request , reason , newTask ) ;
2273
- emitErrorChunk ( request , newTask . id , digest , reason ) ;
2219
+ erroredTask ( request , newTask , reason ) ;
2274
2220
enqueueFlush ( request ) ;
2275
2221
// $FlowFixMe should be able to pass mixed
2276
2222
reader . cancel ( reason ) . then ( error , error ) ;
@@ -2283,19 +2229,8 @@ function serializeBlob(request: Request, blob: Blob): string {
2283
2229
request . abortListeners . delete ( abortBlob ) ;
2284
2230
if ( enableHalt && request . type === PRERENDER ) {
2285
2231
request . pendingChunks -- ;
2286
- } else if (
2287
- enablePostpone &&
2288
- typeof reason === 'object' &&
2289
- reason !== null &&
2290
- ( reason : any ) . $$typeof === REACT_POSTPONE_TYPE
2291
- ) {
2292
- const postponeInstance : Postpone = ( reason : any ) ;
2293
- logPostpone ( request , postponeInstance . message , newTask ) ;
2294
- emitPostponeChunk ( request , newTask . id , postponeInstance ) ;
2295
- enqueueFlush ( request ) ;
2296
2232
} else {
2297
- const digest = logRecoverableError ( request , reason , newTask ) ;
2298
- emitErrorChunk ( request , newTask . id , digest , reason ) ;
2233
+ erroredTask ( request , newTask , reason ) ;
2299
2234
enqueueFlush ( request ) ;
2300
2235
}
2301
2236
// $FlowFixMe should be able to pass mixed
@@ -2396,24 +2331,6 @@ function renderModel(
2396
2331
return serializeLazyID ( newTask . id ) ;
2397
2332
}
2398
2333
return serializeByValueID ( newTask . id ) ;
2399
- } else if ( enablePostpone && x . $$typeof === REACT_POSTPONE_TYPE ) {
2400
- // Something postponed. We'll still send everything we have up until this point.
2401
- // We'll replace this element with a lazy reference that postpones on the client.
2402
- const postponeInstance : Postpone = ( x : any ) ;
2403
- request . pendingChunks ++ ;
2404
- const postponeId = request . nextChunkId ++ ;
2405
- logPostpone ( request , postponeInstance . message , task ) ;
2406
- emitPostponeChunk ( request , postponeId , postponeInstance ) ;
2407
-
2408
- // Restore the context. We assume that this will be restored by the inner
2409
- // functions in case nothing throws so we don't use "finally" here.
2410
- task . keyPath = prevKeyPath ;
2411
- task . implicitSlot = prevImplicitSlot ;
2412
-
2413
- if ( wasReactNode ) {
2414
- return serializeLazyID ( postponeId ) ;
2415
- }
2416
- return serializeByValueID ( postponeId ) ;
2417
2334
}
2418
2335
}
2419
2336
@@ -2425,8 +2342,21 @@ function renderModel(
2425
2342
// Something errored. We'll still send everything we have up until this point.
2426
2343
request . pendingChunks ++ ;
2427
2344
const errorId = request . nextChunkId ++ ;
2428
- const digest = logRecoverableError ( request , x , task ) ;
2429
- emitErrorChunk ( request , errorId , digest , x ) ;
2345
+ if (
2346
+ enablePostpone &&
2347
+ typeof x === 'object' &&
2348
+ x !== null &&
2349
+ x . $$typeof === REACT_POSTPONE_TYPE
2350
+ ) {
2351
+ // Something postponed. We'll still send everything we have up until this point.
2352
+ // We'll replace this element with a lazy reference that postpones on the client.
2353
+ const postponeInstance : Postpone = ( x : any ) ;
2354
+ logPostpone ( request , postponeInstance . message , task ) ;
2355
+ emitPostponeChunk ( request , errorId , postponeInstance ) ;
2356
+ } else {
2357
+ const digest = logRecoverableError ( request , x , task ) ;
2358
+ emitErrorChunk ( request , errorId , digest , x ) ;
2359
+ }
2430
2360
if ( wasReactNode ) {
2431
2361
// We'll replace this element with a lazy reference that throws on the client
2432
2362
// once it gets rendered.
@@ -3946,6 +3876,24 @@ function emitChunk(
3946
3876
emitModelChunk ( request , task . id , json ) ;
3947
3877
}
3948
3878
3879
+ function erroredTask ( request : Request , task : Task , error : mixed ) : void {
3880
+ request . abortableTasks . delete ( task ) ;
3881
+ task . status = ERRORED ;
3882
+ if (
3883
+ enablePostpone &&
3884
+ typeof error === 'object' &&
3885
+ error !== null &&
3886
+ error . $$typeof === REACT_POSTPONE_TYPE
3887
+ ) {
3888
+ const postponeInstance : Postpone = ( error : any ) ;
3889
+ logPostpone ( request , postponeInstance . message , task ) ;
3890
+ emitPostponeChunk ( request , task . id , postponeInstance ) ;
3891
+ } else {
3892
+ const digest = logRecoverableError ( request , error , task ) ;
3893
+ emitErrorChunk ( request , task . id , digest , error ) ;
3894
+ }
3895
+ }
3896
+
3949
3897
const emptyRoot = { } ;
3950
3898
3951
3899
function retryTask ( request : Request , task : Task ) : void {
@@ -4065,20 +4013,9 @@ function retryTask(request: Request, task: Task): void {
4065
4013
const ping = task . ping ;
4066
4014
x . then ( ping , ping ) ;
4067
4015
return ;
4068
- } else if ( enablePostpone && x . $$typeof === REACT_POSTPONE_TYPE ) {
4069
- request . abortableTasks . delete ( task ) ;
4070
- task . status = ERRORED ;
4071
- const postponeInstance : Postpone = ( x : any ) ;
4072
- logPostpone ( request , postponeInstance . message , task ) ;
4073
- emitPostponeChunk ( request , task . id , postponeInstance ) ;
4074
- return ;
4075
4016
}
4076
4017
}
4077
-
4078
- request . abortableTasks . delete ( task ) ;
4079
- task . status = ERRORED ;
4080
- const digest = logRecoverableError ( request , x , task ) ;
4081
- emitErrorChunk ( request , task . id , digest , x ) ;
4018
+ erroredTask ( request , task , x ) ;
4082
4019
} finally {
4083
4020
if ( __DEV__ ) {
4084
4021
debugID = prevDebugID ;
0 commit comments