3535 getStackAddendumByWorkInProgressFiber,
3636} = require ( 'ReactComponentTreeHook' ) ;
3737var { logCapturedError } = require ( 'ReactFiberErrorLogger' ) ;
38+ var { invokeGuardedCallback } = require ( 'ReactErrorUtils' ) ;
3839
3940var ReactFiberBeginWork = require ( 'ReactFiberBeginWork' ) ;
4041var ReactFiberCompleteWork = require ( 'ReactFiberCompleteWork' ) ;
@@ -164,6 +165,9 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
164165 // Keeps track of whether we're currently in a work loop.
165166 let isPerformingWork : boolean = false ;
166167
168+ // Keeps track of whether the current deadline has expired.
169+ let deadlineHasExpired : boolean = false ;
170+
167171 // Keeps track of whether we should should batch sync updates.
168172 let isBatchingUpdates : boolean = false ;
169173
@@ -414,9 +418,17 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
414418 // ref unmounts.
415419 nextEffect = firstEffect ;
416420 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 ) {
420432 invariant (
421433 nextEffect !== null ,
422434 '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,
444456 // This pass also triggers any renderer-specific initial effects.
445457 nextEffect = firstEffect ;
446458 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 ) {
450470 invariant (
451471 nextEffect !== null ,
452472 '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,
675695 }
676696 }
677697
678- function workLoop ( priorityLevel , deadline : Deadline | null , deadlineHasExpired : boolean ) : boolean {
698+ function workLoop ( priorityLevel , deadline : Deadline | null ) {
679699 // Clear any errors.
680700 clearErrors ( ) ;
681701
@@ -743,8 +763,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
743763 if ( hostRootTimeMarker ) {
744764 console . timeEnd ( hostRootTimeMarker ) ;
745765 }
746-
747- return deadlineHasExpired ;
748766 }
749767
750768 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,
755773 ) ;
756774 isPerformingWork = true ;
757775 const isPerformingDeferredWork = Boolean ( deadline ) ;
758- let deadlineHasExpired = false ;
759776
760777 // This outer loop exists so that we can restart the work loop after
761778 // 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,
776793 // Nothing in performWork should be allowed to throw. All unsafe
777794 // operations must happen within workLoop, which is extracted to a
778795 // 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 ) {
784811 // We caught an error during either the begin or complete phases.
785812 const failedWork = nextUnitOfWork ;
786813
787814 if ( failedWork !== null ) {
788- // Reset the priority context to its value before reconciliation.
789- priorityContext = priorityContextBeforeReconciliation ;
790-
791815 // "Capture" the error by finding the nearest boundary. If there is no
792816 // error boundary, the nearest host container acts as one. If
793817 // 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,
818842 // inside resetAfterCommit.
819843 fatalError = error ;
820844 }
821- } finally {
822- priorityContext = priorityContextBeforeReconciliation ;
823845 }
824846
825847 // Stop performing work
@@ -862,6 +884,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
862884
863885 // We're done performing work. Time to clean up.
864886 isPerformingWork = false ;
887+ deadlineHasExpired = false ;
865888 fatalError = null ;
866889 firstUncaughtError = null ;
867890 capturedErrors = null ;
0 commit comments