Skip to content

Commit ea45af6

Browse files
committed
Clean up enableUseHook flag
This has been statically enabled everywhere for months.
1 parent a21d147 commit ea45af6

19 files changed

+23
-128
lines changed

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ describe('ReactFlight', () => {
530530
expect(ReactNoop).toMatchRenderedOutput(<div>I am client</div>);
531531
});
532532

533-
// @gate enableUseHook
534533
it('should error if a non-serializable value is passed to a host component', async () => {
535534
function ClientImpl({children}) {
536535
return children;
@@ -641,7 +640,6 @@ describe('ReactFlight', () => {
641640
});
642641
});
643642

644-
// @gate enableUseHook
645643
it('should trigger the inner most error boundary inside a Client Component', async () => {
646644
function ServerComponent() {
647645
throw new Error('This was thrown in the Server Component.');

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5212,7 +5212,6 @@ describe('ReactDOMFizzServer', () => {
52125212
});
52135213
});
52145214

5215-
// @gate enableUseHook
52165215
it('basic use(promise)', async () => {
52175216
const promiseA = Promise.resolve('A');
52185217
const promiseB = Promise.resolve('B');
@@ -5258,7 +5257,6 @@ describe('ReactDOMFizzServer', () => {
52585257
expect(getVisibleChildren(container)).toEqual('ABC');
52595258
});
52605259

5261-
// @gate enableUseHook
52625260
it('basic use(context)', async () => {
52635261
const ContextA = React.createContext('default');
52645262
const ContextB = React.createContext('B');
@@ -5303,7 +5301,6 @@ describe('ReactDOMFizzServer', () => {
53035301
expect(getVisibleChildren(container)).toEqual(['AB', 'C']);
53045302
});
53055303

5306-
// @gate enableUseHook
53075304
it('use(promise) in multiple components', async () => {
53085305
const promiseA = Promise.resolve('A');
53095306
const promiseB = Promise.resolve('B');
@@ -5357,7 +5354,6 @@ describe('ReactDOMFizzServer', () => {
53575354
expect(getVisibleChildren(container)).toEqual('ABCD');
53585355
});
53595356

5360-
// @gate enableUseHook
53615357
it('using a rejected promise will throw', async () => {
53625358
const promiseA = Promise.resolve('A');
53635359
const promiseB = Promise.reject(new Error('Oops!'));
@@ -5443,7 +5439,6 @@ describe('ReactDOMFizzServer', () => {
54435439
}
54445440
});
54455441

5446-
// @gate enableUseHook
54475442
it("use a promise that's already been instrumented and resolved", async () => {
54485443
const thenable = {
54495444
status: 'fulfilled',
@@ -5467,7 +5462,6 @@ describe('ReactDOMFizzServer', () => {
54675462
expect(getVisibleChildren(container)).toEqual('Hi');
54685463
});
54695464

5470-
// @gate enableUseHook
54715465
it('unwraps thenable that fulfills synchronously without suspending', async () => {
54725466
function App() {
54735467
const thenable = {

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import {
3737
enableLazyContextPropagation,
3838
enableUseMutableSource,
3939
enableTransitionTracing,
40-
enableUseHook,
4140
enableUseMemoCacheHook,
4241
enableUseEffectEventHook,
4342
enableLegacyCache,
@@ -2944,6 +2943,7 @@ function markUpdateInDevTools<A>(fiber: Fiber, lane: Lane, action: A): void {
29442943
export const ContextOnlyDispatcher: Dispatcher = {
29452944
readContext,
29462945

2946+
use,
29472947
useCallback: throwInvalidHookError,
29482948
useContext: throwInvalidHookError,
29492949
useEffect: throwInvalidHookError,
@@ -2964,9 +2964,6 @@ export const ContextOnlyDispatcher: Dispatcher = {
29642964
if (enableCache) {
29652965
(ContextOnlyDispatcher: Dispatcher).useCacheRefresh = throwInvalidHookError;
29662966
}
2967-
if (enableUseHook) {
2968-
(ContextOnlyDispatcher: Dispatcher).use = throwInvalidHookError;
2969-
}
29702967
if (enableUseMemoCacheHook) {
29712968
(ContextOnlyDispatcher: Dispatcher).useMemoCache = throwInvalidHookError;
29722969
}
@@ -2977,6 +2974,7 @@ if (enableUseEffectEventHook) {
29772974
const HooksDispatcherOnMount: Dispatcher = {
29782975
readContext,
29792976

2977+
use,
29802978
useCallback: mountCallback,
29812979
useContext: readContext,
29822980
useEffect: mountEffect,
@@ -2997,9 +2995,6 @@ const HooksDispatcherOnMount: Dispatcher = {
29972995
if (enableCache) {
29982996
(HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
29992997
}
3000-
if (enableUseHook) {
3001-
(HooksDispatcherOnMount: Dispatcher).use = use;
3002-
}
30032998
if (enableUseMemoCacheHook) {
30042999
(HooksDispatcherOnMount: Dispatcher).useMemoCache = useMemoCache;
30053000
}
@@ -3009,6 +3004,7 @@ if (enableUseEffectEventHook) {
30093004
const HooksDispatcherOnUpdate: Dispatcher = {
30103005
readContext,
30113006

3007+
use,
30123008
useCallback: updateCallback,
30133009
useContext: readContext,
30143010
useEffect: updateEffect,
@@ -3032,16 +3028,14 @@ if (enableCache) {
30323028
if (enableUseMemoCacheHook) {
30333029
(HooksDispatcherOnUpdate: Dispatcher).useMemoCache = useMemoCache;
30343030
}
3035-
if (enableUseHook) {
3036-
(HooksDispatcherOnUpdate: Dispatcher).use = use;
3037-
}
30383031
if (enableUseEffectEventHook) {
30393032
(HooksDispatcherOnUpdate: Dispatcher).useEffectEvent = updateEvent;
30403033
}
30413034

30423035
const HooksDispatcherOnRerender: Dispatcher = {
30433036
readContext,
30443037

3038+
use,
30453039
useCallback: updateCallback,
30463040
useContext: readContext,
30473041
useEffect: updateEffect,
@@ -3062,9 +3056,6 @@ const HooksDispatcherOnRerender: Dispatcher = {
30623056
if (enableCache) {
30633057
(HooksDispatcherOnRerender: Dispatcher).useCacheRefresh = updateRefresh;
30643058
}
3065-
if (enableUseHook) {
3066-
(HooksDispatcherOnRerender: Dispatcher).use = use;
3067-
}
30683059
if (enableUseMemoCacheHook) {
30693060
(HooksDispatcherOnRerender: Dispatcher).useMemoCache = useMemoCache;
30703061
}
@@ -3103,6 +3094,7 @@ if (__DEV__) {
31033094
readContext<T>(context: ReactContext<T>): T {
31043095
return readContext(context);
31053096
},
3097+
use,
31063098
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
31073099
currentHookNameInDev = 'useCallback';
31083100
mountHookTypesDev();
@@ -3243,9 +3235,6 @@ if (__DEV__) {
32433235
return mountRefresh();
32443236
};
32453237
}
3246-
if (enableUseHook) {
3247-
(HooksDispatcherOnMountInDEV: Dispatcher).use = use;
3248-
}
32493238
if (enableUseMemoCacheHook) {
32503239
(HooksDispatcherOnMountInDEV: Dispatcher).useMemoCache = useMemoCache;
32513240
}
@@ -3264,6 +3253,7 @@ if (__DEV__) {
32643253
readContext<T>(context: ReactContext<T>): T {
32653254
return readContext(context);
32663255
},
3256+
use,
32673257
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
32683258
currentHookNameInDev = 'useCallback';
32693259
updateHookTypesDev();
@@ -3398,9 +3388,6 @@ if (__DEV__) {
33983388
return mountRefresh();
33993389
};
34003390
}
3401-
if (enableUseHook) {
3402-
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).use = use;
3403-
}
34043391
if (enableUseMemoCacheHook) {
34053392
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useMemoCache =
34063393
useMemoCache;
@@ -3420,6 +3407,7 @@ if (__DEV__) {
34203407
readContext<T>(context: ReactContext<T>): T {
34213408
return readContext(context);
34223409
},
3410+
use,
34233411
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
34243412
currentHookNameInDev = 'useCallback';
34253413
updateHookTypesDev();
@@ -3557,9 +3545,6 @@ if (__DEV__) {
35573545
return updateRefresh();
35583546
};
35593547
}
3560-
if (enableUseHook) {
3561-
(HooksDispatcherOnUpdateInDEV: Dispatcher).use = use;
3562-
}
35633548
if (enableUseMemoCacheHook) {
35643549
(HooksDispatcherOnUpdateInDEV: Dispatcher).useMemoCache = useMemoCache;
35653550
}
@@ -3578,7 +3563,7 @@ if (__DEV__) {
35783563
readContext<T>(context: ReactContext<T>): T {
35793564
return readContext(context);
35803565
},
3581-
3566+
use,
35823567
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
35833568
currentHookNameInDev = 'useCallback';
35843569
updateHookTypesDev();
@@ -3716,9 +3701,6 @@ if (__DEV__) {
37163701
return updateRefresh();
37173702
};
37183703
}
3719-
if (enableUseHook) {
3720-
(HooksDispatcherOnRerenderInDEV: Dispatcher).use = use;
3721-
}
37223704
if (enableUseMemoCacheHook) {
37233705
(HooksDispatcherOnRerenderInDEV: Dispatcher).useMemoCache = useMemoCache;
37243706
}
@@ -3738,6 +3720,10 @@ if (__DEV__) {
37383720
warnInvalidContextAccess();
37393721
return readContext(context);
37403722
},
3723+
use<T>(usable: Usable<T>): T {
3724+
warnInvalidHookAccess();
3725+
return use(usable);
3726+
},
37413727
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
37423728
currentHookNameInDev = 'useCallback';
37433729
warnInvalidHookAccess();
@@ -3888,14 +3874,6 @@ if (__DEV__) {
38883874
return mountRefresh();
38893875
};
38903876
}
3891-
if (enableUseHook) {
3892-
(InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).use = function <T>(
3893-
usable: Usable<T>,
3894-
): T {
3895-
warnInvalidHookAccess();
3896-
return use(usable);
3897-
};
3898-
}
38993877
if (enableUseMemoCacheHook) {
39003878
(InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useMemoCache =
39013879
function (size: number): Array<any> {
@@ -3920,6 +3898,10 @@ if (__DEV__) {
39203898
warnInvalidContextAccess();
39213899
return readContext(context);
39223900
},
3901+
use<T>(usable: Usable<T>): T {
3902+
warnInvalidHookAccess();
3903+
return use(usable);
3904+
},
39233905
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
39243906
currentHookNameInDev = 'useCallback';
39253907
warnInvalidHookAccess();
@@ -4073,14 +4055,6 @@ if (__DEV__) {
40734055
return updateRefresh();
40744056
};
40754057
}
4076-
if (enableUseHook) {
4077-
(InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).use = function <T>(
4078-
usable: Usable<T>,
4079-
): T {
4080-
warnInvalidHookAccess();
4081-
return use(usable);
4082-
};
4083-
}
40844058
if (enableUseMemoCacheHook) {
40854059
(InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useMemoCache =
40864060
function (size: number): Array<any> {
@@ -4105,7 +4079,10 @@ if (__DEV__) {
41054079
warnInvalidContextAccess();
41064080
return readContext(context);
41074081
},
4108-
4082+
use<T>(usable: Usable<T>): T {
4083+
warnInvalidHookAccess();
4084+
return use(usable);
4085+
},
41094086
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
41104087
currentHookNameInDev = 'useCallback';
41114088
warnInvalidHookAccess();
@@ -4259,14 +4236,6 @@ if (__DEV__) {
42594236
return updateRefresh();
42604237
};
42614238
}
4262-
if (enableUseHook) {
4263-
(InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).use = function <
4264-
T,
4265-
>(usable: Usable<T>): T {
4266-
warnInvalidHookAccess();
4267-
return use(usable);
4268-
};
4269-
}
42704239
if (enableUseMemoCacheHook) {
42714240
(InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useMemoCache =
42724241
function (size: number): Array<any> {

packages/react-reconciler/src/__tests__/ReactIsomorphicAct-test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ describe('isomorphic act()', () => {
206206
});
207207

208208
// @gate __DEV__
209-
// @gate enableUseHook
210209
test('unwraps promises by yielding to microtasks (async act scope)', async () => {
211210
const promise = Promise.resolve('Async');
212211

@@ -232,7 +231,6 @@ describe('isomorphic act()', () => {
232231
});
233232

234233
// @gate __DEV__
235-
// @gate enableUseHook
236234
test('unwraps promises by yielding to microtasks (non-async act scope)', async () => {
237235
const promise = Promise.resolve('Async');
238236

@@ -260,7 +258,6 @@ describe('isomorphic act()', () => {
260258
});
261259

262260
// @gate __DEV__
263-
// @gate enableUseHook
264261
test('warns if a promise is used in a non-awaited `act` scope', async () => {
265262
const promise = new Promise(() => {});
266263

0 commit comments

Comments
 (0)