@@ -711,11 +711,12 @@ function commitLayoutEffectOnFiber(
711
711
finishedWork : Fiber ,
712
712
committedLanes : Lanes ,
713
713
) : void {
714
- if ( ( finishedWork . flags & LayoutMask ) !== NoFlags ) {
715
- switch ( finishedWork . tag ) {
716
- case FunctionComponent :
717
- case ForwardRef :
718
- case SimpleMemoComponent : {
714
+ const flags = finishedWork . flags ;
715
+ switch ( finishedWork . tag ) {
716
+ case FunctionComponent :
717
+ case ForwardRef :
718
+ case SimpleMemoComponent : {
719
+ if ( flags & Update ) {
719
720
if ( ! offscreenSubtreeWasHidden ) {
720
721
// At this point layout effects have already been destroyed (during mutation phase).
721
722
// This is done to prevent sibling component effects from interfering with each other,
@@ -739,128 +740,128 @@ function commitLayoutEffectOnFiber(
739
740
commitHookEffectListMount ( HookLayout | HookHasEffect , finishedWork ) ;
740
741
}
741
742
}
742
- break ;
743
743
}
744
- case ClassComponent : {
745
- const instance = finishedWork . stateNode ;
746
- if ( finishedWork . flags & Update ) {
747
- if ( ! offscreenSubtreeWasHidden ) {
748
- if ( current === null ) {
749
- // We could update instance props and state here,
750
- // but instead we rely on them being set during last render.
751
- // TODO: revisit this when we implement resuming.
752
- if ( __DEV__ ) {
753
- if (
754
- finishedWork . type === finishedWork . elementType &&
755
- ! didWarnAboutReassigningProps
756
- ) {
757
- if ( instance . props !== finishedWork . memoizedProps ) {
758
- console . error (
759
- 'Expected %s props to match memoized props before ' +
760
- 'componentDidMount. ' +
761
- 'This might either be because of a bug in React, or because ' +
762
- 'a component reassigns its own `this.props`. ' +
763
- 'Please file an issue.' ,
764
- getComponentNameFromFiber ( finishedWork ) || 'instance' ,
765
- ) ;
766
- }
767
- if ( instance . state !== finishedWork . memoizedState ) {
768
- console . error (
769
- 'Expected %s state to match memoized state before ' +
770
- 'componentDidMount. ' +
771
- 'This might either be because of a bug in React, or because ' +
772
- 'a component reassigns its own `this.state`. ' +
773
- 'Please file an issue.' ,
774
- getComponentNameFromFiber ( finishedWork ) || 'instance' ,
775
- ) ;
776
- }
777
- }
778
- }
744
+ break ;
745
+ }
746
+ case ClassComponent : {
747
+ if ( flags & Update ) {
748
+ if ( ! offscreenSubtreeWasHidden ) {
749
+ const instance = finishedWork . stateNode ;
750
+ if ( current === null ) {
751
+ // We could update instance props and state here,
752
+ // but instead we rely on them being set during last render.
753
+ // TODO: revisit this when we implement resuming.
754
+ if ( __DEV__ ) {
779
755
if (
780
- enableProfilerTimer &&
781
- enableProfilerCommitHooks &&
782
- finishedWork . mode & ProfileMode
756
+ finishedWork . type === finishedWork . elementType &&
757
+ ! didWarnAboutReassigningProps
783
758
) {
784
- try {
785
- startLayoutEffectTimer ( ) ;
786
- instance . componentDidMount ( ) ;
787
- } finally {
788
- recordLayoutEffectDuration ( finishedWork ) ;
759
+ if ( instance . props !== finishedWork . memoizedProps ) {
760
+ console . error (
761
+ 'Expected %s props to match memoized props before ' +
762
+ 'componentDidMount. ' +
763
+ 'This might either be because of a bug in React, or because ' +
764
+ 'a component reassigns its own `this.props`. ' +
765
+ 'Please file an issue.' ,
766
+ getComponentNameFromFiber ( finishedWork ) || 'instance' ,
767
+ ) ;
768
+ }
769
+ if ( instance . state !== finishedWork . memoizedState ) {
770
+ console . error (
771
+ 'Expected %s state to match memoized state before ' +
772
+ 'componentDidMount. ' +
773
+ 'This might either be because of a bug in React, or because ' +
774
+ 'a component reassigns its own `this.state`. ' +
775
+ 'Please file an issue.' ,
776
+ getComponentNameFromFiber ( finishedWork ) || 'instance' ,
777
+ ) ;
789
778
}
790
- } else {
779
+ }
780
+ }
781
+ if (
782
+ enableProfilerTimer &&
783
+ enableProfilerCommitHooks &&
784
+ finishedWork . mode & ProfileMode
785
+ ) {
786
+ try {
787
+ startLayoutEffectTimer ( ) ;
791
788
instance . componentDidMount ( ) ;
789
+ } finally {
790
+ recordLayoutEffectDuration ( finishedWork ) ;
792
791
}
793
792
} else {
794
- const prevProps =
795
- finishedWork . elementType === finishedWork . type
796
- ? current . memoizedProps
797
- : resolveDefaultProps (
798
- finishedWork . type ,
799
- current . memoizedProps ,
800
- ) ;
801
- const prevState = current . memoizedState ;
802
- // We could update instance props and state here,
803
- // but instead we rely on them being set during last render.
804
- // TODO: revisit this when we implement resuming.
805
- if ( __DEV__ ) {
806
- if (
807
- finishedWork . type === finishedWork . elementType &&
808
- ! didWarnAboutReassigningProps
809
- ) {
810
- if ( instance . props !== finishedWork . memoizedProps ) {
811
- console . error (
812
- 'Expected %s props to match memoized props before ' +
813
- 'componentDidUpdate. ' +
814
- 'This might either be because of a bug in React, or because ' +
815
- 'a component reassigns its own `this.props`. ' +
816
- 'Please file an issue.' ,
817
- getComponentNameFromFiber ( finishedWork ) || 'instance' ,
818
- ) ;
819
- }
820
- if ( instance . state !== finishedWork . memoizedState ) {
821
- console . error (
822
- 'Expected %s state to match memoized state before ' +
823
- 'componentDidUpdate. ' +
824
- 'This might either be because of a bug in React, or because ' +
825
- 'a component reassigns its own `this.state`. ' +
826
- 'Please file an issue.' ,
827
- getComponentNameFromFiber ( finishedWork ) || 'instance' ,
828
- ) ;
829
- }
830
- }
831
- }
793
+ instance . componentDidMount ( ) ;
794
+ }
795
+ } else {
796
+ const prevProps =
797
+ finishedWork . elementType === finishedWork . type
798
+ ? current . memoizedProps
799
+ : resolveDefaultProps ( finishedWork . type , current . memoizedProps ) ;
800
+ const prevState = current . memoizedState ;
801
+ // We could update instance props and state here,
802
+ // but instead we rely on them being set during last render.
803
+ // TODO: revisit this when we implement resuming.
804
+ if ( __DEV__ ) {
832
805
if (
833
- enableProfilerTimer &&
834
- enableProfilerCommitHooks &&
835
- finishedWork . mode & ProfileMode
806
+ finishedWork . type === finishedWork . elementType &&
807
+ ! didWarnAboutReassigningProps
836
808
) {
837
- try {
838
- startLayoutEffectTimer ( ) ;
839
- instance . componentDidUpdate (
840
- prevProps ,
841
- prevState ,
842
- instance . __reactInternalSnapshotBeforeUpdate ,
809
+ if ( instance . props !== finishedWork . memoizedProps ) {
810
+ console . error (
811
+ 'Expected %s props to match memoized props before ' +
812
+ 'componentDidUpdate. ' +
813
+ 'This might either be because of a bug in React, or because ' +
814
+ 'a component reassigns its own `this.props`. ' +
815
+ 'Please file an issue.' ,
816
+ getComponentNameFromFiber ( finishedWork ) || 'instance' ,
843
817
) ;
844
- } finally {
845
- recordLayoutEffectDuration ( finishedWork ) ;
846
818
}
847
- } else {
819
+ if ( instance . state !== finishedWork . memoizedState ) {
820
+ console . error (
821
+ 'Expected %s state to match memoized state before ' +
822
+ 'componentDidUpdate. ' +
823
+ 'This might either be because of a bug in React, or because ' +
824
+ 'a component reassigns its own `this.state`. ' +
825
+ 'Please file an issue.' ,
826
+ getComponentNameFromFiber ( finishedWork ) || 'instance' ,
827
+ ) ;
828
+ }
829
+ }
830
+ }
831
+ if (
832
+ enableProfilerTimer &&
833
+ enableProfilerCommitHooks &&
834
+ finishedWork . mode & ProfileMode
835
+ ) {
836
+ try {
837
+ startLayoutEffectTimer ( ) ;
848
838
instance . componentDidUpdate (
849
839
prevProps ,
850
840
prevState ,
851
841
instance . __reactInternalSnapshotBeforeUpdate ,
852
842
) ;
843
+ } finally {
844
+ recordLayoutEffectDuration ( finishedWork ) ;
853
845
}
846
+ } else {
847
+ instance . componentDidUpdate (
848
+ prevProps ,
849
+ prevState ,
850
+ instance . __reactInternalSnapshotBeforeUpdate ,
851
+ ) ;
854
852
}
855
853
}
856
854
}
855
+ }
857
856
857
+ if ( flags & Callback ) {
858
858
// TODO: I think this is now always non-null by the time it reaches the
859
859
// commit phase. Consider removing the type check.
860
860
const updateQueue : UpdateQueue <
861
861
* ,
862
862
> | null = ( finishedWork . updateQueue : any ) ;
863
- if ( finishedWork . flags & Callback && updateQueue !== null ) {
863
+ if ( updateQueue !== null ) {
864
+ const instance = finishedWork . stateNode ;
864
865
if ( __DEV__ ) {
865
866
if (
866
867
finishedWork . type === finishedWork . elementType &&
@@ -893,21 +894,23 @@ function commitLayoutEffectOnFiber(
893
894
// TODO: revisit this when we implement resuming.
894
895
commitCallbacks ( updateQueue , instance ) ;
895
896
}
897
+ }
896
898
897
- if ( finishedWork . flags & Ref ) {
898
- if ( ! offscreenSubtreeWasHidden ) {
899
- commitAttachRef ( finishedWork ) ;
900
- }
899
+ if ( flags & Ref ) {
900
+ if ( ! offscreenSubtreeWasHidden ) {
901
+ commitAttachRef ( finishedWork ) ;
901
902
}
902
- break ;
903
903
}
904
- case HostRoot : {
904
+ break ;
905
+ }
906
+ case HostRoot : {
907
+ if ( flags & Callback ) {
905
908
// TODO: I think this is now always non-null by the time it reaches the
906
909
// commit phase. Consider removing the type check.
907
910
const updateQueue : UpdateQueue <
908
911
* ,
909
912
> | null = ( finishedWork . updateQueue : any ) ;
910
- if ( finishedWork . flags & Callback && updateQueue !== null ) {
913
+ if ( updateQueue !== null ) {
911
914
let instance = null ;
912
915
if ( finishedWork . child !== null ) {
913
916
switch ( finishedWork . child . tag ) {
@@ -921,9 +924,11 @@ function commitLayoutEffectOnFiber(
921
924
}
922
925
commitCallbacks ( updateQueue , instance ) ;
923
926
}
924
- break ;
925
927
}
926
- case HostComponent: {
928
+ break ;
929
+ }
930
+ case HostComponent : {
931
+ if ( flags & Update ) {
927
932
const instance : Instance = finishedWork . stateNode ;
928
933
929
934
// Renderers may schedule work to be done after host components are mounted
@@ -935,24 +940,26 @@ function commitLayoutEffectOnFiber(
935
940
const props = finishedWork . memoizedProps ;
936
941
commitMount ( instance , type , props , finishedWork ) ;
937
942
}
943
+ }
938
944
939
- if ( finishedWork . flags & Ref ) {
940
- if ( ! offscreenSubtreeWasHidden ) {
941
- commitAttachRef ( finishedWork ) ;
942
- }
945
+ if ( flags & Ref ) {
946
+ if ( ! offscreenSubtreeWasHidden ) {
947
+ commitAttachRef ( finishedWork ) ;
943
948
}
944
- break ;
945
- }
946
- case HostText : {
947
- // We have no life-cycles associated with text.
948
- break ;
949
949
}
950
- case HostPortal : {
951
- // We have no life-cycles associated with portals.
952
- break ;
953
- }
954
- case Profiler : {
955
- if ( enableProfilerTimer ) {
950
+ break ;
951
+ }
952
+ case HostText : {
953
+ // We have no life-cycles associated with text.
954
+ break ;
955
+ }
956
+ case HostPortal : {
957
+ // We have no life-cycles associated with portals.
958
+ break ;
959
+ }
960
+ case Profiler : {
961
+ if ( enableProfilerTimer ) {
962
+ if ( flags & Update ) {
956
963
const { onCommit, onRender} = finishedWork . memoizedProps ;
957
964
const { effectDuration} = finishedWork . stateNode ;
958
965
@@ -1009,27 +1016,29 @@ function commitLayoutEffectOnFiber(
1009
1016
}
1010
1017
}
1011
1018
}
1012
- break ;
1013
1019
}
1014
- case SuspenseComponent: {
1020
+ break ;
1021
+ }
1022
+ case SuspenseComponent : {
1023
+ if ( flags & Update ) {
1015
1024
commitSuspenseHydrationCallbacks ( finishedRoot , finishedWork ) ;
1016
- break ;
1017
1025
}
1018
- case SuspenseListComponent:
1019
- case IncompleteClassComponent:
1020
- case ScopeComponent:
1021
- case OffscreenComponent:
1022
- case LegacyHiddenComponent:
1023
- case TracingMarkerComponent : {
1024
- break ;
1025
- }
1026
-
1027
- default:
1028
- throw new Error (
1029
- 'This unit of work tag should not have side-effects. This error is ' +
1030
- 'likely caused by a bug in React. Please file an issue.' ,
1031
- ) ;
1026
+ break ;
1027
+ }
1028
+ case SuspenseListComponent :
1029
+ case IncompleteClassComponent :
1030
+ case ScopeComponent :
1031
+ case OffscreenComponent :
1032
+ case LegacyHiddenComponent :
1033
+ case TracingMarkerComponent : {
1034
+ break ;
1032
1035
}
1036
+
1037
+ default :
1038
+ throw new Error (
1039
+ 'This unit of work tag should not have side-effects. This error is ' +
1040
+ 'likely caused by a bug in React. Please file an issue.' ,
1041
+ ) ;
1033
1042
}
1034
1043
}
1035
1044
0 commit comments