Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up infra for react-reconciler fork #18285

Merged
merged 2 commits into from Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
840 changes: 126 additions & 714 deletions packages/react-reconciler/src/ReactFiberReconciler.js

Large diffs are not rendered by default.

727 changes: 727 additions & 0 deletions packages/react-reconciler/src/ReactFiberReconciler.old.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/shared/ReactFeatureFlags.js
Expand Up @@ -111,6 +111,8 @@ export const warnAboutSpreadingKeyToJSX = false;
// Internal-only attempt to debug a React Native issue. See D20130868.
export const throwEarlyForMysteriousError = false;

export const enableNewReconciler = false;

// --------------------------
// Future APIs to be deprecated
// --------------------------
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.native-fb.js
Expand Up @@ -52,6 +52,8 @@ export const enableLegacyFBPrimerSupport = false;
// Internal-only attempt to debug a React Native issue. See D20130868.
export const throwEarlyForMysteriousError = true;

export const enableNewReconciler = false;

// Only used in www builds.
export function addUserTimingListener() {
invariant(false, 'Not implemented.');
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.native-oss.js
Expand Up @@ -51,6 +51,8 @@ export const enableLegacyFBPrimerSupport = false;
// Internal-only attempt to debug a React Native issue. See D20130868.
export const throwEarlyForMysteriousError = false;

export const enableNewReconciler = false;

// Only used in www builds.
export function addUserTimingListener() {
invariant(false, 'Not implemented.');
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.js
Expand Up @@ -51,6 +51,8 @@ export const enableLegacyFBPrimerSupport = false;
// Internal-only attempt to debug a React Native issue. See D20130868.
export const throwEarlyForMysteriousError = false;

export const enableNewReconciler = false;

// Only used in www builds.
export function addUserTimingListener() {
invariant(false, 'Not implemented.');
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
Expand Up @@ -51,6 +51,8 @@ export const enableLegacyFBPrimerSupport = false;
// Internal-only attempt to debug a React Native issue. See D20130868.
export const throwEarlyForMysteriousError = false;

export const enableNewReconciler = false;

// Only used in www builds.
export function addUserTimingListener() {
invariant(false, 'Not implemented.');
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.testing.js
Expand Up @@ -51,6 +51,8 @@ export const enableLegacyFBPrimerSupport = false;
// Internal-only attempt to debug a React Native issue. See D20130868.
export const throwEarlyForMysteriousError = false;

export const enableNewReconciler = false;

// Only used in www builds.
export function addUserTimingListener() {
invariant(false, 'Not implemented.');
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.testing.www.js
Expand Up @@ -51,6 +51,8 @@ export const enableLegacyFBPrimerSupport = !__EXPERIMENTAL__;
// Internal-only attempt to debug a React Native issue. See D20130868.
export const throwEarlyForMysteriousError = false;

export const enableNewReconciler = false;

// Only used in www builds.
export function addUserTimingListener() {
invariant(false, 'Not implemented.');
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.www.js
Expand Up @@ -109,6 +109,11 @@ export const enableLegacyFBPrimerSupport = !__EXPERIMENTAL__;
// Internal-only attempt to debug a React Native issue. See D20130868.
export const throwEarlyForMysteriousError = false;

// Enable forked reconciler. Piggy-backing on the "variant" global so that we
// don't have to add another test dimension. The build system will compile this
// to the correct value.
export const enableNewReconciler = __VARIANT__;

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
type Check<_X, Y: _X, X: Y = _X> = null;
Expand Down
9 changes: 9 additions & 0 deletions scripts/jest/setupHostConfigs.js
Expand Up @@ -2,6 +2,15 @@

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

jest.mock('react-reconciler/src/ReactFiberReconciler', () => {
return require.requireActual(
__VARIANT__
? // TODO: Update this to point to the new module, once it exists
'react-reconciler/src/ReactFiberReconciler.old'
: 'react-reconciler/src/ReactFiberReconciler.old'
);
});

// When testing the custom renderer code path through `react-reconciler`,
// turn the export into a function, and use the argument as host config.
const shimHostConfigPath = 'react-reconciler/src/ReactFiberHostConfig';
Expand Down
12 changes: 8 additions & 4 deletions scripts/rollup/build.js
Expand Up @@ -324,10 +324,11 @@ function getPlugins(
bundleType,
globalName,
moduleType,
pureExternalModules
pureExternalModules,
bundle
) {
const findAndRecordErrorCodes = extractErrorCodes(errorCodeOpts);
const forks = Modules.getForks(bundleType, entry, moduleType);
const forks = Modules.getForks(bundleType, entry, moduleType, bundle);
const isProduction = isProductionBundleType(bundleType);
const isProfiling = isProfilingBundleType(bundleType);
const isUMDBundle =
Expand Down Expand Up @@ -391,7 +392,9 @@ function getPlugins(
__UMD__: isUMDBundle ? 'true' : 'false',
'process.env.NODE_ENV': isProduction ? "'production'" : "'development'",
__EXPERIMENTAL__,
__VARIANT__: false,
// Enable forked reconciler.
// NOTE: I did not put much thought into how to configure this.
__VARIANT__: bundle.enableNewReconciler === true,
}),
// The CommonJS plugin *only* exists to pull "art" into "react-art".
// I'm going to port "art" to ES modules to avoid this problem.
Expand Down Expand Up @@ -578,7 +581,8 @@ async function createBundle(bundle, bundleType) {
bundleType,
bundle.global,
bundle.moduleType,
pureExternalModules
pureExternalModules,
bundle
),
output: {
externalLiveBindings: false,
Expand Down
10 changes: 10 additions & 0 deletions scripts/rollup/bundles.js
Expand Up @@ -95,6 +95,16 @@ const bundles = [
externals: ['react'],
},

/******* React DOM - www - Uses forked reconciler *******/
{
moduleType: RENDERER,
bundleTypes: [FB_WWW_DEV, FB_WWW_PROD, FB_WWW_PROFILING],
entry: 'react-dom',
global: 'ReactDOMForked',
enableNewReconciler: true,
externals: ['react'],
},

/******* Test Utils *******/
{
moduleType: RENDERER_UTILS,
Expand Down
21 changes: 21 additions & 0 deletions scripts/rollup/forks.js
Expand Up @@ -246,6 +246,27 @@ const forks = Object.freeze({
}
},

'react-reconciler/src/ReactFiberReconciler': (
bundleType,
entry,
dependencies,
moduleType,
bundle
) => {
if (bundle.enableNewReconciler) {
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
// Use the forked version of the reconciler
// TODO: Update this to point to the new module, once it exists
return 'react-reconciler/src/ReactFiberReconciler.old.js';
}
}
// Otherwise, use the non-forked version.
return 'react-reconciler/src/ReactFiberReconciler.old.js';
},

// Different dialogs for caught errors.
'react-reconciler/src/ReactFiberErrorDialog': (bundleType, entry) => {
switch (bundleType) {
Expand Down
5 changes: 3 additions & 2 deletions scripts/rollup/modules.js
Expand Up @@ -60,15 +60,16 @@ function getDependencies(bundleType, entry) {
}

// Hijacks some modules for optimization and integration reasons.
function getForks(bundleType, entry, moduleType) {
function getForks(bundleType, entry, moduleType, bundle) {
const forksForBundle = {};
Object.keys(forks).forEach(srcModule => {
const dependencies = getDependencies(bundleType, entry);
const targetModule = forks[srcModule](
bundleType,
entry,
dependencies,
moduleType
moduleType,
bundle
);
if (targetModule === null) {
return;
Expand Down