@samitouri / QOS-React / commits / 6cb26774e2

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

Brian Vaughn committed Jan 23, 2019 at 13:28 UTC 6cb26774e27e03c7d5d6e4601bcee979a004fe91
27 files changed +32 -107
packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.js renamed
-3
@@ -16,9 +16,6 @@ let ReactDebugTools;
16 describe('ReactHooksInspection', () => {
17 beforeEach(() => {
18 jest.resetModules();
19 - let ReactFeatureFlags = require('shared/ReactFeatureFlags');
20 - // TODO: Switch this test to non-internal once the flag is on by default.
21 - ReactFeatureFlags.enableHooks = true;
19 React = require('react');
20 ReactDebugTools = require('react-debug-tools');
21 });
packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js renamed
-3
@@ -17,9 +17,6 @@ let ReactDebugTools;
17 describe('ReactHooksInspectionIntergration', () => {
18 beforeEach(() => {
19 jest.resetModules();
20 - let ReactFeatureFlags = require('shared/ReactFeatureFlags');
21 - // TODO: Switch this test to non-internal once the flag is on by default.
22 - ReactFeatureFlags.enableHooks = true;
20 React = require('react');
21 ReactTestRenderer = require('react-test-renderer');
22 ReactDebugTools = require('react-debug-tools');
packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.internal.js
-1
@@ -38,7 +38,6 @@ function initModules() {
38
39 ReactFeatureFlags = require('shared/ReactFeatureFlags');
40 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
41 - ReactFeatureFlags.enableHooks = true;
41 React = require('react');
42 ReactDOM = require('react-dom');
43 ReactDOMServer = require('react-dom/server');
packages/react-dom/src/__tests__/ReactDOMSuspensePlaceholder-test.js renamed
-3
@@ -9,7 +9,6 @@
9
10 'use strict';
11
12 -let ReactFeatureFlags;
12 let React;
13 let ReactDOM;
14 let Suspense;
@@ -21,8 +20,6 @@ describe('ReactDOMSuspensePlaceholder', () => {
20
21 beforeEach(() => {
22 jest.resetModules();
24 - ReactFeatureFlags = require('shared/ReactFeatureFlags');
25 - ReactFeatureFlags.enableHooks = true;
23 React = require('react');
24 ReactDOM = require('react-dom');
25 ReactCache = require('react-cache');
packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js
-1
@@ -41,7 +41,6 @@ describe('ReactErrorBoundaries', () => {
41 jest.resetModules();
42 PropTypes = require('prop-types');
43 ReactFeatureFlags = require('shared/ReactFeatureFlags');
44 - ReactFeatureFlags.enableHooks = true;
44 ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
45 ReactDOM = require('react-dom');
46 React = require('react');
packages/react-dom/src/server/ReactPartialRenderer.js
+1 -7
@@ -21,7 +21,6 @@ import describeComponentFrame from 'shared/describeComponentFrame';
21 import ReactSharedInternals from 'shared/ReactSharedInternals';
22 import {
23 warnAboutDeprecatedLifecycles,
24 - enableHooks,
24 enableSuspenseServerRenderer,
25 } from 'shared/ReactFeatureFlags';
26
@@ -55,7 +54,6 @@ import {
54 prepareToUseHooks,
55 finishHooks,
56 Dispatcher,
58 - DispatcherWithoutHooks,
57 currentThreadID,
58 setCurrentThreadID,
59 } from './ReactPartialRendererHooks';
@@ -786,11 +784,7 @@ class ReactDOMServerRenderer {
784 const prevThreadID = currentThreadID;
785 setCurrentThreadID(this.threadID);
786 const prevDispatcher = ReactCurrentDispatcher.current;
789 - if (enableHooks) {
790 - ReactCurrentDispatcher.current = Dispatcher;
791 - } else {
792 - ReactCurrentDispatcher.current = DispatcherWithoutHooks;
793 - }
787 + ReactCurrentDispatcher.current = Dispatcher;
788 try {
789 // Markup generated within <Suspense> ends up buffered until we know
790 // nothing in that boundary suspended
packages/react-dom/src/server/ReactPartialRendererHooks.js
-3
@@ -423,6 +423,3 @@ export const Dispatcher: DispatcherType = {
423 // Debugging effect
424 useDebugValue: noop,
425 };
426 -export const DispatcherWithoutHooks = {
427 - readContext,
428 -};
packages/react-reconciler/src/ReactFiberCommitWork.js
-4
@@ -24,7 +24,6 @@ import type {Thenable} from './ReactFiberScheduler';
24
25 import {unstable_wrap as Schedule_tracing_wrap} from 'scheduler/tracing';
26 import {
27 - enableHooks,
27 enableSchedulerTracing,
28 enableProfilerTimer,
29 } from 'shared/ReactFeatureFlags';
@@ -312,9 +311,6 @@ function commitHookEffectList(
311 mountTag: number,
312 finishedWork: Fiber,
313 ) {
315 - if (!enableHooks) {
316 - return;
317 - }
314 const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);
315 let lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
316 if (lastEffect !== null) {
packages/react-reconciler/src/ReactFiberDispatcher.js
-3
@@ -34,6 +34,3 @@ export const Dispatcher = {
34 useRef,
35 useState,
36 };
37 -export const DispatcherWithoutHooks = {
38 - readContext,
39 -};
packages/react-reconciler/src/ReactFiberHooks.js
-7
@@ -13,7 +13,6 @@ import type {ExpirationTime} from './ReactFiberExpirationTime';
13 import type {HookEffectTag} from './ReactHookEffectTags';
14
15 import {NoWork} from './ReactFiberExpirationTime';
16 -import {enableHooks} from 'shared/ReactFeatureFlags';
16 import {
17 readContext,
18 stashContextDependencies,
@@ -296,9 +295,6 @@ export function renderWithHooks(
295 refOrContext: any,
296 nextRenderExpirationTime: ExpirationTime,
297 ): any {
299 - if (!enableHooks) {
300 - return Component(props, refOrContext);
301 - }
298 renderExpirationTime = nextRenderExpirationTime;
299 currentlyRenderingFiber = workInProgress;
300 firstCurrentHook = current !== null ? current.memoizedState : null;
@@ -397,9 +393,6 @@ export function bailoutHooks(
393 }
394
395 export function resetHooks(): void {
400 - if (!enableHooks) {
401 - return;
402 - }
396 if (__DEV__) {
397 flushHookMismatchWarnings();
398 }
packages/react-reconciler/src/ReactFiberScheduler.js
+4 -13
@@ -56,7 +56,6 @@ import {
56 SimpleMemoComponent,
57 } from 'shared/ReactWorkTags';
58 import {
59 - enableHooks,
59 enableSchedulerTracing,
60 enableProfilerTimer,
61 enableUserTimingAPI,
@@ -165,7 +164,7 @@ import {
164 commitDetachRef,
165 commitPassiveHookEffects,
166 } from './ReactFiberCommitWork';
168 -import {Dispatcher, DispatcherWithoutHooks} from './ReactFiberDispatcher';
167 +import {Dispatcher} from './ReactFiberDispatcher';
168
169 export type Thenable = {
170 then(resolve: () => mixed, reject?: () => mixed): mixed,
@@ -510,7 +509,7 @@ function commitAllLifeCycles(
509 commitAttachRef(nextEffect);
510 }
511
513 - if (enableHooks && effectTag & Passive) {
512 + if (effectTag & Passive) {
513 rootWithPendingPassiveEffects = finishedRoot;
514 }
515
@@ -784,11 +783,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
783 }
784 }
785
787 - if (
788 - enableHooks &&
789 - firstEffect !== null &&
790 - rootWithPendingPassiveEffects !== null
791 - ) {
786 + if (firstEffect !== null && rootWithPendingPassiveEffects !== null) {
787 // This commit included a passive effect. These do not need to fire until
788 // after the next paint. Schedule an callback to fire them in an async
789 // event. To ensure serial execution, the callback will be flushed early if
@@ -1221,11 +1216,7 @@ function renderRoot(root: FiberRoot, isYieldy: boolean): void {
1216 flushPassiveEffects();
1217
1218 isWorking = true;
1224 - if (enableHooks) {
1225 - ReactCurrentDispatcher.current = Dispatcher;
1226 - } else {
1227 - ReactCurrentDispatcher.current = DispatcherWithoutHooks;
1228 - }
1219 + ReactCurrentDispatcher.current = Dispatcher;
1220
1221 const expirationTime = root.nextExpirationTimeToWorkOn;
1222
packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js
-1
@@ -25,7 +25,6 @@ describe('ReactHooks', () => {
25
26 ReactFeatureFlags = require('shared/ReactFeatureFlags');
27 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
28 - ReactFeatureFlags.enableHooks = true;
28 React = require('react');
29 ReactTestRenderer = require('react-test-renderer');
30 ReactDOMServer = require('react-dom/server');
packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js
-1
@@ -59,7 +59,6 @@ describe('ReactHooksWithNoopRenderer', () => {
59
60 ReactFeatureFlags = require('shared/ReactFeatureFlags');
61 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
62 - ReactFeatureFlags.enableHooks = true;
62 ReactFeatureFlags.enableSchedulerTracing = true;
63 React = require('react');
64 ReactNoop = require('react-noop-renderer');
packages/react-reconciler/src/__tests__/ReactNewContext-test.internal.js
-1
@@ -21,7 +21,6 @@ describe('ReactNewContext', () => {
21 jest.resetModules();
22 ReactFeatureFlags = require('shared/ReactFeatureFlags');
23 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
24 - ReactFeatureFlags.enableHooks = true;
24 React = require('react');
25 useContext = React.useContext;
26 ReactNoop = require('react-noop-renderer');
packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js
-1
@@ -17,7 +17,6 @@ describe('ReactSuspense', () => {
17 ReactFeatureFlags = require('shared/ReactFeatureFlags');
18 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
19 ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
20 - ReactFeatureFlags.enableHooks = true;
20 React = require('react');
21 ReactTestRenderer = require('react-test-renderer');
22 // JestReact = require('jest-react');
packages/react-reconciler/src/__tests__/ReactSuspenseFuzz-test.internal.js
-1
@@ -23,7 +23,6 @@ describe('ReactSuspenseFuzz', () => {
23 ReactFeatureFlags = require('shared/ReactFeatureFlags');
24 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
25 ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
26 - ReactFeatureFlags.enableHooks = true;
26 React = require('react');
27 Suspense = React.Suspense;
28 ReactTestRenderer = require('react-test-renderer');
packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js
-1
@@ -17,7 +17,6 @@ describe('ReactSuspenseWithNoopRenderer', () => {
17 beforeEach(() => {
18 jest.resetModules();
19 ReactFeatureFlags = require('shared/ReactFeatureFlags');
20 - ReactFeatureFlags.enableHooks = true;
20 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
21 ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
22 React = require('react');
packages/react-test-renderer/src/ReactShallowRenderer.js
+16 -27
@@ -15,7 +15,6 @@ import shallowEqual from 'shared/shallowEqual';
15 import invariant from 'shared/invariant';
16 import checkPropTypes from 'prop-types/checkPropTypes';
17 import ReactSharedInternals from 'shared/ReactSharedInternals';
18 -import {enableHooks} from 'shared/ReactFeatureFlags';
18 import warning from 'shared/warning';
19 import is from 'shared/objectIs';
20
@@ -187,17 +186,15 @@ class ReactShallowRenderer {
186 this._rendering = false;
187 this._forcedUpdate = false;
188 this._updater = new Updater(this);
190 - if (enableHooks) {
191 - this._dispatcher = this._createDispatcher();
192 - this._workInProgressHook = null;
193 - this._firstWorkInProgressHook = null;
194 - this._isReRender = false;
195 - this._didScheduleRenderPhaseUpdate = false;
196 - this._renderPhaseUpdates = null;
197 - this._currentlyRenderingComponent = null;
198 - this._numberOfReRenders = 0;
199 - this._previousComponentIdentity = null;
200 - }
189 + this._dispatcher = this._createDispatcher();
190 + this._workInProgressHook = null;
191 + this._firstWorkInProgressHook = null;
192 + this._isReRender = false;
193 + this._didScheduleRenderPhaseUpdate = false;
194 + this._renderPhaseUpdates = null;
195 + this._currentlyRenderingComponent = null;
196 + this._numberOfReRenders = 0;
197 + this._previousComponentIdentity = null;
198 }
199
200 _context: null | Object;
@@ -560,27 +557,19 @@ class ReactShallowRenderer {
557
558 this._mountClassComponent(element, this._context);
559 } else {
563 - if (enableHooks) {
564 - const prevDispatcher = ReactCurrentDispatcher.current;
565 - ReactCurrentDispatcher.current = this._dispatcher;
566 - this._prepareToUseHooks(element.type);
567 - try {
568 - this._rendered = element.type.call(
569 - undefined,
570 - element.props,
571 - this._context,
572 - );
573 - } finally {
574 - ReactCurrentDispatcher.current = prevDispatcher;
575 - }
576 - this._finishHooks(element, context);
577 - } else {
560 + const prevDispatcher = ReactCurrentDispatcher.current;
561 + ReactCurrentDispatcher.current = this._dispatcher;
562 + this._prepareToUseHooks(element.type);
563 + try {
564 this._rendered = element.type.call(
565 undefined,
566 element.props,
567 this._context,
568 );
569 + } finally {
570 + ReactCurrentDispatcher.current = prevDispatcher;
571 }
572 + this._finishHooks(element, context);
573 }
574 }
575
packages/react-test-renderer/src/__tests__/ReactShallowRendererHooks-test.js renamed
-3
@@ -16,9 +16,6 @@ let React;
16 describe('ReactShallowRenderer with hooks', () => {
17 beforeEach(() => {
18 jest.resetModules();
19 - let ReactFeatureFlags = require('shared/ReactFeatureFlags');
20 - // TODO: Switch this test to non-internal once the flag is on by default.
21 - ReactFeatureFlags.enableHooks = true;
19 createRenderer = require('react-test-renderer/shallow').createRenderer;
20 React = require('react');
21 });
packages/react/src/React.js
+11 -14
@@ -13,7 +13,6 @@ import {
13 REACT_STRICT_MODE_TYPE,
14 REACT_SUSPENSE_TYPE,
15 } from 'shared/ReactSymbols';
16 -import {enableHooks} from 'shared/ReactFeatureFlags';
16
17 import {Component, PureComponent} from './ReactBaseClasses';
18 import {createRef} from './ReactCreateRef';
@@ -66,6 +65,17 @@ const React = {
65 lazy,
66 memo,
67
68 + useCallback,
69 + useContext,
70 + useEffect,
71 + useImperativeHandle,
72 + useDebugValue,
73 + useLayoutEffect,
74 + useMemo,
75 + useReducer,
76 + useRef,
77 + useState,
78 +
79 Fragment: REACT_FRAGMENT_TYPE,
80 StrictMode: REACT_STRICT_MODE_TYPE,
81 Suspense: REACT_SUSPENSE_TYPE,
@@ -95,17 +105,4 @@ if (enableStableConcurrentModeAPIs) {
105 React.unstable_Profiler = undefined;
106 }
107
98 -if (enableHooks) {
99 - React.useCallback = useCallback;
100 - React.useContext = useContext;
101 - React.useEffect = useEffect;
102 - React.useImperativeHandle = useImperativeHandle;
103 - React.useDebugValue = useDebugValue;
104 - React.useLayoutEffect = useLayoutEffect;
105 - React.useMemo = useMemo;
106 - React.useReducer = useReducer;
107 - React.useRef = useRef;
108 - React.useState = useState;
109 -}
110 -
108 export default React;
packages/shared/ReactFeatureFlags.js
-1
@@ -9,7 +9,6 @@
9
10 export const enableUserTimingAPI = __DEV__;
11
12 -export const enableHooks = false;
12 // Helps identify side effects in begin-phase lifecycle hooks and setState reducers:
13 export const debugRenderPhaseSideEffects = false;
14
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -16,7 +16,6 @@ import typeof * as FeatureFlagsShimType from './ReactFeatureFlags.native-fb';
16 export const {debugRenderPhaseSideEffects} = require('ReactFeatureFlags');
17
18 // The rest of the flags are static for better dead code elimination.
19 -export const enableHooks = true;
19 export const enableUserTimingAPI = __DEV__;
20 export const enableProfilerTimer = __PROFILE__;
21 export const enableSchedulerTracing = __PROFILE__;
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -14,7 +14,6 @@ import typeof * as FeatureFlagsShimType from './ReactFeatureFlags.native-oss';
14
15 export const debugRenderPhaseSideEffects = false;
16 export const debugRenderPhaseSideEffectsForStrictMode = false;
17 -export const enableHooks = false;
17 export const enableUserTimingAPI = __DEV__;
18 export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
19 export const warnAboutDeprecatedLifecycles = false;
packages/shared/forks/ReactFeatureFlags.persistent.js
-1
@@ -15,7 +15,6 @@ import typeof * as PersistentFeatureFlagsType from './ReactFeatureFlags.persiste
15 export const debugRenderPhaseSideEffects = false;
16 export const debugRenderPhaseSideEffectsForStrictMode = false;
17 export const enableUserTimingAPI = __DEV__;
18 -export const enableHooks = false;
18 export const warnAboutDeprecatedLifecycles = false;
19 export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
20 export const enableProfilerTimer = __PROFILE__;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -15,7 +15,6 @@ import typeof * as PersistentFeatureFlagsType from './ReactFeatureFlags.persiste
15 export const debugRenderPhaseSideEffects = false;
16 export const debugRenderPhaseSideEffectsForStrictMode = false;
17 export const enableUserTimingAPI = __DEV__;
18 -export const enableHooks = false;
18 export const warnAboutDeprecatedLifecycles = false;
19 export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
20 export const enableProfilerTimer = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -15,7 +15,6 @@ import typeof * as PersistentFeatureFlagsType from './ReactFeatureFlags.persiste
15 export const debugRenderPhaseSideEffects = false;
16 export const debugRenderPhaseSideEffectsForStrictMode = false;
17 export const enableUserTimingAPI = __DEV__;
18 -export const enableHooks = true;
18 export const warnAboutDeprecatedLifecycles = false;
19 export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
20 export const enableProfilerTimer = false;
packages/shared/forks/ReactFeatureFlags.www.js
-3
@@ -21,9 +21,6 @@ export const {
21 warnAboutShorthandPropertyCollision,
22 } = require('ReactFeatureFlags');
23
24 -// The rest of the flags are static for better dead code elimination.
25 -export const enableHooks = true;
26 -
24 // In www, we have experimental support for gathering data
25 // from User Timing API calls in production. By default, we
26 // only emit performance.mark/measure calls in __DEV__. But if