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' ) ;
@@ -144,6 +145,9 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
144
145
// Keeps track of whether we're currently in a work loop.
145
146
let isPerformingWork : boolean = false ;
146
147
148
+ // Keeps track of whether the current deadline has expired.
149
+ let deadlineHasExpired : boolean = false ;
150
+
147
151
// Keeps track of whether we should should batch sync updates.
148
152
let isBatchingUpdates : boolean = false ;
149
153
@@ -394,9 +398,17 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
394
398
// ref unmounts.
395
399
nextEffect = firstEffect ;
396
400
while ( nextEffect !== null ) {
397
- try {
398
- commitAllHostEffects ( finishedWork ) ;
399
- } catch ( error ) {
401
+ let error = null ;
402
+ if ( __DEV__ ) {
403
+ error = invokeGuardedCallback ( null , commitAllHostEffects , null , finishedWork ) ;
404
+ } else {
405
+ try {
406
+ commitAllHostEffects ( finishedWork ) ;
407
+ } catch ( e ) {
408
+ error = e ;
409
+ }
410
+ }
411
+ if ( error !== null ) {
400
412
invariant (
401
413
nextEffect !== null ,
402
414
'Should have next effect. This error is likely caused by a bug ' +
@@ -424,9 +436,17 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
424
436
// This pass also triggers any renderer-specific initial effects.
425
437
nextEffect = firstEffect ;
426
438
while ( nextEffect !== null ) {
427
- try {
428
- commitAllLifeCycles ( finishedWork , nextEffect ) ;
429
- } catch ( error ) {
439
+ let error = null ;
440
+ if ( __DEV__ ) {
441
+ error = invokeGuardedCallback ( null , commitAllLifeCycles , null , finishedWork ) ;
442
+ } else {
443
+ try {
444
+ commitAllLifeCycles ( finishedWork ) ;
445
+ } catch ( e ) {
446
+ error = e ;
447
+ }
448
+ }
449
+ if ( error !== null ) {
430
450
invariant (
431
451
nextEffect !== null ,
432
452
'Should have next effect. This error is likely caused by a bug ' +
@@ -655,7 +675,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
655
675
}
656
676
}
657
677
658
- function workLoop ( priorityLevel , deadline : Deadline | null , deadlineHasExpired : boolean ) : boolean {
678
+ function workLoop ( priorityLevel , deadline : Deadline | null ) {
659
679
// Clear any errors.
660
680
clearErrors ( ) ;
661
681
@@ -723,8 +743,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
723
743
if ( hostRootTimeMarker ) {
724
744
console . timeEnd ( hostRootTimeMarker ) ;
725
745
}
726
-
727
- return deadlineHasExpired ;
728
746
}
729
747
730
748
function performWork ( priorityLevel : PriorityLevel , deadline : Deadline | null ) {
@@ -735,7 +753,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
735
753
) ;
736
754
isPerformingWork = true ;
737
755
const isPerformingDeferredWork = Boolean ( deadline ) ;
738
- let deadlineHasExpired = false ;
739
756
740
757
// This outer loop exists so that we can restart the work loop after
741
758
// catching an error. It also lets us flush Task work at the end of a
@@ -756,18 +773,25 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
756
773
// Nothing in performWork should be allowed to throw. All unsafe
757
774
// operations must happen within workLoop, which is extracted to a
758
775
// separate function so that it can be optimized by the JS engine.
759
- try {
760
- priorityContextBeforeReconciliation = priorityContext ;
761
- priorityContext = nextPriorityLevel ;
762
- deadlineHasExpired = workLoop ( priorityLevel , deadline , deadlineHasExpired ) ;
763
- } catch ( error ) {
776
+ priorityContextBeforeReconciliation = priorityContext ;
777
+ let error = null ;
778
+ if ( __DEV__ ) {
779
+ error = invokeGuardedCallback ( null , workLoop , null , priorityLevel , deadline ) ;
780
+ } else {
781
+ try {
782
+ workLoop ( priorityLevel , deadline ) ;
783
+ } catch ( e ) {
784
+ error = e ;
785
+ }
786
+ }
787
+ // Reset the priority context to its value before reconcilation.
788
+ priorityContext = priorityContextBeforeReconciliation ;
789
+
790
+ if ( error !== null ) {
764
791
// We caught an error during either the begin or complete phases.
765
792
const failedWork = nextUnitOfWork ;
766
793
767
794
if ( failedWork !== null ) {
768
- // Reset the priority context to its value before reconciliation.
769
- priorityContext = priorityContextBeforeReconciliation ;
770
-
771
795
// "Capture" the error by finding the nearest boundary. If there is no
772
796
// error boundary, the nearest host container acts as one. If
773
797
// captureError returns null, the error was intentionally ignored.
@@ -798,8 +822,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
798
822
// inside resetAfterCommit.
799
823
fatalError = error ;
800
824
}
801
- } finally {
802
- priorityContext = priorityContextBeforeReconciliation ;
803
825
}
804
826
805
827
// Stop performing work
@@ -842,6 +864,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
842
864
843
865
// We're done performing work. Time to clean up.
844
866
isPerformingWork = false ;
867
+ deadlineHasExpired = false ;
845
868
fatalError = null ;
846
869
firstUncaughtError = null ;
847
870
capturedErrors = null ;
0 commit comments