@@ -275,11 +275,13 @@ let interruptedBy: Fiber | null = null;
275
275
276
276
let stashedWorkInProgressProperties ;
277
277
let replayUnitOfWork ;
278
+ let mayReplayFailedUnitOfWork ;
278
279
let isReplayingFailedUnitOfWork ;
279
280
let originalReplayError ;
280
281
let rethrowOriginalError ;
281
282
if ( __DEV__ && replayFailedUnitOfWorkWithInvokeGuardedCallback ) {
282
283
stashedWorkInProgressProperties = null ;
284
+ mayReplayFailedUnitOfWork = true ;
283
285
isReplayingFailedUnitOfWork = false ;
284
286
originalReplayError = null ;
285
287
replayUnitOfWork = (
@@ -952,18 +954,22 @@ function completeUnitOfWork(workInProgress: Fiber): Fiber | null {
952
954
const siblingFiber = workInProgress . sibling ;
953
955
954
956
if ( ( workInProgress . effectTag & Incomplete ) === NoEffect ) {
957
+ if ( __DEV__ && replayFailedUnitOfWorkWithInvokeGuardedCallback ) {
958
+ // Don't replay if it fails during completion phase.
959
+ mayReplayFailedUnitOfWork = false ;
960
+ }
955
961
// This fiber completed.
962
+ // Remember we're completing this unit so we can find a boundary if it fails.
963
+ nextUnitOfWork = workInProgress ;
956
964
if ( enableProfilerTimer ) {
957
965
if ( workInProgress . mode & ProfileMode ) {
958
966
startProfilerTimer ( workInProgress ) ;
959
967
}
960
-
961
968
nextUnitOfWork = completeWork (
962
969
current ,
963
970
workInProgress ,
964
971
nextRenderExpirationTime ,
965
972
) ;
966
-
967
973
if ( workInProgress . mode & ProfileMode ) {
968
974
// Update render duration assuming we didn't error.
969
975
stopProfilerTimerIfRunningAndRecordDelta ( workInProgress , false ) ;
@@ -975,6 +981,10 @@ function completeUnitOfWork(workInProgress: Fiber): Fiber | null {
975
981
nextRenderExpirationTime ,
976
982
) ;
977
983
}
984
+ if ( __DEV__ && replayFailedUnitOfWorkWithInvokeGuardedCallback ) {
985
+ // We're out of completion phase so replaying is fine now.
986
+ mayReplayFailedUnitOfWork = true ;
987
+ }
978
988
stopWorkTimer ( workInProgress ) ;
979
989
resetChildExpirationTime ( workInProgress , nextRenderExpirationTime ) ;
980
990
if ( __DEV__ ) {
@@ -1292,6 +1302,14 @@ function renderRoot(root: FiberRoot, isYieldy: boolean): void {
1292
1302
resetContextDependences ( ) ;
1293
1303
resetHooks ( ) ;
1294
1304
1305
+ // Reset in case completion throws.
1306
+ // This is only used in DEV and when replaying is on.
1307
+ let mayReplay ;
1308
+ if ( __DEV__ && replayFailedUnitOfWorkWithInvokeGuardedCallback ) {
1309
+ mayReplay = mayReplayFailedUnitOfWork ;
1310
+ mayReplayFailedUnitOfWork = true ;
1311
+ }
1312
+
1295
1313
if ( nextUnitOfWork === null ) {
1296
1314
// This is a fatal error.
1297
1315
didFatal = true ;
@@ -1303,9 +1321,11 @@ function renderRoot(root: FiberRoot, isYieldy: boolean): void {
1303
1321
( resetCurrentlyProcessingQueue : any ) ( ) ;
1304
1322
}
1305
1323
1306
- const failedUnitOfWork : Fiber = nextUnitOfWork ;
1307
1324
if ( __DEV__ && replayFailedUnitOfWorkWithInvokeGuardedCallback ) {
1308
- replayUnitOfWork ( failedUnitOfWork , thrownValue , isYieldy ) ;
1325
+ if ( mayReplay ) {
1326
+ const failedUnitOfWork : Fiber = nextUnitOfWork ;
1327
+ replayUnitOfWork ( failedUnitOfWork , thrownValue , isYieldy ) ;
1328
+ }
1309
1329
}
1310
1330
1311
1331
// TODO: we already know this isn't true in some cases.
0 commit comments