Skip to content

Commit

Permalink
Remove useHooks feature flag entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Jan 23, 2019
1 parent 021844a commit d1ffc25
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 87 deletions.
8 changes: 1 addition & 7 deletions packages/react-dom/src/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import describeComponentFrame from 'shared/describeComponentFrame';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {
warnAboutDeprecatedLifecycles,
enableHooks,
enableSuspenseServerRenderer,
} from 'shared/ReactFeatureFlags';

Expand Down Expand Up @@ -55,7 +54,6 @@ import {
prepareToUseHooks,
finishHooks,
Dispatcher,
DispatcherWithoutHooks,
currentThreadID,
setCurrentThreadID,
} from './ReactPartialRendererHooks';
Expand Down Expand Up @@ -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 <Suspense> ends up buffered until we know
// nothing in that boundary suspended
Expand Down
3 changes: 0 additions & 3 deletions packages/react-dom/src/server/ReactPartialRendererHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,3 @@ export const Dispatcher: DispatcherType = {
// Debugging effect
useDebugValue: noop,
};
export const DispatcherWithoutHooks = {
readContext,
};
4 changes: 0 additions & 4 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions packages/react-reconciler/src/ReactFiberDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@ export const Dispatcher = {
useRef,
useState,
};
export const DispatcherWithoutHooks = {
readContext,
};
7 changes: 0 additions & 7 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -397,9 +393,6 @@ export function bailoutHooks(
}

export function resetHooks(): void {
if (!enableHooks) {
return;
}
if (__DEV__) {
flushHookMismatchWarnings();
}
Expand Down
17 changes: 4 additions & 13 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import {
SimpleMemoComponent,
} from 'shared/ReactWorkTags';
import {
enableHooks,
enableSchedulerTracing,
enableProfilerTimer,
enableUserTimingAPI,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -510,7 +509,7 @@ function commitAllLifeCycles(
commitAttachRef(nextEffect);
}

if (enableHooks && effectTag & Passive) {
if (effectTag & Passive) {
rootWithPendingPassiveEffects = finishedRoot;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
43 changes: 16 additions & 27 deletions packages/react-test-renderer/src/ReactShallowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
25 changes: 11 additions & 14 deletions packages/react/src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
1 change: 0 additions & 1 deletion packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.persistent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
Expand Down
1 change: 0 additions & 1 deletion packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d1ffc25

Please sign in to comment.