34
34
getStackAddendumByWorkInProgressFiber,
35
35
} = require ( 'ReactComponentTreeHook' ) ;
36
36
var { logCapturedError } = require ( 'ReactFiberErrorLogger' ) ;
37
+ var { invokeGuardedCallback } = require ( 'ReactErrorUtils' ) ;
37
38
38
39
var ReactFiberBeginWork = require ( 'ReactFiberBeginWork' ) ;
39
40
var ReactFiberCompleteWork = require ( 'ReactFiberCompleteWork' ) ;
@@ -130,6 +131,9 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
130
131
// Keeps track of whether we're currently in a work loop.
131
132
let isPerformingWork : boolean = false ;
132
133
134
+ // Keeps track of whether the current deadline has expired.
135
+ let deadlineHasExpired : boolean = false ;
136
+
133
137
// Keeps track of whether we should should batch sync updates.
134
138
let isBatchingUpdates : boolean = false ;
135
139
@@ -377,9 +381,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
377
381
// ref unmounts.
378
382
nextEffect = firstEffect ;
379
383
while ( nextEffect !== null ) {
380
- try {
381
- commitAllHostEffects ( finishedWork ) ;
382
- } catch ( error ) {
384
+ const error = invokeGuardedCallback ( null , commitAllHostEffects , null , finishedWork ) ;
385
+ if ( error !== null ) {
383
386
invariant (
384
387
nextEffect !== null ,
385
388
'Should have next effect. This error is likely caused by a bug ' +
@@ -407,9 +410,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
407
410
// This pass also triggers any renderer-specific initial effects.
408
411
nextEffect = firstEffect ;
409
412
while ( nextEffect !== null ) {
410
- try {
411
- commitAllLifeCycles ( finishedWork , nextEffect ) ;
412
- } catch ( error ) {
413
+ const error = invokeGuardedCallback ( null , commitAllLifeCycles , null , finishedWork ) ;
414
+ if ( error !== null ) {
413
415
invariant (
414
416
nextEffect !== null ,
415
417
'Should have next effect. This error is likely caused by a bug ' +
@@ -638,7 +640,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
638
640
}
639
641
}
640
642
641
- function workLoop ( priorityLevel , deadline : Deadline | null , deadlineHasExpired : boolean ) : boolean {
643
+ function workLoop ( priorityLevel , deadline : Deadline | null ) {
642
644
// Clear any errors.
643
645
clearErrors ( ) ;
644
646
@@ -706,8 +708,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
706
708
if ( hostRootTimeMarker ) {
707
709
console . timeEnd ( hostRootTimeMarker ) ;
708
710
}
709
-
710
- return deadlineHasExpired ;
711
711
}
712
712
713
713
function performWork ( priorityLevel : PriorityLevel , deadline : Deadline | null ) {
@@ -718,7 +718,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
718
718
) ;
719
719
isPerformingWork = true ;
720
720
const isPerformingDeferredWork = Boolean ( deadline ) ;
721
- let deadlineHasExpired = false ;
722
721
723
722
// This outer loop exists so that we can restart the work loop after
724
723
// catching an error. It also lets us flush Task work at the end of a
@@ -739,17 +738,15 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
739
738
// Nothing in performWork should be allowed to throw. All unsafe
740
739
// operations must happen within workLoop, which is extracted to a
741
740
// separate function so that it can be optimized by the JS engine.
742
- try {
743
- priorityContextBeforeReconciliation = priorityContext ;
744
- priorityContext = nextPriorityLevel ;
745
- deadlineHasExpired = workLoop ( priorityLevel , deadline , deadlineHasExpired ) ;
746
- } catch ( error ) {
741
+ priorityContextBeforeReconciliation = priorityContext ;
742
+ const error = invokeGuardedCallback ( null , workLoop , null , priorityLevel , deadline ) ;
743
+ // Reset the priority context to its value before reconcilation.
744
+ priorityContext = priorityContextBeforeReconciliation ;
745
+
746
+ if ( error !== null ) {
747
747
// We caught an error during either the begin or complete phases.
748
748
const failedWork = nextUnitOfWork ;
749
749
if ( failedWork !== null ) {
750
- // Reset the priority context to its value before reconcilation.
751
- priorityContext = priorityContextBeforeReconciliation ;
752
-
753
750
// "Capture" the error by finding the nearest boundary. If there is no
754
751
// error boundary, the nearest host container acts as one. If
755
752
// captureError returns null, the error was intentionally ignored.
@@ -780,8 +777,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
780
777
// inside resetAfterCommit.
781
778
fatalError = error ;
782
779
}
783
- } finally {
784
- priorityContext = priorityContextBeforeReconciliation ;
785
780
}
786
781
787
782
// Stop performing work
@@ -824,6 +819,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
824
819
825
820
// We're done performing work. Time to clean up.
826
821
isPerformingWork = false ;
822
+ deadlineHasExpired = false ;
827
823
fatalError = null ;
828
824
firstUncaughtError = null ;
829
825
capturedErrors = null ;
0 commit comments