@@ -231,7 +231,7 @@ function checkShouldComponentUpdate(
231231 newProps ,
232232 oldState ,
233233 newState ,
234- newContext ,
234+ nextLegacyContext ,
235235) {
236236 const instance = workInProgress . stateNode ;
237237 const ctor = workInProgress . type ;
@@ -240,7 +240,7 @@ function checkShouldComponentUpdate(
240240 const shouldUpdate = instance . shouldComponentUpdate (
241241 newProps ,
242242 newState ,
243- newContext ,
243+ nextLegacyContext ,
244244 ) ;
245245 stopPhaseTimer ( ) ;
246246
@@ -616,15 +616,15 @@ function callComponentWillReceiveProps(
616616 workInProgress ,
617617 instance ,
618618 newProps ,
619- newContext ,
619+ nextLegacyContext ,
620620) {
621621 const oldState = instance . state ;
622622 startPhaseTimer ( workInProgress , 'componentWillReceiveProps' ) ;
623623 if ( typeof instance . componentWillReceiveProps === 'function' ) {
624- instance . componentWillReceiveProps ( newProps , newContext ) ;
624+ instance . componentWillReceiveProps ( newProps , nextLegacyContext ) ;
625625 }
626626 if ( typeof instance . UNSAFE_componentWillReceiveProps === 'function' ) {
627- instance . UNSAFE_componentWillReceiveProps ( newProps , newContext ) ;
627+ instance . UNSAFE_componentWillReceiveProps ( newProps , nextLegacyContext ) ;
628628 }
629629 stopPhaseTimer ( ) ;
630630
@@ -736,6 +736,7 @@ function mountClassInstance(
736736
737737function resumeMountClassInstance (
738738 workInProgress : Fiber ,
739+ hasPendingNewContext : boolean ,
739740 renderExpirationTime : ExpirationTime ,
740741) : boolean {
741742 const ctor = workInProgress . type ;
@@ -746,8 +747,11 @@ function resumeMountClassInstance(
746747 instance . props = oldProps ;
747748
748749 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+ ) ;
751755
752756 const getDerivedStateFromProps = ctor . getDerivedStateFromProps ;
753757 const hasNewLifecycles =
@@ -765,12 +769,12 @@ function resumeMountClassInstance(
765769 ( typeof instance . UNSAFE_componentWillReceiveProps === 'function' ||
766770 typeof instance . componentWillReceiveProps === 'function' )
767771 ) {
768- if ( oldProps !== newProps || oldContext !== newContext ) {
772+ if ( oldProps !== newProps || oldContext !== nextLegacyContext ) {
769773 callComponentWillReceiveProps (
770774 workInProgress ,
771775 instance ,
772776 newProps ,
773- newContext ,
777+ nextLegacyContext ,
774778 ) ;
775779 }
776780 }
@@ -794,6 +798,7 @@ function resumeMountClassInstance(
794798 oldProps === newProps &&
795799 oldState === newState &&
796800 ! hasContextChanged ( ) &&
801+ ! hasPendingNewContext &&
797802 ! checkHasForceUpdateAfterProcessing ( )
798803 ) {
799804 // If an update was already in progress, we should schedule an Update
@@ -815,13 +820,14 @@ function resumeMountClassInstance(
815820
816821 const shouldUpdate =
817822 checkHasForceUpdateAfterProcessing ( ) ||
823+ hasPendingNewContext ||
818824 checkShouldComponentUpdate (
819825 workInProgress ,
820826 oldProps ,
821827 newProps ,
822828 oldState ,
823829 newState ,
824- newContext ,
830+ nextLegacyContext ,
825831 ) ;
826832
827833 if ( shouldUpdate ) {
@@ -861,7 +867,7 @@ function resumeMountClassInstance(
861867 // if shouldComponentUpdate returns false.
862868 instance . props = newProps ;
863869 instance . state = newState ;
864- instance . context = newContext ;
870+ instance . context = nextLegacyContext ;
865871
866872 return shouldUpdate ;
867873}
@@ -870,6 +876,7 @@ function resumeMountClassInstance(
870876function updateClassInstance (
871877 current : Fiber ,
872878 workInProgress : Fiber ,
879+ hasPendingNewContext : boolean ,
873880 renderExpirationTime : ExpirationTime ,
874881) : boolean {
875882 const ctor = workInProgress . type ;
@@ -880,8 +887,11 @@ function updateClassInstance(
880887 instance . props = oldProps ;
881888
882889 const oldContext = instance . context ;
883- const newUnmaskedContext = getUnmaskedContext ( workInProgress ) ;
884- const newContext = getMaskedContext ( workInProgress , newUnmaskedContext ) ;
890+ const nextLegacyUnmaskedContext = getUnmaskedContext ( workInProgress ) ;
891+ const nextLegacyContext = getMaskedContext (
892+ workInProgress ,
893+ nextLegacyUnmaskedContext ,
894+ ) ;
885895
886896 const getDerivedStateFromProps = ctor . getDerivedStateFromProps ;
887897 const hasNewLifecycles =
@@ -899,12 +909,12 @@ function updateClassInstance(
899909 ( typeof instance . UNSAFE_componentWillReceiveProps === 'function' ||
900910 typeof instance . componentWillReceiveProps === 'function' )
901911 ) {
902- if ( oldProps !== newProps || oldContext !== newContext ) {
912+ if ( oldProps !== newProps || oldContext !== nextLegacyContext ) {
903913 callComponentWillReceiveProps (
904914 workInProgress ,
905915 instance ,
906916 newProps ,
907- newContext ,
917+ nextLegacyContext ,
908918 ) ;
909919 }
910920 }
@@ -929,6 +939,7 @@ function updateClassInstance(
929939 oldProps === newProps &&
930940 oldState === newState &&
931941 ! hasContextChanged ( ) &&
942+ ! hasPendingNewContext &&
932943 ! checkHasForceUpdateAfterProcessing ( )
933944 ) {
934945 // If an update was already in progress, we should schedule an Update
@@ -963,13 +974,14 @@ function updateClassInstance(
963974
964975 const shouldUpdate =
965976 checkHasForceUpdateAfterProcessing ( ) ||
977+ hasPendingNewContext ||
966978 checkShouldComponentUpdate (
967979 workInProgress ,
968980 oldProps ,
969981 newProps ,
970982 oldState ,
971983 newState ,
972- newContext ,
984+ nextLegacyContext ,
973985 ) ;
974986
975987 if ( shouldUpdate ) {
@@ -982,10 +994,14 @@ function updateClassInstance(
982994 ) {
983995 startPhaseTimer ( workInProgress , 'componentWillUpdate' ) ;
984996 if ( typeof instance . componentWillUpdate === 'function' ) {
985- instance . componentWillUpdate ( newProps , newState , newContext ) ;
997+ instance . componentWillUpdate ( newProps , newState , nextLegacyContext ) ;
986998 }
987999 if ( typeof instance . UNSAFE_componentWillUpdate === 'function' ) {
988- instance . UNSAFE_componentWillUpdate ( newProps , newState , newContext ) ;
1000+ instance . UNSAFE_componentWillUpdate (
1001+ newProps ,
1002+ newState ,
1003+ nextLegacyContext ,
1004+ ) ;
9891005 }
9901006 stopPhaseTimer ( ) ;
9911007 }
@@ -1025,7 +1041,7 @@ function updateClassInstance(
10251041 // if shouldComponentUpdate returns false.
10261042 instance . props = newProps ;
10271043 instance . state = newState ;
1028- instance . context = newContext ;
1044+ instance . context = nextLegacyContext ;
10291045
10301046 return shouldUpdate ;
10311047}
0 commit comments