Remove unused lastFullyObservedContext (#31435)
Sophie Alpert committed
Nov 6, 2024 at 07:35 UTC
66855b96378daedb1405e83f2365e0d90966ea0e
1 file changed
+66
-77
packages/react-reconciler/src/ReactFiberNewContext.js
+66
-77
@@ -74,7 +74,6 @@ let lastContextDependency:
74
| ContextDependency<mixed>
75
| ContextDependencyWithSelect<mixed>
76
| null = null;
77
-let lastFullyObservedContext: ReactContext<any> | null = null;
77
78
let isDisallowedContextReadInDEV: boolean = false;
79
@@ -83,7 +82,6 @@ export function resetContextDependencies(): void {
82
// cannot be called outside the render phase.
83
currentlyRenderingFiber = null;
84
lastContextDependency = null;
86
- lastFullyObservedContext = null;
85
if (__DEV__) {
86
isDisallowedContextReadInDEV = false;
87
}
@@ -730,7 +728,6 @@ export function prepareToReadContext(
728
): void {
729
currentlyRenderingFiber = workInProgress;
730
lastContextDependency = null;
733
- lastFullyObservedContext = null;
731
732
const dependencies = workInProgress.dependencies;
733
if (dependencies !== null) {
@@ -802,46 +799,42 @@ function readContextForConsumer_withSelect<C>(
799
? context._currentValue
800
: context._currentValue2;
801
805
- if (lastFullyObservedContext === context) {
806
- // Nothing to do. We already observe everything in this context.
807
- } else {
808
- const contextItem = {
809
- context: ((context: any): ReactContext<mixed>),
810
- memoizedValue: value,
811
- next: null,
812
- select: ((select: any): (context: mixed) => Array<mixed>),
813
- lastSelectedValue: select(value),
814
- };
815
-
816
- if (lastContextDependency === null) {
817
- if (consumer === null) {
818
- throw new Error(
819
- 'Context can only be read while React is rendering. ' +
820
- 'In classes, you can read it in the render method or getDerivedStateFromProps. ' +
821
- 'In function components, you can read it directly in the function body, but not ' +
822
- 'inside Hooks like useReducer() or useMemo().',
823
- );
824
- }
802
+ const contextItem = {
803
+ context: ((context: any): ReactContext<mixed>),
804
+ memoizedValue: value,
805
+ next: null,
806
+ select: ((select: any): (context: mixed) => Array<mixed>),
807
+ lastSelectedValue: select(value),
808
+ };
809
+
810
+ if (lastContextDependency === null) {
811
+ if (consumer === null) {
812
+ throw new Error(
813
+ 'Context can only be read while React is rendering. ' +
814
+ 'In classes, you can read it in the render method or getDerivedStateFromProps. ' +
815
+ 'In function components, you can read it directly in the function body, but not ' +
816
+ 'inside Hooks like useReducer() or useMemo().',
817
+ );
818
+ }
819
826
- // This is the first dependency for this component. Create a new list.
827
- lastContextDependency = contextItem;
828
- consumer.dependencies = __DEV__
829
- ? {
830
- lanes: NoLanes,
831
- firstContext: contextItem,
832
- _debugThenableState: null,
833
- }
834
- : {
835
- lanes: NoLanes,
836
- firstContext: contextItem,
837
- };
838
- if (enableLazyContextPropagation) {
839
- consumer.flags |= NeedsPropagation;
840
- }
841
- } else {
842
- // Append a new context item.
843
- lastContextDependency = lastContextDependency.next = contextItem;
820
+ // This is the first dependency for this component. Create a new list.
821
+ lastContextDependency = contextItem;
822
+ consumer.dependencies = __DEV__
823
+ ? {
824
+ lanes: NoLanes,
825
+ firstContext: contextItem,
826
+ _debugThenableState: null,
827
+ }
828
+ : {
829
+ lanes: NoLanes,
830
+ firstContext: contextItem,
831
+ };
832
+ if (enableLazyContextPropagation) {
833
+ consumer.flags |= NeedsPropagation;
834
}
835
+ } else {
836
+ // Append a new context item.
837
+ lastContextDependency = lastContextDependency.next = contextItem;
838
}
839
return value;
840
}
@@ -854,44 +847,40 @@ function readContextForConsumer<C>(
847
? context._currentValue
848
: context._currentValue2;
849
857
- if (lastFullyObservedContext === context) {
858
- // Nothing to do. We already observe everything in this context.
859
- } else {
860
- const contextItem = {
861
- context: ((context: any): ReactContext<mixed>),
862
- memoizedValue: value,
863
- next: null,
864
- };
865
-
866
- if (lastContextDependency === null) {
867
- if (consumer === null) {
868
- throw new Error(
869
- 'Context can only be read while React is rendering. ' +
870
- 'In classes, you can read it in the render method or getDerivedStateFromProps. ' +
871
- 'In function components, you can read it directly in the function body, but not ' +
872
- 'inside Hooks like useReducer() or useMemo().',
873
- );
874
- }
850
+ const contextItem = {
851
+ context: ((context: any): ReactContext<mixed>),
852
+ memoizedValue: value,
853
+ next: null,
854
+ };
855
876
- // This is the first dependency for this component. Create a new list.
877
- lastContextDependency = contextItem;
878
- consumer.dependencies = __DEV__
879
- ? {
880
- lanes: NoLanes,
881
- firstContext: contextItem,
882
- _debugThenableState: null,
883
- }
884
- : {
885
- lanes: NoLanes,
886
- firstContext: contextItem,
887
- };
888
- if (enableLazyContextPropagation) {
889
- consumer.flags |= NeedsPropagation;
890
- }
891
- } else {
892
- // Append a new context item.
893
- lastContextDependency = lastContextDependency.next = contextItem;
856
+ if (lastContextDependency === null) {
857
+ if (consumer === null) {
858
+ throw new Error(
859
+ 'Context can only be read while React is rendering. ' +
860
+ 'In classes, you can read it in the render method or getDerivedStateFromProps. ' +
861
+ 'In function components, you can read it directly in the function body, but not ' +
862
+ 'inside Hooks like useReducer() or useMemo().',
863
+ );
864
+ }
865
+
866
+ // This is the first dependency for this component. Create a new list.
867
+ lastContextDependency = contextItem;
868
+ consumer.dependencies = __DEV__
869
+ ? {
870
+ lanes: NoLanes,
871
+ firstContext: contextItem,
872
+ _debugThenableState: null,
873
+ }
874
+ : {
875
+ lanes: NoLanes,
876
+ firstContext: contextItem,
877
+ };
878
+ if (enableLazyContextPropagation) {
879
+ consumer.flags |= NeedsPropagation;
880
}
881
+ } else {
882
+ // Append a new context item.
883
+ lastContextDependency = lastContextDependency.next = contextItem;
884
}
885
return value;
886
}