From 8777b44e982e7ddedda62aee02f1fd370795db44 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Thu, 13 Feb 2020 20:33:53 +0000 Subject: [PATCH] Add Modern WWW build (#18028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Build both stable and experimental WWW builds * Flip already experimental WWW flags to true * Remove FB-specific internals from modern FB builds We think we're not going to need these. * Disable classic features in modern WWW builds * Disable legacy ReactDOM API for modern WWW build * Don’t include user timing in prod * Fix bad copy paste and add missing flags to test renderer * Add testing WWW feature flag file We need it because WWW has a different meaning of experimental now. --- packages/react-dom/src/client/ReactDOM.js | 14 +++-- packages/react-dom/src/client/ReactDOMFB.js | 31 ++++++---- packages/react-reconciler/src/ReactFiber.js | 8 ++- packages/shared/ReactFeatureFlags.js | 3 + .../forks/ReactFeatureFlags.native-fb.js | 5 +- .../forks/ReactFeatureFlags.native-oss.js | 5 +- .../forks/ReactFeatureFlags.persistent.js | 5 +- .../forks/ReactFeatureFlags.test-renderer.js | 5 +- .../ReactFeatureFlags.test-renderer.www.js | 7 ++- .../shared/forks/ReactFeatureFlags.testing.js | 5 +- .../forks/ReactFeatureFlags.testing.www.js | 62 +++++++++++++++++++ .../shared/forks/ReactFeatureFlags.www.js | 27 ++++---- scripts/rollup/build.js | 8 +-- scripts/rollup/forks.js | 7 ++- 14 files changed, 143 insertions(+), 49 deletions(-) create mode 100644 packages/shared/forks/ReactFeatureFlags.testing.www.js diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index ee54497f232af..f542aa752b1f5 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -56,6 +56,7 @@ import ReactVersion from 'shared/ReactVersion'; import invariant from 'shared/invariant'; import { exposeConcurrentModeAPIs, + disableLegacyReactDOMAPIs, disableUnstableCreatePortal, disableUnstableRenderSubtreeIntoContainer, warnUnstableRenderSubtreeIntoContainer, @@ -133,12 +134,6 @@ function createPortal( const ReactDOM: Object = { createPortal, - // Legacy - findDOMNode, - hydrate, - render, - unmountComponentAtNode, - unstable_batchedUpdates: batchedUpdates, flushSync: flushSync, @@ -166,6 +161,13 @@ const ReactDOM: Object = { version: ReactVersion, }; +if (!disableLegacyReactDOMAPIs) { + ReactDOM.findDOMNode = findDOMNode; + ReactDOM.hydrate = hydrate; + ReactDOM.render = render; + ReactDOM.unmountComponentAtNode = unmountComponentAtNode; +} + if (exposeConcurrentModeAPIs) { ReactDOM.createRoot = createRoot; ReactDOM.createBlockingRoot = createBlockingRoot; diff --git a/packages/react-dom/src/client/ReactDOMFB.js b/packages/react-dom/src/client/ReactDOMFB.js index 877c7d2ea3f15..5acb45d81e9bb 100644 --- a/packages/react-dom/src/client/ReactDOMFB.js +++ b/packages/react-dom/src/client/ReactDOMFB.js @@ -13,19 +13,24 @@ import ReactDOM from './ReactDOM'; import {isEnabled} from '../events/ReactBrowserEventEmitter'; import {getClosestInstanceFromNode} from './ReactDOMComponentTree'; -Object.assign( - (ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: any), - { - // These are real internal dependencies that are trickier to remove: - ReactBrowserEventEmitter: { - isEnabled, +if (__EXPERIMENTAL__) { + // This is a modern WWW build. + // It should be the same as open source. Don't add new things here. +} else { + // For classic WWW builds, include a few internals that are already in use. + Object.assign( + (ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: any), + { + ReactBrowserEventEmitter: { + isEnabled, + }, + ReactDOMComponentTree: { + getClosestInstanceFromNode, + }, + // Perf experiment + addUserTimingListener, }, - ReactDOMComponentTree: { - getClosestInstanceFromNode, - }, - // Perf experiment - addUserTimingListener, - }, -); + ); +} export default ReactDOM; diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index 792cd1def4db5..a51116219927f 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -425,7 +425,9 @@ export function createWorkInProgress( if (__DEV__) { // DEV-only fields - workInProgress._debugID = current._debugID; + if (enableUserTimingAPI) { + workInProgress._debugID = current._debugID; + } workInProgress._debugSource = current._debugSource; workInProgress._debugOwner = current._debugOwner; workInProgress._debugHookTypes = current._debugHookTypes; @@ -958,7 +960,9 @@ export function assignFiberPropertiesInDEV( target.selfBaseDuration = source.selfBaseDuration; target.treeBaseDuration = source.treeBaseDuration; } - target._debugID = source._debugID; + if (enableUserTimingAPI) { + target._debugID = source._debugID; + } target._debugSource = source._debugSource; target._debugOwner = source._debugOwner; target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming; diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index c73997f1dcef9..0dd89f7674a5b 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -114,6 +114,9 @@ export const disableLegacyContext = false; // Disables React.createFactory export const disableCreateFactory = false; +// Disables hydrate, render, findDOMNode, unmountComponentAtNode +export const disableLegacyReactDOMAPIs = false; + // Disables children for