Skip to content

Commit 95e54ae

Browse files
committed
Set up infra for react-reconciler fork
We're planning to land some significant refactors of the reconciler. We want to be able to gradually roll out the new implementation side-by- side with the existing one. So we'll create a short lived fork of the react-reconciler package. Once the new implementation has stabilized, we'll delete the old implementation and promote the new one. This means, for as long as the fork exists, we'll need to maintain two separate implementations. This sounds painful, but since the forks will still be largely the same, most changes will not require two separate implementations. In practice, you'll implement the change in the old fork and then copy paste it to the new one. This commit only sets up the build and testing infrastructure. It does not actually fork any modules. I'll do that in subsequent PRs. The forked version of the reconciler will be used to build a special version of React DOM. I've called this build ReactDOMForked. It's only built for www; there's no open source version. The new reconciler is disabled by default. It's enabled in the `yarn test-www-variant` command. The reconciler fork isn't really related to the "variant" feature of the www builds, but I'm piggy backing on that concept to avoid having to add yet another testing dimension.
1 parent 9fd68de commit 95e54ae

14 files changed

+209
-6
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import {enableNewReconciler} from 'shared/ReactFeatureFlags';
11+
12+
// The entry file imports either the old or new version of the reconciler.
13+
// During build and testing, this indirection is always shimmed with the actual
14+
// modules, otherwise both reconcilers would be initialized. So this is really
15+
// only here for Flow purposes.
16+
17+
import {
18+
createContainer as createContainer_old,
19+
updateContainer as updateContainer_old,
20+
batchedEventUpdates as batchedEventUpdates_old,
21+
batchedUpdates as batchedUpdates_old,
22+
unbatchedUpdates as unbatchedUpdates_old,
23+
deferredUpdates as deferredUpdates_old,
24+
syncUpdates as syncUpdates_old,
25+
discreteUpdates as discreteUpdates_old,
26+
flushDiscreteUpdates as flushDiscreteUpdates_old,
27+
flushControlled as flushControlled_old,
28+
flushSync as flushSync_old,
29+
flushPassiveEffects as flushPassiveEffects_old,
30+
IsThisRendererActing as IsThisRendererActing_old,
31+
getPublicRootInstance as getPublicRootInstance_old,
32+
attemptSynchronousHydration as attemptSynchronousHydration_old,
33+
attemptUserBlockingHydration as attemptUserBlockingHydration_old,
34+
attemptContinuousHydration as attemptContinuousHydration_old,
35+
attemptHydrationAtCurrentPriority as attemptHydrationAtCurrentPriority_old,
36+
findHostInstance as findHostInstance_old,
37+
findHostInstanceWithWarning as findHostInstanceWithWarning_old,
38+
findHostInstanceWithNoPortals as findHostInstanceWithNoPortals_old,
39+
shouldSuspend as shouldSuspend_old,
40+
injectIntoDevTools as injectIntoDevTools_old,
41+
act as act_old,
42+
} from './ReactFiberReconciler.old';
43+
44+
// TODO: Update these to point to the fork.
45+
import {
46+
createContainer as createContainer_new,
47+
updateContainer as updateContainer_new,
48+
batchedEventUpdates as batchedEventUpdates_new,
49+
batchedUpdates as batchedUpdates_new,
50+
unbatchedUpdates as unbatchedUpdates_new,
51+
deferredUpdates as deferredUpdates_new,
52+
syncUpdates as syncUpdates_new,
53+
discreteUpdates as discreteUpdates_new,
54+
flushDiscreteUpdates as flushDiscreteUpdates_new,
55+
flushControlled as flushControlled_new,
56+
flushSync as flushSync_new,
57+
flushPassiveEffects as flushPassiveEffects_new,
58+
IsThisRendererActing as IsThisRendererActing_new,
59+
getPublicRootInstance as getPublicRootInstance_new,
60+
attemptSynchronousHydration as attemptSynchronousHydration_new,
61+
attemptUserBlockingHydration as attemptUserBlockingHydration_new,
62+
attemptContinuousHydration as attemptContinuousHydration_new,
63+
attemptHydrationAtCurrentPriority as attemptHydrationAtCurrentPriority_new,
64+
findHostInstance as findHostInstance_new,
65+
findHostInstanceWithWarning as findHostInstanceWithWarning_new,
66+
findHostInstanceWithNoPortals as findHostInstanceWithNoPortals_new,
67+
shouldSuspend as shouldSuspend_new,
68+
injectIntoDevTools as injectIntoDevTools_new,
69+
act as act_new,
70+
} from './ReactFiberReconciler.old';
71+
72+
export const createContainer = enableNewReconciler
73+
? createContainer_new
74+
: createContainer_old;
75+
export const updateContainer = enableNewReconciler
76+
? updateContainer_new
77+
: updateContainer_old;
78+
export const batchedEventUpdates = enableNewReconciler
79+
? batchedEventUpdates_new
80+
: batchedEventUpdates_old;
81+
export const batchedUpdates = enableNewReconciler
82+
? batchedUpdates_new
83+
: batchedUpdates_old;
84+
export const unbatchedUpdates = enableNewReconciler
85+
? unbatchedUpdates_new
86+
: unbatchedUpdates_old;
87+
export const deferredUpdates = enableNewReconciler
88+
? deferredUpdates_new
89+
: deferredUpdates_old;
90+
export const syncUpdates = enableNewReconciler
91+
? syncUpdates_new
92+
: syncUpdates_old;
93+
export const discreteUpdates = enableNewReconciler
94+
? discreteUpdates_new
95+
: discreteUpdates_old;
96+
export const flushDiscreteUpdates = enableNewReconciler
97+
? flushDiscreteUpdates_new
98+
: flushDiscreteUpdates_old;
99+
export const flushControlled = enableNewReconciler
100+
? flushControlled_new
101+
: flushControlled_old;
102+
export const flushSync = enableNewReconciler ? flushSync_new : flushSync_old;
103+
export const flushPassiveEffects = enableNewReconciler
104+
? flushPassiveEffects_new
105+
: flushPassiveEffects_old;
106+
export const IsThisRendererActing = enableNewReconciler
107+
? IsThisRendererActing_new
108+
: IsThisRendererActing_old;
109+
export const getPublicRootInstance = enableNewReconciler
110+
? getPublicRootInstance_new
111+
: getPublicRootInstance_old;
112+
export const attemptSynchronousHydration = enableNewReconciler
113+
? attemptSynchronousHydration_new
114+
: attemptSynchronousHydration_old;
115+
export const attemptUserBlockingHydration = enableNewReconciler
116+
? attemptUserBlockingHydration_new
117+
: attemptUserBlockingHydration_old;
118+
export const attemptContinuousHydration = enableNewReconciler
119+
? attemptContinuousHydration_new
120+
: attemptContinuousHydration_old;
121+
export const attemptHydrationAtCurrentPriority = enableNewReconciler
122+
? attemptHydrationAtCurrentPriority_new
123+
: attemptHydrationAtCurrentPriority_old;
124+
export const findHostInstance = enableNewReconciler
125+
? findHostInstance_new
126+
: findHostInstance_old;
127+
export const findHostInstanceWithWarning = enableNewReconciler
128+
? findHostInstanceWithWarning_new
129+
: findHostInstanceWithWarning_old;
130+
export const findHostInstanceWithNoPortals = enableNewReconciler
131+
? findHostInstanceWithNoPortals_new
132+
: findHostInstanceWithNoPortals_old;
133+
export const shouldSuspend = enableNewReconciler
134+
? shouldSuspend_new
135+
: shouldSuspend_old;
136+
export const injectIntoDevTools = enableNewReconciler
137+
? injectIntoDevTools_new
138+
: injectIntoDevTools_old;
139+
export const act = enableNewReconciler ? act_new : act_old;

packages/shared/ReactFeatureFlags.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export const warnAboutSpreadingKeyToJSX = false;
111111
// Internal-only attempt to debug a React Native issue. See D20130868.
112112
export const throwEarlyForMysteriousError = false;
113113

114+
export const enableNewReconciler = false;
115+
114116
// --------------------------
115117
// Future APIs to be deprecated
116118
// --------------------------

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export const enableLegacyFBPrimerSupport = false;
5252
// Internal-only attempt to debug a React Native issue. See D20130868.
5353
export const throwEarlyForMysteriousError = true;
5454

55+
export const enableNewReconciler = false;
56+
5557
// Only used in www builds.
5658
export function addUserTimingListener() {
5759
invariant(false, 'Not implemented.');

packages/shared/forks/ReactFeatureFlags.native-oss.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export const enableLegacyFBPrimerSupport = false;
5151
// Internal-only attempt to debug a React Native issue. See D20130868.
5252
export const throwEarlyForMysteriousError = false;
5353

54+
export const enableNewReconciler = false;
55+
5456
// Only used in www builds.
5557
export function addUserTimingListener() {
5658
invariant(false, 'Not implemented.');

packages/shared/forks/ReactFeatureFlags.test-renderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export const enableLegacyFBPrimerSupport = false;
5151
// Internal-only attempt to debug a React Native issue. See D20130868.
5252
export const throwEarlyForMysteriousError = false;
5353

54+
export const enableNewReconciler = false;
55+
5456
// Only used in www builds.
5557
export function addUserTimingListener() {
5658
invariant(false, 'Not implemented.');

packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export const enableLegacyFBPrimerSupport = false;
5151
// Internal-only attempt to debug a React Native issue. See D20130868.
5252
export const throwEarlyForMysteriousError = false;
5353

54+
export const enableNewReconciler = false;
55+
5456
// Only used in www builds.
5557
export function addUserTimingListener() {
5658
invariant(false, 'Not implemented.');

packages/shared/forks/ReactFeatureFlags.testing.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export const enableLegacyFBPrimerSupport = false;
5151
// Internal-only attempt to debug a React Native issue. See D20130868.
5252
export const throwEarlyForMysteriousError = false;
5353

54+
export const enableNewReconciler = false;
55+
5456
// Only used in www builds.
5557
export function addUserTimingListener() {
5658
invariant(false, 'Not implemented.');

packages/shared/forks/ReactFeatureFlags.testing.www.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export const enableLegacyFBPrimerSupport = !__EXPERIMENTAL__;
5151
// Internal-only attempt to debug a React Native issue. See D20130868.
5252
export const throwEarlyForMysteriousError = false;
5353

54+
export const enableNewReconciler = false;
55+
5456
// Only used in www builds.
5557
export function addUserTimingListener() {
5658
invariant(false, 'Not implemented.');

packages/shared/forks/ReactFeatureFlags.www.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ export const enableLegacyFBPrimerSupport = !__EXPERIMENTAL__;
109109
// Internal-only attempt to debug a React Native issue. See D20130868.
110110
export const throwEarlyForMysteriousError = false;
111111

112+
// Enable forked reconciler. Piggy-backing on the "variant" global so that we
113+
// don't have to add another test dimension. The build system will compile this
114+
// to the correct value.
115+
export const enableNewReconciler = __VARIANT__;
116+
112117
// Flow magic to verify the exports of this file match the original version.
113118
// eslint-disable-next-line no-unused-vars
114119
type Check<_X, Y: _X, X: Y = _X> = null;

scripts/jest/setupHostConfigs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
const inlinedHostConfigs = require('../shared/inlinedHostConfigs');
44

5+
jest.mock('react-reconciler/src/ReactFiberReconciler', () => {
6+
return require.requireActual(
7+
__VARIANT__
8+
? // TODO: Update this to point to the new module, once it exists
9+
'react-reconciler/src/ReactFiberReconciler.old'
10+
: 'react-reconciler/src/ReactFiberReconciler.old'
11+
);
12+
});
13+
514
// When testing the custom renderer code path through `react-reconciler`,
615
// turn the export into a function, and use the argument as host config.
716
const shimHostConfigPath = 'react-reconciler/src/ReactFiberHostConfig';

0 commit comments

Comments
 (0)