@@ -50,6 +50,7 @@ import {
5050 computeExpirationForFiber ,
5151 scheduleWork ,
5252} from './ReactFiberScheduler' ;
53+ import { checkForPendingContext } from './ReactFiberNewContext' ;
5354
5455const fakeInternalInstance = { } ;
5556const isArray = Array . isArray ;
@@ -231,7 +232,7 @@ function checkShouldComponentUpdate(
231232 newProps ,
232233 oldState ,
233234 newState ,
234- newContext ,
235+ nextLegacyContext ,
235236) {
236237 const instance = workInProgress . stateNode ;
237238 const ctor = workInProgress . type ;
@@ -240,7 +241,7 @@ function checkShouldComponentUpdate(
240241 const shouldUpdate = instance . shouldComponentUpdate (
241242 newProps ,
242243 newState ,
243- newContext ,
244+ nextLegacyContext ,
244245 ) ;
245246 stopPhaseTimer ( ) ;
246247
@@ -616,15 +617,15 @@ function callComponentWillReceiveProps(
616617 workInProgress ,
617618 instance ,
618619 newProps ,
619- newContext ,
620+ nextLegacyContext ,
620621) {
621622 const oldState = instance . state ;
622623 startPhaseTimer ( workInProgress , 'componentWillReceiveProps' ) ;
623624 if ( typeof instance . componentWillReceiveProps === 'function' ) {
624- instance . componentWillReceiveProps ( newProps , newContext ) ;
625+ instance . componentWillReceiveProps ( newProps , nextLegacyContext ) ;
625626 }
626627 if ( typeof instance . UNSAFE_componentWillReceiveProps === 'function' ) {
627- instance . UNSAFE_componentWillReceiveProps ( newProps , newContext ) ;
628+ instance . UNSAFE_componentWillReceiveProps ( newProps , nextLegacyContext ) ;
628629 }
629630 stopPhaseTimer ( ) ;
630631
@@ -746,8 +747,16 @@ 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+ ) ;
755+
756+ const hasPendingNewContext = checkForPendingContext (
757+ workInProgress ,
758+ renderExpirationTime ,
759+ ) ;
751760
752761 const getDerivedStateFromProps = ctor . getDerivedStateFromProps ;
753762 const hasNewLifecycles =
@@ -765,12 +774,12 @@ function resumeMountClassInstance(
765774 ( typeof instance . UNSAFE_componentWillReceiveProps === 'function' ||
766775 typeof instance . componentWillReceiveProps === 'function' )
767776 ) {
768- if ( oldProps !== newProps || oldContext !== newContext ) {
777+ if ( oldProps !== newProps || oldContext !== nextLegacyContext ) {
769778 callComponentWillReceiveProps (
770779 workInProgress ,
771780 instance ,
772781 newProps ,
773- newContext ,
782+ nextLegacyContext ,
774783 ) ;
775784 }
776785 }
@@ -794,6 +803,7 @@ function resumeMountClassInstance(
794803 oldProps === newProps &&
795804 oldState === newState &&
796805 ! hasContextChanged ( ) &&
806+ ! hasPendingNewContext &&
797807 ! checkHasForceUpdateAfterProcessing ( )
798808 ) {
799809 // If an update was already in progress, we should schedule an Update
@@ -815,13 +825,14 @@ function resumeMountClassInstance(
815825
816826 const shouldUpdate =
817827 checkHasForceUpdateAfterProcessing ( ) ||
828+ hasPendingNewContext ||
818829 checkShouldComponentUpdate (
819830 workInProgress ,
820831 oldProps ,
821832 newProps ,
822833 oldState ,
823834 newState ,
824- newContext ,
835+ nextLegacyContext ,
825836 ) ;
826837
827838 if ( shouldUpdate ) {
@@ -861,7 +872,7 @@ function resumeMountClassInstance(
861872 // if shouldComponentUpdate returns false.
862873 instance . props = newProps ;
863874 instance . state = newState ;
864- instance . context = newContext ;
875+ instance . context = nextLegacyContext ;
865876
866877 return shouldUpdate ;
867878}
@@ -880,8 +891,16 @@ function updateClassInstance(
880891 instance . props = oldProps ;
881892
882893 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+ ) ;
885904
886905 const getDerivedStateFromProps = ctor . getDerivedStateFromProps ;
887906 const hasNewLifecycles =
@@ -899,12 +918,12 @@ function updateClassInstance(
899918 ( typeof instance . UNSAFE_componentWillReceiveProps === 'function' ||
900919 typeof instance . componentWillReceiveProps === 'function' )
901920 ) {
902- if ( oldProps !== newProps || oldContext !== newContext ) {
921+ if ( oldProps !== newProps || oldContext !== nextLegacyContext ) {
903922 callComponentWillReceiveProps (
904923 workInProgress ,
905924 instance ,
906925 newProps ,
907- newContext ,
926+ nextLegacyContext ,
908927 ) ;
909928 }
910929 }
@@ -929,6 +948,7 @@ function updateClassInstance(
929948 oldProps === newProps &&
930949 oldState === newState &&
931950 ! hasContextChanged ( ) &&
951+ ! hasPendingNewContext &&
932952 ! checkHasForceUpdateAfterProcessing ( )
933953 ) {
934954 // If an update was already in progress, we should schedule an Update
@@ -963,13 +983,14 @@ function updateClassInstance(
963983
964984 const shouldUpdate =
965985 checkHasForceUpdateAfterProcessing ( ) ||
986+ hasPendingNewContext ||
966987 checkShouldComponentUpdate (
967988 workInProgress ,
968989 oldProps ,
969990 newProps ,
970991 oldState ,
971992 newState ,
972- newContext ,
993+ nextLegacyContext ,
973994 ) ;
974995
975996 if ( shouldUpdate ) {
@@ -982,10 +1003,14 @@ function updateClassInstance(
9821003 ) {
9831004 startPhaseTimer ( workInProgress , 'componentWillUpdate' ) ;
9841005 if ( typeof instance . componentWillUpdate === 'function' ) {
985- instance . componentWillUpdate ( newProps , newState , newContext ) ;
1006+ instance . componentWillUpdate ( newProps , newState , nextLegacyContext ) ;
9861007 }
9871008 if ( typeof instance . UNSAFE_componentWillUpdate === 'function' ) {
988- instance . UNSAFE_componentWillUpdate ( newProps , newState , newContext ) ;
1009+ instance . UNSAFE_componentWillUpdate (
1010+ newProps ,
1011+ newState ,
1012+ nextLegacyContext ,
1013+ ) ;
9891014 }
9901015 stopPhaseTimer ( ) ;
9911016 }
@@ -1025,7 +1050,7 @@ function updateClassInstance(
10251050 // if shouldComponentUpdate returns false.
10261051 instance . props = newProps ;
10271052 instance . state = newState ;
1028- instance . context = newContext ;
1053+ instance . context = nextLegacyContext ;
10291054
10301055 return shouldUpdate ;
10311056}
0 commit comments