35
35
getStackAddendumByWorkInProgressFiber,
36
36
} = require ( 'ReactComponentTreeHook' ) ;
37
37
var { logCapturedError } = require ( 'ReactFiberErrorLogger' ) ;
38
+ var { invokeGuardedCallback } = require ( 'ReactErrorUtils' ) ;
38
39
39
40
var ReactFiberBeginWork = require ( 'ReactFiberBeginWork' ) ;
40
41
var ReactFiberCompleteWork = require ( 'ReactFiberCompleteWork' ) ;
@@ -164,6 +165,9 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
164
165
// Keeps track of whether we're currently in a work loop.
165
166
let isPerformingWork : boolean = false ;
166
167
168
+ // Keeps track of whether the current deadline has expired.
169
+ let deadlineHasExpired : boolean = false ;
170
+
167
171
// Keeps track of whether we should should batch sync updates.
168
172
let isBatchingUpdates : boolean = false ;
169
173
@@ -414,9 +418,17 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
414
418
// ref unmounts.
415
419
nextEffect = firstEffect ;
416
420
while ( nextEffect !== null ) {
417
- try {
418
- commitAllHostEffects ( finishedWork ) ;
419
- } catch ( error ) {
421
+ let error = null ;
422
+ if ( __DEV__ ) {
423
+ error = invokeGuardedCallback ( null , commitAllHostEffects , null , finishedWork ) ;
424
+ } else {
425
+ try {
426
+ commitAllHostEffects ( finishedWork ) ;
427
+ } catch ( e ) {
428
+ error = e ;
429
+ }
430
+ }
431
+ if ( error !== null ) {
420
432
invariant (
421
433
nextEffect !== null ,
422
434
'Should have next effect. This error is likely caused by a bug ' +
@@ -444,9 +456,17 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
444
456
// This pass also triggers any renderer-specific initial effects.
445
457
nextEffect = firstEffect ;
446
458
while ( nextEffect !== null ) {
447
- try {
448
- commitAllLifeCycles ( finishedWork , nextEffect ) ;
449
- } catch ( error ) {
459
+ let error = null ;
460
+ if ( __DEV__ ) {
461
+ error = invokeGuardedCallback ( null , commitAllLifeCycles , null , finishedWork ) ;
462
+ } else {
463
+ try {
464
+ commitAllLifeCycles ( finishedWork ) ;
465
+ } catch ( e ) {
466
+ error = e ;
467
+ }
468
+ }
469
+ if ( error !== null ) {
450
470
invariant (
451
471
nextEffect !== null ,
452
472
'Should have next effect. This error is likely caused by a bug ' +
@@ -675,7 +695,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
675
695
}
676
696
}
677
697
678
- function workLoop ( priorityLevel , deadline : Deadline | null , deadlineHasExpired : boolean ) : boolean {
698
+ function workLoop ( priorityLevel , deadline : Deadline | null ) {
679
699
// Clear any errors.
680
700
clearErrors ( ) ;
681
701
@@ -743,8 +763,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
743
763
if ( hostRootTimeMarker ) {
744
764
console . timeEnd ( hostRootTimeMarker ) ;
745
765
}
746
-
747
- return deadlineHasExpired ;
748
766
}
749
767
750
768
function performWork ( priorityLevel : PriorityLevel , deadline : Deadline | null ) {
@@ -755,7 +773,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
755
773
) ;
756
774
isPerformingWork = true ;
757
775
const isPerformingDeferredWork = Boolean ( deadline ) ;
758
- let deadlineHasExpired = false ;
759
776
760
777
// This outer loop exists so that we can restart the work loop after
761
778
// catching an error. It also lets us flush Task work at the end of a
@@ -776,18 +793,25 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
776
793
// Nothing in performWork should be allowed to throw. All unsafe
777
794
// operations must happen within workLoop, which is extracted to a
778
795
// separate function so that it can be optimized by the JS engine.
779
- try {
780
- priorityContextBeforeReconciliation = priorityContext ;
781
- priorityContext = nextPriorityLevel ;
782
- deadlineHasExpired = workLoop ( priorityLevel , deadline , deadlineHasExpired ) ;
783
- } catch ( error ) {
796
+ priorityContextBeforeReconciliation = priorityContext ;
797
+ let error = null ;
798
+ if ( __DEV__ ) {
799
+ error = invokeGuardedCallback ( null , workLoop , null , priorityLevel , deadline ) ;
800
+ } else {
801
+ try {
802
+ workLoop ( priorityLevel , deadline ) ;
803
+ } catch ( e ) {
804
+ error = e ;
805
+ }
806
+ }
807
+ // Reset the priority context to its value before reconcilation.
808
+ priorityContext = priorityContextBeforeReconciliation ;
809
+
810
+ if ( error !== null ) {
784
811
// We caught an error during either the begin or complete phases.
785
812
const failedWork = nextUnitOfWork ;
786
813
787
814
if ( failedWork !== null ) {
788
- // Reset the priority context to its value before reconciliation.
789
- priorityContext = priorityContextBeforeReconciliation ;
790
-
791
815
// "Capture" the error by finding the nearest boundary. If there is no
792
816
// error boundary, the nearest host container acts as one. If
793
817
// captureError returns null, the error was intentionally ignored.
@@ -818,8 +842,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
818
842
// inside resetAfterCommit.
819
843
fatalError = error ;
820
844
}
821
- } finally {
822
- priorityContext = priorityContextBeforeReconciliation ;
823
845
}
824
846
825
847
// Stop performing work
@@ -862,6 +884,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
862
884
863
885
// We're done performing work. Time to clean up.
864
886
isPerformingWork = false ;
887
+ deadlineHasExpired = false ;
865
888
fatalError = null ;
866
889
firstUncaughtError = null ;
867
890
capturedErrors = null ;
0 commit comments