From 480b96ebb171dd9876f989b3bd924fcc34e0db0a Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 24 Mar 2021 01:48:27 +0000 Subject: [PATCH 1/2] Add react-reconciler/constants entry point --- packages/react-noop-renderer/src/createReactNoop.js | 4 +--- packages/react-reconciler/README.md | 4 ++-- packages/react-reconciler/constants.js | 12 ++++++++++++ packages/react-reconciler/npm/constants.js | 7 +++++++ packages/react-reconciler/package.json | 1 + scripts/rollup/bundles.js | 11 ++++++++++- 6 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 packages/react-reconciler/constants.js create mode 100644 packages/react-reconciler/npm/constants.js diff --git a/packages/react-noop-renderer/src/createReactNoop.js b/packages/react-noop-renderer/src/createReactNoop.js index 6cef4f7ade498..0475088a0a838 100644 --- a/packages/react-noop-renderer/src/createReactNoop.js +++ b/packages/react-noop-renderer/src/createReactNoop.js @@ -22,14 +22,12 @@ import type {RootTag} from 'react-reconciler/src/ReactRootTags'; import * as Scheduler from 'scheduler/unstable_mock'; import {REACT_FRAGMENT_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols'; import {ConcurrentRoot, LegacyRoot} from 'react-reconciler/src/ReactRootTags'; +import {DefaultEventPriority} from 'react-reconciler/constants'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import enqueueTask from 'shared/enqueueTask'; const {IsSomeRendererActing} = ReactSharedInternals; -// TODO: Publish public entry point that exports the event priority constants -const DefaultEventPriority = 8; - type Container = { rootID: string, children: Array, diff --git a/packages/react-reconciler/README.md b/packages/react-reconciler/README.md index 4a0ce2aa427d9..ec15ffd27436d 100644 --- a/packages/react-reconciler/README.md +++ b/packages/react-reconciler/README.md @@ -216,14 +216,14 @@ This is a property (not a function) that should be set to `true` if your rendere #### `getCurrentEventPriority` -To implement this method, you'll need some constants available on the _returned_ `Renderer` object: +To implement this method, you'll need some constants available on the special `react-reconciler/constants` entry point: ```js import { DiscreteEventPriority, ContinuousEventPriority, DefaultEventPriority, -} from './ReactFiberReconciler/src/ReactEventPriorities'; +} from 'react-reconciler/constants'; const HostConfig = { // ... diff --git a/packages/react-reconciler/constants.js b/packages/react-reconciler/constants.js new file mode 100644 index 0000000000000..fba59ba132ec2 --- /dev/null +++ b/packages/react-reconciler/constants.js @@ -0,0 +1,12 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +'use strict'; + +export * from './src/ReactEventPriorities'; diff --git a/packages/react-reconciler/npm/constants.js b/packages/react-reconciler/npm/constants.js new file mode 100644 index 0000000000000..df4f2b61987c0 --- /dev/null +++ b/packages/react-reconciler/npm/constants.js @@ -0,0 +1,7 @@ +'use strict'; + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/react-reconciler-constants.production.min.js'); +} else { + module.exports = require('./cjs/react-reconciler-constants.development.js'); +} diff --git a/packages/react-reconciler/package.json b/packages/react-reconciler/package.json index a6fd3a05a9627..7a681953eeb2e 100644 --- a/packages/react-reconciler/package.json +++ b/packages/react-reconciler/package.json @@ -12,6 +12,7 @@ "LICENSE", "README.md", "build-info.json", + "constants.js", "index.js", "reflection.js", "cjs/" diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index 9c6a8c8a95d86..e37e7bbfe644a 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -604,7 +604,7 @@ const bundles = [ externals: ['react'], }, - /******* Reflection *******/ + /******* Reconciler Reflection *******/ { moduleType: RENDERER_UTILS, bundleTypes: [NODE_DEV, NODE_PROD], @@ -613,6 +613,15 @@ const bundles = [ externals: [], }, + /******* Reconciler Constants *******/ + { + moduleType: RENDERER_UTILS, + bundleTypes: [NODE_DEV, NODE_PROD], + entry: 'react-reconciler/constants', + global: 'ReactReconcilerConstants', + externals: [], + }, + /******* React Is *******/ { bundleTypes: [ From cb2c3cac95b4eb7dbb483fcd39baa59157e31d7a Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 24 Mar 2021 02:00:03 +0000 Subject: [PATCH 2/2] Move root tags to /constants --- .../react-noop-renderer/src/createReactNoop.js | 7 +++++-- packages/react-reconciler/constants.js | 2 +- .../src/ReactReconcilerConstants.js | 18 ++++++++++++++++++ scripts/rollup/modules.js | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 packages/react-reconciler/src/ReactReconcilerConstants.js diff --git a/packages/react-noop-renderer/src/createReactNoop.js b/packages/react-noop-renderer/src/createReactNoop.js index 0475088a0a838..1f90af7bac00f 100644 --- a/packages/react-noop-renderer/src/createReactNoop.js +++ b/packages/react-noop-renderer/src/createReactNoop.js @@ -21,8 +21,11 @@ import type {RootTag} from 'react-reconciler/src/ReactRootTags'; import * as Scheduler from 'scheduler/unstable_mock'; import {REACT_FRAGMENT_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols'; -import {ConcurrentRoot, LegacyRoot} from 'react-reconciler/src/ReactRootTags'; -import {DefaultEventPriority} from 'react-reconciler/constants'; +import { + DefaultEventPriority, + ConcurrentRoot, + LegacyRoot, +} from 'react-reconciler/constants'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import enqueueTask from 'shared/enqueueTask'; diff --git a/packages/react-reconciler/constants.js b/packages/react-reconciler/constants.js index fba59ba132ec2..c98f17cf9cc07 100644 --- a/packages/react-reconciler/constants.js +++ b/packages/react-reconciler/constants.js @@ -9,4 +9,4 @@ 'use strict'; -export * from './src/ReactEventPriorities'; +export * from './src/ReactReconcilerConstants'; diff --git a/packages/react-reconciler/src/ReactReconcilerConstants.js b/packages/react-reconciler/src/ReactReconcilerConstants.js new file mode 100644 index 0000000000000..ce41e42dc0b2f --- /dev/null +++ b/packages/react-reconciler/src/ReactReconcilerConstants.js @@ -0,0 +1,18 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +// These are semi-public constants exposed to any third-party renderers. +// Only expose the minimal subset necessary to implement a host config. + +export { + DiscreteEventPriority, + ContinuousEventPriority, + DefaultEventPriority, +} from './ReactEventPriorities'; +export {ConcurrentRoot, LegacyRoot} from './ReactRootTags'; diff --git a/scripts/rollup/modules.js b/scripts/rollup/modules.js index 80c0a6c2cddbe..1585e307aa7b4 100644 --- a/scripts/rollup/modules.js +++ b/scripts/rollup/modules.js @@ -16,6 +16,7 @@ const importSideEffects = Object.freeze({ 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface': HAS_NO_SIDE_EFFECTS_ON_IMPORT, scheduler: HAS_NO_SIDE_EFFECTS_ON_IMPORT, 'scheduler/tracing': HAS_NO_SIDE_EFFECTS_ON_IMPORT, + react: HAS_NO_SIDE_EFFECTS_ON_IMPORT, 'react-dom/server': HAS_NO_SIDE_EFFECTS_ON_IMPORT, 'react/jsx-dev-runtime': HAS_NO_SIDE_EFFECTS_ON_IMPORT, 'react-fetch/node': HAS_NO_SIDE_EFFECTS_ON_IMPORT,