@@ -50,6 +50,7 @@ import {
50
50
computeExpirationForFiber ,
51
51
scheduleWork ,
52
52
} from './ReactFiberScheduler' ;
53
+ import { checkForPendingContext } from './ReactFiberNewContext' ;
53
54
54
55
const fakeInternalInstance = { } ;
55
56
const isArray = Array . isArray ;
@@ -231,7 +232,7 @@ function checkShouldComponentUpdate(
231
232
newProps ,
232
233
oldState ,
233
234
newState ,
234
- newContext ,
235
+ nextLegacyContext ,
235
236
) {
236
237
const instance = workInProgress . stateNode ;
237
238
const ctor = workInProgress . type ;
@@ -240,7 +241,7 @@ function checkShouldComponentUpdate(
240
241
const shouldUpdate = instance . shouldComponentUpdate (
241
242
newProps ,
242
243
newState ,
243
- newContext ,
244
+ nextLegacyContext ,
244
245
) ;
245
246
stopPhaseTimer ( ) ;
246
247
@@ -616,15 +617,15 @@ function callComponentWillReceiveProps(
616
617
workInProgress ,
617
618
instance ,
618
619
newProps ,
619
- newContext ,
620
+ nextLegacyContext ,
620
621
) {
621
622
const oldState = instance . state ;
622
623
startPhaseTimer ( workInProgress , 'componentWillReceiveProps' ) ;
623
624
if ( typeof instance . componentWillReceiveProps === 'function' ) {
624
- instance . componentWillReceiveProps ( newProps , newContext ) ;
625
+ instance . componentWillReceiveProps ( newProps , nextLegacyContext ) ;
625
626
}
626
627
if ( typeof instance . UNSAFE_componentWillReceiveProps === 'function' ) {
627
- instance . UNSAFE_componentWillReceiveProps ( newProps , newContext ) ;
628
+ instance . UNSAFE_componentWillReceiveProps ( newProps , nextLegacyContext ) ;
628
629
}
629
630
stopPhaseTimer ( ) ;
630
631
@@ -746,8 +747,16 @@ function resumeMountClassInstance(
746
747
instance . props = oldProps ;
747
748
748
749
const oldContext = instance . context ;
749
- const newUnmaskedContext = getUnmaskedContext ( workInProgress ) ;
750
- const newContext = getMaskedContext ( workInProgress , newUnmaskedContext ) ;
750
+ const nextLegacyUnmaskedContext = getUnmaskedContext ( workInProgress ) ;
751
+ const nextLegacyContext = getMaskedContext (
752
+ workInProgress ,
753
+ nextLegacyUnmaskedContext ,
754
+ ) ;
755
+
756
+ const hasPendingNewContext = checkForPendingContext (
757
+ workInProgress ,
758
+ renderExpirationTime ,
759
+ ) ;
751
760
752
761
const getDerivedStateFromProps = ctor . getDerivedStateFromProps ;
753
762
const hasNewLifecycles =
@@ -765,12 +774,12 @@ function resumeMountClassInstance(
765
774
( typeof instance . UNSAFE_componentWillReceiveProps === 'function' ||
766
775
typeof instance . componentWillReceiveProps === 'function' )
767
776
) {
768
- if ( oldProps !== newProps || oldContext !== newContext ) {
777
+ if ( oldProps !== newProps || oldContext !== nextLegacyContext ) {
769
778
callComponentWillReceiveProps (
770
779
workInProgress ,
771
780
instance ,
772
781
newProps ,
773
- newContext ,
782
+ nextLegacyContext ,
774
783
) ;
775
784
}
776
785
}
@@ -794,6 +803,7 @@ function resumeMountClassInstance(
794
803
oldProps === newProps &&
795
804
oldState === newState &&
796
805
! hasContextChanged ( ) &&
806
+ ! hasPendingNewContext &&
797
807
! checkHasForceUpdateAfterProcessing ( )
798
808
) {
799
809
// If an update was already in progress, we should schedule an Update
@@ -815,13 +825,14 @@ function resumeMountClassInstance(
815
825
816
826
const shouldUpdate =
817
827
checkHasForceUpdateAfterProcessing ( ) ||
828
+ hasPendingNewContext ||
818
829
checkShouldComponentUpdate (
819
830
workInProgress ,
820
831
oldProps ,
821
832
newProps ,
822
833
oldState ,
823
834
newState ,
824
- newContext ,
835
+ nextLegacyContext ,
825
836
) ;
826
837
827
838
if ( shouldUpdate ) {
@@ -861,7 +872,7 @@ function resumeMountClassInstance(
861
872
// if shouldComponentUpdate returns false.
862
873
instance . props = newProps ;
863
874
instance . state = newState ;
864
- instance . context = newContext ;
875
+ instance . context = nextLegacyContext ;
865
876
866
877
return shouldUpdate ;
867
878
}
@@ -880,8 +891,16 @@ function updateClassInstance(
880
891
instance . props = oldProps ;
881
892
882
893
const oldContext = instance . context ;
883
- const newUnmaskedContext = getUnmaskedContext ( workInProgress ) ;
884
- const newContext = getMaskedContext ( workInProgress , newUnmaskedContext ) ;
894
+ const nextLegacyUnmaskedContext = getUnmaskedContext ( workInProgress ) ;
895
+ const nextLegacyContext = getMaskedContext (
896
+ workInProgress ,
897
+ nextLegacyUnmaskedContext ,
898
+ ) ;
899
+
900
+ const hasPendingNewContext = checkForPendingContext (
901
+ workInProgress ,
902
+ renderExpirationTime ,
903
+ ) ;
885
904
886
905
const getDerivedStateFromProps = ctor . getDerivedStateFromProps ;
887
906
const hasNewLifecycles =
@@ -899,12 +918,12 @@ function updateClassInstance(
899
918
( typeof instance . UNSAFE_componentWillReceiveProps === 'function' ||
900
919
typeof instance . componentWillReceiveProps === 'function' )
901
920
) {
902
- if ( oldProps !== newProps || oldContext !== newContext ) {
921
+ if ( oldProps !== newProps || oldContext !== nextLegacyContext ) {
903
922
callComponentWillReceiveProps (
904
923
workInProgress ,
905
924
instance ,
906
925
newProps ,
907
- newContext ,
926
+ nextLegacyContext ,
908
927
) ;
909
928
}
910
929
}
@@ -929,6 +948,7 @@ function updateClassInstance(
929
948
oldProps === newProps &&
930
949
oldState === newState &&
931
950
! hasContextChanged ( ) &&
951
+ ! hasPendingNewContext &&
932
952
! checkHasForceUpdateAfterProcessing ( )
933
953
) {
934
954
// If an update was already in progress, we should schedule an Update
@@ -963,13 +983,14 @@ function updateClassInstance(
963
983
964
984
const shouldUpdate =
965
985
checkHasForceUpdateAfterProcessing ( ) ||
986
+ hasPendingNewContext ||
966
987
checkShouldComponentUpdate (
967
988
workInProgress ,
968
989
oldProps ,
969
990
newProps ,
970
991
oldState ,
971
992
newState ,
972
- newContext ,
993
+ nextLegacyContext ,
973
994
) ;
974
995
975
996
if ( shouldUpdate ) {
@@ -982,10 +1003,14 @@ function updateClassInstance(
982
1003
) {
983
1004
startPhaseTimer ( workInProgress , 'componentWillUpdate' ) ;
984
1005
if ( typeof instance . componentWillUpdate === 'function' ) {
985
- instance . componentWillUpdate ( newProps , newState , newContext ) ;
1006
+ instance . componentWillUpdate ( newProps , newState , nextLegacyContext ) ;
986
1007
}
987
1008
if ( typeof instance . UNSAFE_componentWillUpdate === 'function' ) {
988
- instance . UNSAFE_componentWillUpdate ( newProps , newState , newContext ) ;
1009
+ instance . UNSAFE_componentWillUpdate (
1010
+ newProps ,
1011
+ newState ,
1012
+ nextLegacyContext ,
1013
+ ) ;
989
1014
}
990
1015
stopPhaseTimer ( ) ;
991
1016
}
@@ -1025,7 +1050,7 @@ function updateClassInstance(
1025
1050
// if shouldComponentUpdate returns false.
1026
1051
instance . props = newProps ;
1027
1052
instance . state = newState ;
1028
- instance . context = newContext ;
1053
+ instance . context = nextLegacyContext ;
1029
1054
1030
1055
return shouldUpdate ;
1031
1056
}
0 commit comments