diff --git a/packages/react-dom/src/server/ReactPartialRenderer.js b/packages/react-dom/src/server/ReactPartialRenderer.js index 597abb4a6699f..82d56f3a49e02 100644 --- a/packages/react-dom/src/server/ReactPartialRenderer.js +++ b/packages/react-dom/src/server/ReactPartialRenderer.js @@ -21,7 +21,6 @@ import describeComponentFrame from 'shared/describeComponentFrame'; import ReactSharedInternals from 'shared/ReactSharedInternals'; import { warnAboutDeprecatedLifecycles, - enableHooks, enableSuspenseServerRenderer, } from 'shared/ReactFeatureFlags'; @@ -55,7 +54,6 @@ import { prepareToUseHooks, finishHooks, Dispatcher, - DispatcherWithoutHooks, currentThreadID, setCurrentThreadID, } from './ReactPartialRendererHooks'; @@ -786,11 +784,7 @@ class ReactDOMServerRenderer { const prevThreadID = currentThreadID; setCurrentThreadID(this.threadID); const prevDispatcher = ReactCurrentDispatcher.current; - if (enableHooks) { - ReactCurrentDispatcher.current = Dispatcher; - } else { - ReactCurrentDispatcher.current = DispatcherWithoutHooks; - } + ReactCurrentDispatcher.current = Dispatcher; try { // Markup generated within ends up buffered until we know // nothing in that boundary suspended diff --git a/packages/react-dom/src/server/ReactPartialRendererHooks.js b/packages/react-dom/src/server/ReactPartialRendererHooks.js index 025b51a8c026a..d8496b8a26294 100644 --- a/packages/react-dom/src/server/ReactPartialRendererHooks.js +++ b/packages/react-dom/src/server/ReactPartialRendererHooks.js @@ -423,6 +423,3 @@ export const Dispatcher: DispatcherType = { // Debugging effect useDebugValue: noop, }; -export const DispatcherWithoutHooks = { - readContext, -}; diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.js b/packages/react-reconciler/src/ReactFiberCommitWork.js index 85cd0a5791baa..76e136dd7dbf5 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.js @@ -24,7 +24,6 @@ import type {Thenable} from './ReactFiberScheduler'; import {unstable_wrap as Schedule_tracing_wrap} from 'scheduler/tracing'; import { - enableHooks, enableSchedulerTracing, enableProfilerTimer, } from 'shared/ReactFeatureFlags'; @@ -312,9 +311,6 @@ function commitHookEffectList( mountTag: number, finishedWork: Fiber, ) { - if (!enableHooks) { - return; - } const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any); let lastEffect = updateQueue !== null ? updateQueue.lastEffect : null; if (lastEffect !== null) { diff --git a/packages/react-reconciler/src/ReactFiberDispatcher.js b/packages/react-reconciler/src/ReactFiberDispatcher.js index ed2ed3b2f315b..f1572072b3f6f 100644 --- a/packages/react-reconciler/src/ReactFiberDispatcher.js +++ b/packages/react-reconciler/src/ReactFiberDispatcher.js @@ -34,6 +34,3 @@ export const Dispatcher = { useRef, useState, }; -export const DispatcherWithoutHooks = { - readContext, -}; diff --git a/packages/react-reconciler/src/ReactFiberHooks.js b/packages/react-reconciler/src/ReactFiberHooks.js index d2396cfdbec14..00cd8aa94039a 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.js +++ b/packages/react-reconciler/src/ReactFiberHooks.js @@ -13,7 +13,6 @@ import type {ExpirationTime} from './ReactFiberExpirationTime'; import type {HookEffectTag} from './ReactHookEffectTags'; import {NoWork} from './ReactFiberExpirationTime'; -import {enableHooks} from 'shared/ReactFeatureFlags'; import { readContext, stashContextDependencies, @@ -296,9 +295,6 @@ export function renderWithHooks( refOrContext: any, nextRenderExpirationTime: ExpirationTime, ): any { - if (!enableHooks) { - return Component(props, refOrContext); - } renderExpirationTime = nextRenderExpirationTime; currentlyRenderingFiber = workInProgress; firstCurrentHook = current !== null ? current.memoizedState : null; @@ -397,9 +393,6 @@ export function bailoutHooks( } export function resetHooks(): void { - if (!enableHooks) { - return; - } if (__DEV__) { flushHookMismatchWarnings(); } diff --git a/packages/react-reconciler/src/ReactFiberScheduler.js b/packages/react-reconciler/src/ReactFiberScheduler.js index bcc41fe3670a4..1563f54b69a82 100644 --- a/packages/react-reconciler/src/ReactFiberScheduler.js +++ b/packages/react-reconciler/src/ReactFiberScheduler.js @@ -56,7 +56,6 @@ import { SimpleMemoComponent, } from 'shared/ReactWorkTags'; import { - enableHooks, enableSchedulerTracing, enableProfilerTimer, enableUserTimingAPI, @@ -165,7 +164,7 @@ import { commitDetachRef, commitPassiveHookEffects, } from './ReactFiberCommitWork'; -import {Dispatcher, DispatcherWithoutHooks} from './ReactFiberDispatcher'; +import {Dispatcher} from './ReactFiberDispatcher'; export type Thenable = { then(resolve: () => mixed, reject?: () => mixed): mixed, @@ -510,7 +509,7 @@ function commitAllLifeCycles( commitAttachRef(nextEffect); } - if (enableHooks && effectTag & Passive) { + if (effectTag & Passive) { rootWithPendingPassiveEffects = finishedRoot; } @@ -784,11 +783,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void { } } - if ( - enableHooks && - firstEffect !== null && - rootWithPendingPassiveEffects !== null - ) { + if (firstEffect !== null && rootWithPendingPassiveEffects !== null) { // This commit included a passive effect. These do not need to fire until // after the next paint. Schedule an callback to fire them in an async // event. To ensure serial execution, the callback will be flushed early if @@ -1221,11 +1216,7 @@ function renderRoot(root: FiberRoot, isYieldy: boolean): void { flushPassiveEffects(); isWorking = true; - if (enableHooks) { - ReactCurrentDispatcher.current = Dispatcher; - } else { - ReactCurrentDispatcher.current = DispatcherWithoutHooks; - } + ReactCurrentDispatcher.current = Dispatcher; const expirationTime = root.nextExpirationTimeToWorkOn; diff --git a/packages/react-test-renderer/src/ReactShallowRenderer.js b/packages/react-test-renderer/src/ReactShallowRenderer.js index 778e5943ec9c1..815220efb7c1d 100644 --- a/packages/react-test-renderer/src/ReactShallowRenderer.js +++ b/packages/react-test-renderer/src/ReactShallowRenderer.js @@ -15,7 +15,6 @@ import shallowEqual from 'shared/shallowEqual'; import invariant from 'shared/invariant'; import checkPropTypes from 'prop-types/checkPropTypes'; import ReactSharedInternals from 'shared/ReactSharedInternals'; -import {enableHooks} from 'shared/ReactFeatureFlags'; import warning from 'shared/warning'; import is from 'shared/objectIs'; @@ -187,17 +186,15 @@ class ReactShallowRenderer { this._rendering = false; this._forcedUpdate = false; this._updater = new Updater(this); - if (enableHooks) { - this._dispatcher = this._createDispatcher(); - this._workInProgressHook = null; - this._firstWorkInProgressHook = null; - this._isReRender = false; - this._didScheduleRenderPhaseUpdate = false; - this._renderPhaseUpdates = null; - this._currentlyRenderingComponent = null; - this._numberOfReRenders = 0; - this._previousComponentIdentity = null; - } + this._dispatcher = this._createDispatcher(); + this._workInProgressHook = null; + this._firstWorkInProgressHook = null; + this._isReRender = false; + this._didScheduleRenderPhaseUpdate = false; + this._renderPhaseUpdates = null; + this._currentlyRenderingComponent = null; + this._numberOfReRenders = 0; + this._previousComponentIdentity = null; } _context: null | Object; @@ -560,27 +557,19 @@ class ReactShallowRenderer { this._mountClassComponent(element, this._context); } else { - if (enableHooks) { - const prevDispatcher = ReactCurrentDispatcher.current; - ReactCurrentDispatcher.current = this._dispatcher; - this._prepareToUseHooks(element.type); - try { - this._rendered = element.type.call( - undefined, - element.props, - this._context, - ); - } finally { - ReactCurrentDispatcher.current = prevDispatcher; - } - this._finishHooks(element, context); - } else { + const prevDispatcher = ReactCurrentDispatcher.current; + ReactCurrentDispatcher.current = this._dispatcher; + this._prepareToUseHooks(element.type); + try { this._rendered = element.type.call( undefined, element.props, this._context, ); + } finally { + ReactCurrentDispatcher.current = prevDispatcher; } + this._finishHooks(element, context); } } diff --git a/packages/react/src/React.js b/packages/react/src/React.js index 4b868feca9c88..78f72791eb023 100644 --- a/packages/react/src/React.js +++ b/packages/react/src/React.js @@ -13,7 +13,6 @@ import { REACT_STRICT_MODE_TYPE, REACT_SUSPENSE_TYPE, } from 'shared/ReactSymbols'; -import {enableHooks} from 'shared/ReactFeatureFlags'; import {Component, PureComponent} from './ReactBaseClasses'; import {createRef} from './ReactCreateRef'; @@ -66,6 +65,17 @@ const React = { lazy, memo, + useCallback, + useContext, + useEffect, + useImperativeHandle, + useDebugValue, + useLayoutEffect, + useMemo, + useReducer, + useRef, + useState, + Fragment: REACT_FRAGMENT_TYPE, StrictMode: REACT_STRICT_MODE_TYPE, Suspense: REACT_SUSPENSE_TYPE, @@ -95,17 +105,4 @@ if (enableStableConcurrentModeAPIs) { React.unstable_Profiler = undefined; } -if (enableHooks) { - React.useCallback = useCallback; - React.useContext = useContext; - React.useEffect = useEffect; - React.useImperativeHandle = useImperativeHandle; - React.useDebugValue = useDebugValue; - React.useLayoutEffect = useLayoutEffect; - React.useMemo = useMemo; - React.useReducer = useReducer; - React.useRef = useRef; - React.useState = useState; -} - export default React; diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index b1108b2010318..af5241d1f28b1 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -9,7 +9,6 @@ export const enableUserTimingAPI = __DEV__; -export const enableHooks = true; // Helps identify side effects in begin-phase lifecycle hooks and setState reducers: export const debugRenderPhaseSideEffects = false; diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index 943cef96e8a51..1a308519bad78 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -16,7 +16,6 @@ import typeof * as FeatureFlagsShimType from './ReactFeatureFlags.native-fb'; export const {debugRenderPhaseSideEffects} = require('ReactFeatureFlags'); // The rest of the flags are static for better dead code elimination. -export const enableHooks = true; export const enableUserTimingAPI = __DEV__; export const enableProfilerTimer = __PROFILE__; export const enableSchedulerTracing = __PROFILE__; diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index 5c2734e3161e9..2e4918dc1e593 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -14,7 +14,6 @@ import typeof * as FeatureFlagsShimType from './ReactFeatureFlags.native-oss'; export const debugRenderPhaseSideEffects = false; export const debugRenderPhaseSideEffectsForStrictMode = false; -export const enableHooks = true; export const enableUserTimingAPI = __DEV__; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; export const warnAboutDeprecatedLifecycles = false; diff --git a/packages/shared/forks/ReactFeatureFlags.persistent.js b/packages/shared/forks/ReactFeatureFlags.persistent.js index 7d5a1abda8f9f..34cce860a0d5a 100644 --- a/packages/shared/forks/ReactFeatureFlags.persistent.js +++ b/packages/shared/forks/ReactFeatureFlags.persistent.js @@ -15,7 +15,6 @@ import typeof * as PersistentFeatureFlagsType from './ReactFeatureFlags.persiste export const debugRenderPhaseSideEffects = false; export const debugRenderPhaseSideEffectsForStrictMode = false; export const enableUserTimingAPI = __DEV__; -export const enableHooks = true; export const warnAboutDeprecatedLifecycles = false; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; export const enableProfilerTimer = __PROFILE__; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 1ffb97e53a0ba..d33865e96468e 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -15,7 +15,6 @@ import typeof * as PersistentFeatureFlagsType from './ReactFeatureFlags.persiste export const debugRenderPhaseSideEffects = false; export const debugRenderPhaseSideEffectsForStrictMode = false; export const enableUserTimingAPI = __DEV__; -export const enableHooks = true; export const warnAboutDeprecatedLifecycles = false; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false; export const enableProfilerTimer = false; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index 516f5738d5a3f..09c63908f825f 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -15,7 +15,6 @@ import typeof * as PersistentFeatureFlagsType from './ReactFeatureFlags.persiste export const debugRenderPhaseSideEffects = false; export const debugRenderPhaseSideEffectsForStrictMode = false; export const enableUserTimingAPI = __DEV__; -export const enableHooks = true; export const warnAboutDeprecatedLifecycles = false; export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false; export const enableProfilerTimer = false; diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index 40ea1ca5e0a9c..56e563822b0f9 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -21,9 +21,6 @@ export const { warnAboutShorthandPropertyCollision, } = require('ReactFeatureFlags'); -// The rest of the flags are static for better dead code elimination. -export const enableHooks = true; - // In www, we have experimental support for gathering data // from User Timing API calls in production. By default, we // only emit performance.mark/measure calls in __DEV__. But if