@@ -506,7 +506,11 @@ export function commitClassCallbacks(finishedWork: Fiber) {
506506 // but instead we rely on them being set during last render.
507507 // TODO: revisit this when we implement resuming.
508508 try {
509- commitCallbacks ( updateQueue , instance ) ;
509+ if ( __DEV__ ) {
510+ runWithFiberInDEV ( finishedWork , commitCallbacks , updateQueue , instance ) ;
511+ } else {
512+ commitCallbacks ( updateQueue , instance ) ;
513+ }
510514 } catch ( error ) {
511515 captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
512516 }
@@ -521,7 +525,16 @@ export function commitClassHiddenCallbacks(finishedWork: Fiber) {
521525 if ( updateQueue !== null ) {
522526 const instance = finishedWork . stateNode ;
523527 try {
524- commitHiddenCallbacks ( updateQueue , instance ) ;
528+ if ( __DEV__ ) {
529+ runWithFiberInDEV (
530+ finishedWork ,
531+ commitHiddenCallbacks ,
532+ updateQueue ,
533+ instance ,
534+ ) ;
535+ } else {
536+ commitHiddenCallbacks ( updateQueue , instance ) ;
537+ }
525538 } catch ( error ) {
526539 captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
527540 }
@@ -547,7 +560,11 @@ export function commitRootCallbacks(finishedWork: Fiber) {
547560 }
548561 }
549562 try {
550- commitCallbacks ( updateQueue , instance ) ;
563+ if ( __DEV__ ) {
564+ runWithFiberInDEV ( finishedWork , commitCallbacks , updateQueue , instance ) ;
565+ } else {
566+ commitCallbacks ( updateQueue , instance ) ;
567+ }
551568 } catch (error) {
552569 captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
553570 }
@@ -559,6 +576,14 @@ if (__DEV__) {
559576 didWarnAboutUndefinedSnapshotBeforeUpdate = new Set ( ) ;
560577}
561578
579+ function callGetSnapshotBeforeUpdates(
580+ instance: any,
581+ prevProps: any,
582+ prevState: any,
583+ ) {
584+ return instance . getSnapshotBeforeUpdate ( prevProps , prevState ) ;
585+ }
586+
562587export function commitClassSnapshot(finishedWork: Fiber, current: Fiber) {
563588 const prevProps = current . memoizedProps ;
564589 const prevState = current . memoizedState ;
@@ -595,15 +620,20 @@ export function commitClassSnapshot(finishedWork: Fiber, current: Fiber) {
595620 }
596621 }
597622 try {
598- const snapshot = instance . getSnapshotBeforeUpdate (
599- resolveClassComponentProps (
600- finishedWork . type ,
601- prevProps ,
602- finishedWork . elementType === finishedWork . type ,
603- ) ,
604- prevState ,
623+ const resolvedPrevProps = resolveClassComponentProps (
624+ finishedWork . type ,
625+ prevProps ,
626+ finishedWork . elementType === finishedWork . type ,
605627 ) ;
628+ let snapshot ;
606629 if ( __DEV__ ) {
630+ snapshot = runWithFiberInDEV (
631+ finishedWork ,
632+ callGetSnapshotBeforeUpdates ,
633+ instance ,
634+ resolvedPrevProps ,
635+ prevState ,
636+ ) ;
607637 const didWarnSet =
608638 ( ( didWarnAboutUndefinedSnapshotBeforeUpdate : any ) : Set < mixed > ) ;
609639 if ( snapshot === undefined && ! didWarnSet . has ( finishedWork . type ) ) {
@@ -614,6 +644,12 @@ export function commitClassSnapshot(finishedWork: Fiber, current: Fiber) {
614644 getComponentNameFromFiber ( finishedWork ) ,
615645 ) ;
616646 }
647+ } else {
648+ snapshot = callGetSnapshotBeforeUpdates (
649+ instance ,
650+ resolvedPrevProps ,
651+ prevState ,
652+ ) ;
617653 }
618654 instance.__reactInternalSnapshotBeforeUpdate = snapshot;
619655 } catch ( error ) {
@@ -726,7 +762,11 @@ export function safelyAttachRef(
726762 nearestMountedAncestor : Fiber | null ,
727763) {
728764 try {
729- commitAttachRef ( current ) ;
765+ if ( __DEV__ ) {
766+ runWithFiberInDEV ( current , commitAttachRef , current ) ;
767+ } else {
768+ commitAttachRef ( current ) ;
769+ }
730770 } catch (error) {
731771 captureCommitPhaseError ( current , nearestMountedAncestor , error ) ;
732772 }
@@ -745,12 +785,20 @@ export function safelyDetachRef(
745785 if ( shouldProfile ( current ) ) {
746786 try {
747787 startLayoutEffectTimer ( ) ;
748- refCleanup ( ) ;
788+ if ( __DEV__ ) {
789+ runWithFiberInDEV ( current , refCleanup ) ;
790+ } else {
791+ refCleanup ( ) ;
792+ }
749793 } finally {
750794 recordLayoutEffectDuration ( current ) ;
751795 }
752796 } else {
753- refCleanup ( ) ;
797+ if ( __DEV__ ) {
798+ runWithFiberInDEV ( current , refCleanup ) ;
799+ } else {
800+ refCleanup ( ) ;
801+ }
754802 }
755803 } catch ( error ) {
756804 captureCommitPhaseError ( current , nearestMountedAncestor , error ) ;
@@ -767,12 +815,20 @@ export function safelyDetachRef(
767815 if ( shouldProfile ( current ) ) {
768816 try {
769817 startLayoutEffectTimer ( ) ;
770- ref ( null ) ;
818+ if ( __DEV__ ) {
819+ ( runWithFiberInDEV ( current , ref, null ) : void ) ;
820+ } else {
821+ ref ( null ) ;
822+ }
771823 } finally {
772824 recordLayoutEffectDuration ( current ) ;
773825 }
774826 } else {
775- ref ( null ) ;
827+ if ( __DEV__ ) {
828+ ( runWithFiberInDEV ( current , ref , null ) : void ) ;
829+ } else {
830+ ref ( null ) ;
831+ }
776832 }
777833 } catch ( error ) {
778834 captureCommitPhaseError ( current , nearestMountedAncestor , error ) ;
@@ -806,6 +862,44 @@ export function safelyCallDestroy(
806862 }
807863}
808864
865+ function commitProfiler (
866+ finishedWork : Fiber ,
867+ current : Fiber | null ,
868+ commitTime : number ,
869+ effectDuration : number ,
870+ ) {
871+ const { onCommit , onRender } = finishedWork . memoizedProps ;
872+
873+ let phase = current === null ? 'mount' : 'update' ;
874+ if ( enableProfilerNestedUpdatePhase ) {
875+ if ( isCurrentUpdateNested ( ) ) {
876+ phase = 'nested - update ';
877+ }
878+ }
879+
880+ if ( typeof onRender === 'function' ) {
881+ onRender (
882+ finishedWork . memoizedProps . id ,
883+ phase ,
884+ finishedWork . actualDuration ,
885+ finishedWork . treeBaseDuration ,
886+ finishedWork . actualStartTime ,
887+ commitTime ,
888+ ) ;
889+ }
890+
891+ if ( enableProfilerCommitHooks ) {
892+ if ( typeof onCommit === 'function' ) {
893+ onCommit (
894+ finishedWork . memoizedProps . id ,
895+ phase ,
896+ effectDuration ,
897+ commitTime ,
898+ ) ;
899+ }
900+ }
901+ }
902+
809903export function commitProfilerUpdate(
810904 finishedWork: Fiber,
811905 current: Fiber | null,
@@ -814,35 +908,17 @@ export function commitProfilerUpdate(
814908) {
815909 if ( enableProfilerTimer && getExecutionContext ( ) & CommitContext ) {
816910 try {
817- const { onCommit, onRender} = finishedWork . memoizedProps ;
818-
819- let phase = current === null ? 'mount' : 'update' ;
820- if ( enableProfilerNestedUpdatePhase ) {
821- if ( isCurrentUpdateNested ( ) ) {
822- phase = 'nested-update' ;
823- }
824- }
825-
826- if ( typeof onRender === 'function' ) {
827- onRender (
828- finishedWork . memoizedProps . id ,
829- phase ,
830- finishedWork . actualDuration ,
831- finishedWork . treeBaseDuration ,
832- finishedWork . actualStartTime ,
911+ if ( __DEV__ ) {
912+ runWithFiberInDEV (
913+ finishedWork ,
914+ commitProfiler ,
915+ finishedWork ,
916+ current ,
833917 commitTime ,
918+ effectDuration ,
834919 ) ;
835- }
836-
837- if ( enableProfilerCommitHooks ) {
838- if ( typeof onCommit === 'function' ) {
839- onCommit (
840- finishedWork . memoizedProps . id ,
841- phase ,
842- effectDuration ,
843- commitTime ,
844- ) ;
845- }
920+ } else {
921+ commitProfiler ( finishedWork , current, commitTime, effectDuration) ;
846922 }
847923 } catch (error) {
848924 captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
0 commit comments