Skip to content

Commit 010c4ed

Browse files
committed
Use module pattern so context stack is isolated per renderer
1 parent ad9544f commit 010c4ed

10 files changed

+510
-393
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type {HostConfig} from 'react-reconciler';
1111
import type {ReactProviderType, ReactContext} from 'shared/ReactTypes';
1212
import type {Fiber} from 'react-reconciler/src/ReactFiber';
1313
import type {HostContext} from './ReactFiberHostContext';
14+
import type {LegacyContext} from './ReactFiberContext';
15+
import type {NewContext} from './ReactFiberNewContext';
1416
import type {HydrationContext} from './ReactFiberHydrationContext';
1517
import type {FiberRoot} from './ReactFiberRoot';
1618
import type {ExpirationTime} from './ReactFiberExpirationTime';
@@ -56,15 +58,6 @@ import {
5658
cloneChildFibers,
5759
} from './ReactChildFiber';
5860
import {processUpdateQueue} from './ReactFiberUpdateQueue';
59-
import {
60-
getMaskedContext,
61-
getUnmaskedContext,
62-
hasContextChanged as hasLegacyContextChanged,
63-
pushContextProvider as pushLegacyContextProvider,
64-
pushTopLevelContextObject,
65-
invalidateContextProvider,
66-
} from './ReactFiberContext';
67-
import {pushProvider} from './ReactFiberNewContext';
6861
import {NoWork, Never} from './ReactFiberExpirationTime';
6962
import {AsyncMode, StrictMode} from './ReactTypeOfMode';
7063
import MAX_SIGNED_31_BIT_INT from './maxSigned31BitInt';
@@ -82,6 +75,8 @@ if (__DEV__) {
8275
export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
8376
config: HostConfig<T, P, I, TI, HI, PI, C, CC, CX, PL>,
8477
hostContext: HostContext<C, CX>,
78+
legacyContext: LegacyContext,
79+
newContext: NewContext,
8580
hydrationContext: HydrationContext<C, CX>,
8681
scheduleWork: (fiber: Fiber, expirationTime: ExpirationTime) => void,
8782
computeExpirationForFiber: (fiber: Fiber) => ExpirationTime,
@@ -90,6 +85,17 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
9085

9186
const {pushHostContext, pushHostContainer} = hostContext;
9287

88+
const {pushProvider} = newContext;
89+
90+
const {
91+
getMaskedContext,
92+
getUnmaskedContext,
93+
hasContextChanged: hasLegacyContextChanged,
94+
pushContextProvider: pushLegacyContextProvider,
95+
pushTopLevelContextObject,
96+
invalidateContextProvider,
97+
} = legacyContext;
98+
9399
const {
94100
enterHydrationState,
95101
resetHydrationState,
@@ -104,6 +110,7 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
104110
resumeMountClassInstance,
105111
updateClassInstance,
106112
} = ReactFiberClassComponent(
113+
legacyContext,
107114
scheduleWork,
108115
computeExpirationForFiber,
109116
memoizeProps,

packages/react-reconciler/src/ReactFiberClassComponent.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import type {Fiber} from './ReactFiber';
1111
import type {ExpirationTime} from './ReactFiberExpirationTime';
12+
import type {LegacyContext} from './ReactFiberContext';
1213
import type {CapturedValue} from './ReactCapturedValue';
1314

1415
import {Update} from 'shared/ReactTypeOfSideEffect';
@@ -29,17 +30,10 @@ import warning from 'fbjs/lib/warning';
2930

3031
import {startPhaseTimer, stopPhaseTimer} from './ReactDebugFiberPerf';
3132
import {StrictMode} from './ReactTypeOfMode';
32-
import {
33-
cacheContext,
34-
getMaskedContext,
35-
getUnmaskedContext,
36-
isContextConsumer,
37-
} from './ReactFiberContext';
3833
import {
3934
insertUpdateIntoFiber,
4035
processUpdateQueue,
4136
} from './ReactFiberUpdateQueue';
42-
import {hasContextChanged} from './ReactFiberContext';
4337

4438
const fakeInternalInstance = {};
4539
const isArray = Array.isArray;
@@ -110,11 +104,20 @@ function callGetDerivedStateFromCatch(ctor: any, capturedValues: Array<mixed>) {
110104
}
111105

112106
export default function(
107+
legacyContext: LegacyContext,
113108
scheduleWork: (fiber: Fiber, expirationTime: ExpirationTime) => void,
114109
computeExpirationForFiber: (fiber: Fiber) => ExpirationTime,
115110
memoizeProps: (workInProgress: Fiber, props: any) => void,
116111
memoizeState: (workInProgress: Fiber, state: any) => void,
117112
) {
113+
const {
114+
cacheContext,
115+
getMaskedContext,
116+
getUnmaskedContext,
117+
isContextConsumer,
118+
hasContextChanged,
119+
} = legacyContext;
120+
118121
// Class component state updater
119122
const updater = {
120123
isMounted,

packages/react-reconciler/src/ReactFiberCompleteWork.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type {HostConfig} from 'react-reconciler';
1111
import type {Fiber} from './ReactFiber';
1212
import type {ExpirationTime} from './ReactFiberExpirationTime';
1313
import type {HostContext} from './ReactFiberHostContext';
14+
import type {LegacyContext} from './ReactFiberContext';
15+
import type {NewContext} from './ReactFiberNewContext';
1416
import type {HydrationContext} from './ReactFiberHydrationContext';
1517
import type {FiberRoot} from './ReactFiberRoot';
1618

@@ -45,15 +47,12 @@ import {
4547
import invariant from 'fbjs/lib/invariant';
4648

4749
import {reconcileChildFibers} from './ReactChildFiber';
48-
import {
49-
popContextProvider as popLegacyContextProvider,
50-
popTopLevelContextObject as popTopLevelLegacyContextObject,
51-
} from './ReactFiberContext';
52-
import {popProvider} from './ReactFiberNewContext';
5350

5451
export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
5552
config: HostConfig<T, P, I, TI, HI, PI, C, CC, CX, PL>,
5653
hostContext: HostContext<C, CX>,
54+
legacyContext: LegacyContext,
55+
newContext: NewContext,
5756
hydrationContext: HydrationContext<C, CX>,
5857
) {
5958
const {
@@ -73,6 +72,13 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
7372
popHostContainer,
7473
} = hostContext;
7574

75+
const {
76+
popContextProvider: popLegacyContextProvider,
77+
popTopLevelContextObject: popTopLevelLegacyContextObject,
78+
} = legacyContext;
79+
80+
const {popProvider} = newContext;
81+
7682
const {
7783
prepareToHydrateHostInstance,
7884
prepareToHydrateHostTextInstance,

0 commit comments

Comments
 (0)