@@ -1017,20 +1017,31 @@ function logPostpone(
1017
1017
request : Request ,
1018
1018
reason : string ,
1019
1019
postponeInfo : ThrownInfo ,
1020
+ debugTask : null | ConsoleTask ,
1020
1021
) : void {
1021
1022
// If this callback errors, we intentionally let that error bubble up to become a fatal error
1022
1023
// so that someone fixes the error reporting instead of hiding it.
1023
- request .onPostpone ( reason , postponeInfo ) ;
1024
+ const onPostpone = request . onPostpone ;
1025
+ if ( __DEV__ && enableOwnerStacks && debugTask ) {
1026
+ debugTask . run ( onPostpone . bind ( null , reason , postponeInfo ) ) ;
1027
+ } else {
1028
+ onPostpone ( reason , postponeInfo ) ;
1029
+ }
1024
1030
}
1025
1031
1026
1032
function logRecoverableError (
1027
1033
request : Request ,
1028
1034
error : any ,
1029
1035
errorInfo : ThrownInfo ,
1036
+ debugTask : null | ConsoleTask ,
1030
1037
) : ?string {
1031
1038
// If this callback errors, we intentionally let that error bubble up to become a fatal error
1032
1039
// so that someone fixes the error reporting instead of hiding it.
1033
- const errorDigest = request . onError ( error , errorInfo ) ;
1040
+ const onError = request . onError ;
1041
+ const errorDigest =
1042
+ __DEV__ && enableOwnerStacks && debugTask
1043
+ ? debugTask . run ( onError . bind ( null , error , errorInfo ) )
1044
+ : onError ( error , errorInfo ) ;
1034
1045
if ( errorDigest != null && typeof errorDigest !== 'string' ) {
1035
1046
// We used to throw here but since this gets called from a variety of unprotected places it
1036
1047
// seems better to just warn and discard the returned value.
@@ -1045,14 +1056,24 @@ function logRecoverableError(
1045
1056
return errorDigest ;
1046
1057
}
1047
1058
1048
- function fatalError ( request : Request , error : mixed ) : void {
1059
+ function fatalError (
1060
+ request : Request ,
1061
+ error : mixed ,
1062
+ errorInfo : ThrownInfo ,
1063
+ debugTask : null | ConsoleTask ,
1064
+ ) : void {
1049
1065
// This is called outside error handling code such as if the root errors outside
1050
1066
// a suspense boundary or if the root suspense boundary's fallback errors.
1051
1067
// It's also called if React itself or its host configs errors.
1052
1068
const onShellError = request . onShellError ;
1053
- onShellError ( error ) ;
1054
1069
const onFatalError = request . onFatalError ;
1055
- onFatalError ( error ) ;
1070
+ if ( __DEV__ && enableOwnerStacks && debugTask ) {
1071
+ debugTask . run ( onShellError . bind ( null , error ) ) ;
1072
+ debugTask . run ( onFatalError . bind ( null , error ) ) ;
1073
+ } else {
1074
+ onShellError ( error ) ;
1075
+ onFatalError ( error ) ;
1076
+ }
1056
1077
if ( request . destination !== null ) {
1057
1078
request . status = CLOSED ;
1058
1079
closeWithError ( request . destination , error ) ;
@@ -1185,11 +1206,21 @@ function renderSuspenseBoundary(
1185
1206
error . $$typeof === REACT_POSTPONE_TYPE
1186
1207
) {
1187
1208
const postponeInstance : Postpone = ( error : any ) ;
1188
- logPostpone ( request , postponeInstance . message , thrownInfo ) ;
1209
+ logPostpone (
1210
+ request ,
1211
+ postponeInstance . message ,
1212
+ thrownInfo ,
1213
+ __DEV__ && enableOwnerStacks ? task . debugTask : null ,
1214
+ ) ;
1189
1215
// TODO: Figure out a better signal than a magic digest value.
1190
1216
errorDigest = 'POSTPONE ';
1191
1217
} else {
1192
- errorDigest = logRecoverableError ( request , error , thrownInfo ) ;
1218
+ errorDigest = logRecoverableError (
1219
+ request ,
1220
+ error ,
1221
+ thrownInfo ,
1222
+ __DEV__ && enableOwnerStacks ? task . debugTask : null ,
1223
+ ) ;
1193
1224
}
1194
1225
encodeErrorForBoundary ( newBoundary , errorDigest , error , thrownInfo , false ) ;
1195
1226
@@ -1332,11 +1363,21 @@ function replaySuspenseBoundary(
1332
1363
error . $$typeof === REACT_POSTPONE_TYPE
1333
1364
) {
1334
1365
const postponeInstance : Postpone = ( error : any ) ;
1335
- logPostpone ( request , postponeInstance . message , thrownInfo ) ;
1366
+ logPostpone (
1367
+ request ,
1368
+ postponeInstance . message ,
1369
+ thrownInfo ,
1370
+ __DEV__ && enableOwnerStacks ? task . debugTask : null ,
1371
+ ) ;
1336
1372
// TODO: Figure out a better signal than a magic digest value.
1337
1373
errorDigest = 'POSTPONE ';
1338
1374
} else {
1339
- errorDigest = logRecoverableError ( request , error , thrownInfo ) ;
1375
+ errorDigest = logRecoverableError (
1376
+ request ,
1377
+ error ,
1378
+ thrownInfo ,
1379
+ __DEV__ && enableOwnerStacks ? task . debugTask : null ,
1380
+ ) ;
1340
1381
}
1341
1382
encodeErrorForBoundary (
1342
1383
resumedBoundary ,
@@ -2397,6 +2438,7 @@ function replayElement(
2397
2438
thrownInfo ,
2398
2439
childNodes ,
2399
2440
childSlots ,
2441
+ __DEV__ && enableOwnerStacks ? task . debugTask : null ,
2400
2442
) ;
2401
2443
}
2402
2444
task . replay = replay ;
@@ -2971,6 +3013,7 @@ function replayFragment(
2971
3013
thrownInfo ,
2972
3014
childNodes ,
2973
3015
childSlots ,
3016
+ __DEV__ && enableOwnerStacks ? task . debugTask : null ,
2974
3017
) ;
2975
3018
}
2976
3019
task . replay = replay ;
@@ -3361,7 +3404,12 @@ function injectPostponedHole(
3361
3404
reason : string ,
3362
3405
thrownInfo : ThrownInfo ,
3363
3406
) : Segment {
3364
- logPostpone ( request , reason , thrownInfo ) ;
3407
+ logPostpone (
3408
+ request ,
3409
+ reason ,
3410
+ thrownInfo ,
3411
+ __DEV__ && enableOwnerStacks ? task . debugTask : null ,
3412
+ ) ;
3365
3413
// Something suspended, we'll need to create a new segment and resolve it later.
3366
3414
const segment = task . blockedSegment ;
3367
3415
const insertionIndex = segment . chunks . length ;
@@ -3645,6 +3693,7 @@ function erroredReplay(
3645
3693
errorInfo : ThrownInfo ,
3646
3694
replayNodes : ReplayNode [ ] ,
3647
3695
resumeSlots : ResumeSlots ,
3696
+ debugTask : null | ConsoleTask ,
3648
3697
) : void {
3649
3698
// Erroring during a replay doesn't actually cause an error by itself because
3650
3699
// that component has already rendered. What causes the error is the resumable
@@ -3661,11 +3710,11 @@ function erroredReplay(
3661
3710
error . $$typeof === REACT_POSTPONE_TYPE
3662
3711
) {
3663
3712
const postponeInstance : Postpone = ( error : any ) ;
3664
- logPostpone ( request , postponeInstance . message , errorInfo ) ;
3713
+ logPostpone ( request , postponeInstance . message , errorInfo , debugTask ) ;
3665
3714
// TODO: Figure out a better signal than a magic digest value.
3666
3715
errorDigest = 'POSTPONE' ;
3667
3716
} else {
3668
- errorDigest = logRecoverableError ( request , error , errorInfo ) ;
3717
+ errorDigest = logRecoverableError ( request , error, errorInfo, debugTask ) ;
3669
3718
}
3670
3719
abortRemainingReplayNodes (
3671
3720
request ,
@@ -3684,6 +3733,7 @@ function erroredTask(
3684
3733
boundary : Root | SuspenseBoundary ,
3685
3734
error : mixed ,
3686
3735
errorInfo : ThrownInfo ,
3736
+ debugTask : null | ConsoleTask ,
3687
3737
) {
3688
3738
// Report the error to a global handler.
3689
3739
let errorDigest ;
@@ -3694,14 +3744,14 @@ function erroredTask(
3694
3744
error . $$typeof === REACT_POSTPONE_TYPE
3695
3745
) {
3696
3746
const postponeInstance : Postpone = ( error : any ) ;
3697
- logPostpone ( request , postponeInstance . message , errorInfo ) ;
3747
+ logPostpone ( request , postponeInstance . message , errorInfo , debugTask ) ;
3698
3748
// TODO: Figure out a better signal than a magic digest value.
3699
3749
errorDigest = 'POSTPONE ';
3700
3750
} else {
3701
- errorDigest = logRecoverableError ( request , error , errorInfo ) ;
3751
+ errorDigest = logRecoverableError ( request , error , errorInfo , debugTask ) ;
3702
3752
}
3703
3753
if ( boundary === null ) {
3704
- fatalError ( request , error ) ;
3754
+ fatalError ( request , error , errorInfo , debugTask ) ;
3705
3755
} else {
3706
3756
boundary . pendingTasks -- ;
3707
3757
if ( boundary . status !== CLIENT_RENDERED ) {
@@ -3857,11 +3907,11 @@ function abortTask(task: Task, request: Request, error: mixed): void {
3857
3907
'The render was aborted with postpone when the shell is incomplete. Reason: ' +
3858
3908
postponeInstance . message ,
3859
3909
) ;
3860
- logRecoverableError ( request , fatal , errorInfo ) ;
3861
- fatalError ( request , fatal ) ;
3910
+ logRecoverableError ( request , fatal , errorInfo , null ) ;
3911
+ fatalError ( request , fatal , errorInfo , null ) ;
3862
3912
} else {
3863
- logRecoverableError ( request , error , errorInfo ) ;
3864
- fatalError ( request , error ) ;
3913
+ logRecoverableError ( request , error , errorInfo , null ) ;
3914
+ fatalError ( request , error , errorInfo , null ) ;
3865
3915
}
3866
3916
return ;
3867
3917
} else {
@@ -3878,11 +3928,11 @@ function abortTask(task: Task, request: Request, error: mixed): void {
3878
3928
error . $$typeof === REACT_POSTPONE_TYPE
3879
3929
) {
3880
3930
const postponeInstance : Postpone = ( error : any ) ;
3881
- logPostpone ( request , postponeInstance . message , errorInfo ) ;
3931
+ logPostpone ( request , postponeInstance . message , errorInfo , null ) ;
3882
3932
// TODO: Figure out a better signal than a magic digest value.
3883
3933
errorDigest = 'POSTPONE ';
3884
3934
} else {
3885
- errorDigest = logRecoverableError ( request , error , errorInfo ) ;
3935
+ errorDigest = logRecoverableError ( request , error , errorInfo , null ) ;
3886
3936
}
3887
3937
abortRemainingReplayNodes (
3888
3938
request ,
@@ -3916,11 +3966,11 @@ function abortTask(task: Task, request: Request, error: mixed): void {
3916
3966
error . $$typeof === REACT_POSTPONE_TYPE
3917
3967
) {
3918
3968
const postponeInstance : Postpone = ( error : any ) ;
3919
- logPostpone ( request , postponeInstance . message , errorInfo ) ;
3969
+ logPostpone ( request , postponeInstance . message , errorInfo , null ) ;
3920
3970
// TODO: Figure out a better signal than a magic digest value.
3921
3971
errorDigest = 'POSTPONE ';
3922
3972
} else {
3923
- errorDigest = logRecoverableError ( request , error , errorInfo ) ;
3973
+ errorDigest = logRecoverableError ( request , error , errorInfo , null ) ;
3924
3974
}
3925
3975
encodeErrorForBoundary ( boundary , errorDigest , error , errorInfo , true ) ;
3926
3976
@@ -3958,7 +4008,7 @@ function safelyEmitEarlyPreloads(
3958
4008
} catch ( error ) {
3959
4009
// We assume preloads are optimistic and thus non-fatal if errored.
3960
4010
const errorInfo : ThrownInfo = { } ;
3961
- logRecoverableError ( request , error , errorInfo ) ;
4011
+ logRecoverableError ( request , error , errorInfo , null ) ;
3962
4012
}
3963
4013
}
3964
4014
@@ -4200,7 +4250,12 @@ function retryRenderTask(
4200
4250
const postponeInstance : Postpone = ( x : any ) ;
4201
4251
4202
4252
const postponeInfo = getThrownInfo ( task . componentStack ) ;
4203
- logPostpone ( request , postponeInstance . message , postponeInfo ) ;
4253
+ logPostpone (
4254
+ request ,
4255
+ postponeInstance . message ,
4256
+ postponeInfo ,
4257
+ __DEV__ && enableOwnerStacks ? task . debugTask : null ,
4258
+ ) ;
4204
4259
trackPostpone ( request , trackedPostpones , task , segment ) ;
4205
4260
finishedTask ( request , task . blockedBoundary , segment ) ;
4206
4261
return ;
@@ -4210,7 +4265,13 @@ function retryRenderTask(
4210
4265
const errorInfo = getThrownInfo ( task . componentStack ) ;
4211
4266
task . abortSet . delete ( task ) ;
4212
4267
segment . status = ERRORED ;
4213
- erroredTask ( request , task . blockedBoundary , x , errorInfo ) ;
4268
+ erroredTask (
4269
+ request ,
4270
+ task . blockedBoundary ,
4271
+ x ,
4272
+ errorInfo ,
4273
+ __DEV__ && enableOwnerStacks ? task . debugTask : null ,
4274
+ ) ;
4214
4275
return ;
4215
4276
} finally {
4216
4277
if ( __DEV__ ) {
@@ -4289,6 +4350,7 @@ function retryReplayTask(request: Request, task: ReplayTask): void {
4289
4350
errorInfo ,
4290
4351
task . replay . nodes ,
4291
4352
task . replay . slots ,
4353
+ __DEV__ && enableOwnerStacks ? task . debugTask : null ,
4292
4354
) ;
4293
4355
request . pendingRootTasks -- ;
4294
4356
if ( request . pendingRootTasks === 0 ) {
@@ -4342,8 +4404,8 @@ export function performWork(request: Request): void {
4342
4404
}
4343
4405
} catch ( error ) {
4344
4406
const errorInfo : ThrownInfo = { } ;
4345
- logRecoverableError ( request , error , errorInfo ) ;
4346
- fatalError ( request , error ) ;
4407
+ logRecoverableError ( request , error , errorInfo , null ) ;
4408
+ fatalError ( request , error , errorInfo , null ) ;
4347
4409
} finally {
4348
4410
setCurrentResumableState ( prevResumableState ) ;
4349
4411
ReactSharedInternals . H = prevDispatcher ;
@@ -4927,8 +4989,8 @@ export function startFlowing(request: Request, destination: Destination): void {
4927
4989
flushCompletedQueues ( request , destination ) ;
4928
4990
} catch ( error ) {
4929
4991
const errorInfo : ThrownInfo = { } ;
4930
- logRecoverableError ( request , error , errorInfo ) ;
4931
- fatalError ( request , error ) ;
4992
+ logRecoverableError ( request , error , errorInfo , null ) ;
4993
+ fatalError ( request , error , errorInfo , null ) ;
4932
4994
}
4933
4995
}
4934
4996
@@ -4953,8 +5015,8 @@ export function abort(request: Request, reason: mixed): void {
4953
5015
}
4954
5016
} catch ( error ) {
4955
5017
const errorInfo : ThrownInfo = { } ;
4956
- logRecoverableError ( request , error , errorInfo ) ;
4957
- fatalError ( request , error ) ;
5018
+ logRecoverableError ( request , error , errorInfo , null ) ;
5019
+ fatalError ( request , error , errorInfo , null ) ;
4958
5020
}
4959
5021
}
4960
5022
0 commit comments