Enable hooks! (#14679)
* Turned enableHooks feature flag on everywhere * Removed useHooks feature flag from tests (now that it's on by default) * Remove useHooks feature flag entirely
This commit is contained in:
parent
73962c3664
commit
6cb26774e2
|
@ -16,9 +16,6 @@ let ReactDebugTools;
|
|||
describe('ReactHooksInspection', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
let ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
// TODO: Switch this test to non-internal once the flag is on by default.
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
React = require('react');
|
||||
ReactDebugTools = require('react-debug-tools');
|
||||
});
|
|
@ -17,9 +17,6 @@ let ReactDebugTools;
|
|||
describe('ReactHooksInspectionIntergration', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
let ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
// TODO: Switch this test to non-internal once the flag is on by default.
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
React = require('react');
|
||||
ReactTestRenderer = require('react-test-renderer');
|
||||
ReactDebugTools = require('react-debug-tools');
|
|
@ -38,7 +38,6 @@ function initModules() {
|
|||
|
||||
ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
React = require('react');
|
||||
ReactDOM = require('react-dom');
|
||||
ReactDOMServer = require('react-dom/server');
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
let ReactFeatureFlags;
|
||||
let React;
|
||||
let ReactDOM;
|
||||
let Suspense;
|
||||
|
@ -21,8 +20,6 @@ describe('ReactDOMSuspensePlaceholder', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
React = require('react');
|
||||
ReactDOM = require('react-dom');
|
||||
ReactCache = require('react-cache');
|
|
@ -41,7 +41,6 @@ describe('ReactErrorBoundaries', () => {
|
|||
jest.resetModules();
|
||||
PropTypes = require('prop-types');
|
||||
ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
|
||||
ReactDOM = require('react-dom');
|
||||
React = require('react');
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
try {
|
||||
// Markup generated within <Suspense> ends up buffered until we know
|
||||
// nothing in that boundary suspended
|
||||
|
|
|
@ -423,6 +423,3 @@ export const Dispatcher: DispatcherType = {
|
|||
// Debugging effect
|
||||
useDebugValue: noop,
|
||||
};
|
||||
export const DispatcherWithoutHooks = {
|
||||
readContext,
|
||||
};
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -34,6 +34,3 @@ export const Dispatcher = {
|
|||
useRef,
|
||||
useState,
|
||||
};
|
||||
export const DispatcherWithoutHooks = {
|
||||
readContext,
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
const expirationTime = root.nextExpirationTimeToWorkOn;
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ describe('ReactHooks', () => {
|
|||
|
||||
ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
React = require('react');
|
||||
ReactTestRenderer = require('react-test-renderer');
|
||||
ReactDOMServer = require('react-dom/server');
|
||||
|
|
|
@ -59,7 +59,6 @@ describe('ReactHooksWithNoopRenderer', () => {
|
|||
|
||||
ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
ReactFeatureFlags.enableSchedulerTracing = true;
|
||||
React = require('react');
|
||||
ReactNoop = require('react-noop-renderer');
|
||||
|
|
|
@ -21,7 +21,6 @@ describe('ReactNewContext', () => {
|
|||
jest.resetModules();
|
||||
ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
React = require('react');
|
||||
useContext = React.useContext;
|
||||
ReactNoop = require('react-noop-renderer');
|
||||
|
|
|
@ -17,7 +17,6 @@ describe('ReactSuspense', () => {
|
|||
ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
|
||||
ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
React = require('react');
|
||||
ReactTestRenderer = require('react-test-renderer');
|
||||
// JestReact = require('jest-react');
|
||||
|
|
|
@ -23,7 +23,6 @@ describe('ReactSuspenseFuzz', () => {
|
|||
ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
|
||||
ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
React = require('react');
|
||||
Suspense = React.Suspense;
|
||||
ReactTestRenderer = require('react-test-renderer');
|
||||
|
|
|
@ -17,7 +17,6 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
|||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
|
||||
ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
|
||||
React = require('react');
|
||||
|
|
|
@ -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,7 +186,6 @@ 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;
|
||||
|
@ -198,7 +196,6 @@ class ReactShallowRenderer {
|
|||
this._numberOfReRenders = 0;
|
||||
this._previousComponentIdentity = null;
|
||||
}
|
||||
}
|
||||
|
||||
_context: null | Object;
|
||||
_newState: null | Object;
|
||||
|
@ -560,7 +557,6 @@ class ReactShallowRenderer {
|
|||
|
||||
this._mountClassComponent(element, this._context);
|
||||
} else {
|
||||
if (enableHooks) {
|
||||
const prevDispatcher = ReactCurrentDispatcher.current;
|
||||
ReactCurrentDispatcher.current = this._dispatcher;
|
||||
this._prepareToUseHooks(element.type);
|
||||
|
@ -574,13 +570,6 @@ class ReactShallowRenderer {
|
|||
ReactCurrentDispatcher.current = prevDispatcher;
|
||||
}
|
||||
this._finishHooks(element, context);
|
||||
} else {
|
||||
this._rendered = element.type.call(
|
||||
undefined,
|
||||
element.props,
|
||||
this._context,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,6 @@ let React;
|
|||
describe('ReactShallowRenderer with hooks', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
let ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
// TODO: Switch this test to non-internal once the flag is on by default.
|
||||
ReactFeatureFlags.enableHooks = true;
|
||||
createRenderer = require('react-test-renderer/shallow').createRenderer;
|
||||
React = require('react');
|
||||
});
|
|
@ -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;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
export const enableUserTimingAPI = __DEV__;
|
||||
|
||||
export const enableHooks = false;
|
||||
// Helps identify side effects in begin-phase lifecycle hooks and setState reducers:
|
||||
export const debugRenderPhaseSideEffects = false;
|
||||
|
||||
|
|
|
@ -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__;
|
||||
|
|
|
@ -14,7 +14,6 @@ import typeof * as FeatureFlagsShimType from './ReactFeatureFlags.native-oss';
|
|||
|
||||
export const debugRenderPhaseSideEffects = false;
|
||||
export const debugRenderPhaseSideEffectsForStrictMode = false;
|
||||
export const enableHooks = false;
|
||||
export const enableUserTimingAPI = __DEV__;
|
||||
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
|
||||
export const warnAboutDeprecatedLifecycles = false;
|
||||
|
|
|
@ -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 = false;
|
||||
export const warnAboutDeprecatedLifecycles = false;
|
||||
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
|
||||
export const enableProfilerTimer = __PROFILE__;
|
||||
|
|
|
@ -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 = false;
|
||||
export const warnAboutDeprecatedLifecycles = false;
|
||||
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
|
||||
export const enableProfilerTimer = false;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue