Clean up enableUseHook flag (#26707)
This has been statically enabled everywhere for months.
Andrew Clark committed
Apr 23, 2023 at 14:50 UTC
7ce765ec321a6f213019b56b36f9dccb2a8a7d5c
21 files changed
+31
-128
packages/react-client/src/__tests__/ReactFlight-test.js
-2
@@ -530,7 +530,6 @@ describe('ReactFlight', () => {
530
expect(ReactNoop).toMatchRenderedOutput(<div>I am client</div>);
531
});
532
533
- // @gate enableUseHook
533
it('should error if a non-serializable value is passed to a host component', async () => {
534
function ClientImpl({children}) {
535
return children;
@@ -641,7 +640,6 @@ describe('ReactFlight', () => {
640
});
641
});
642
644
- // @gate enableUseHook
643
it('should trigger the inner most error boundary inside a Client Component', async () => {
644
function ServerComponent() {
645
throw new Error('This was thrown in the Server Component.');
packages/react-debug-tools/src/ReactDebugHooks.js
+8
@@ -106,6 +106,13 @@ function readContext<T>(context: ReactContext<T>): T {
106
return context._currentValue;
107
}
108
109
+function use<T>(): T {
110
+ // TODO: What should this do if it receives an unresolved promise?
111
+ throw new Error(
112
+ 'Support for `use` not yet implemented in react-debug-tools.',
113
+ );
114
+}
115
+
116
function useContext<T>(context: ReactContext<T>): T {
117
hookLog.push({
118
primitive: 'Context',
@@ -327,6 +334,7 @@ function useId(): string {
334
}
335
336
const Dispatcher: DispatcherType = {
337
+ use,
338
readContext,
339
useCacheRefresh,
340
useCallback,
packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
-6
@@ -5212,7 +5212,6 @@ describe('ReactDOMFizzServer', () => {
5212
});
5213
});
5214
5215
- // @gate enableUseHook
5215
it('basic use(promise)', async () => {
5216
const promiseA = Promise.resolve('A');
5217
const promiseB = Promise.resolve('B');
@@ -5258,7 +5257,6 @@ describe('ReactDOMFizzServer', () => {
5257
expect(getVisibleChildren(container)).toEqual('ABC');
5258
});
5259
5261
- // @gate enableUseHook
5260
it('basic use(context)', async () => {
5261
const ContextA = React.createContext('default');
5262
const ContextB = React.createContext('B');
@@ -5303,7 +5301,6 @@ describe('ReactDOMFizzServer', () => {
5301
expect(getVisibleChildren(container)).toEqual(['AB', 'C']);
5302
});
5303
5306
- // @gate enableUseHook
5304
it('use(promise) in multiple components', async () => {
5305
const promiseA = Promise.resolve('A');
5306
const promiseB = Promise.resolve('B');
@@ -5357,7 +5354,6 @@ describe('ReactDOMFizzServer', () => {
5354
expect(getVisibleChildren(container)).toEqual('ABCD');
5355
});
5356
5360
- // @gate enableUseHook
5357
it('using a rejected promise will throw', async () => {
5358
const promiseA = Promise.resolve('A');
5359
const promiseB = Promise.reject(new Error('Oops!'));
@@ -5443,7 +5439,6 @@ describe('ReactDOMFizzServer', () => {
5439
}
5440
});
5441
5446
- // @gate enableUseHook
5442
it("use a promise that's already been instrumented and resolved", async () => {
5443
const thenable = {
5444
status: 'fulfilled',
@@ -5467,7 +5462,6 @@ describe('ReactDOMFizzServer', () => {
5462
expect(getVisibleChildren(container)).toEqual('Hi');
5463
});
5464
5470
- // @gate enableUseHook
5465
it('unwraps thenable that fulfills synchronously without suspending', async () => {
5466
function App() {
5467
const thenable = {
packages/react-reconciler/src/ReactFiberHooks.js
+20
-51
@@ -37,7 +37,6 @@ import {
37
enableLazyContextPropagation,
38
enableUseMutableSource,
39
enableTransitionTracing,
40
- enableUseHook,
40
enableUseMemoCacheHook,
41
enableUseEffectEventHook,
42
enableLegacyCache,
@@ -2944,6 +2943,7 @@ function markUpdateInDevTools<A>(fiber: Fiber, lane: Lane, action: A): void {
2943
export const ContextOnlyDispatcher: Dispatcher = {
2944
readContext,
2945
2946
+ use,
2947
useCallback: throwInvalidHookError,
2948
useContext: throwInvalidHookError,
2949
useEffect: throwInvalidHookError,
@@ -2964,9 +2964,6 @@ export const ContextOnlyDispatcher: Dispatcher = {
2964
if (enableCache) {
2965
(ContextOnlyDispatcher: Dispatcher).useCacheRefresh = throwInvalidHookError;
2966
}
2967
-if (enableUseHook) {
2968
- (ContextOnlyDispatcher: Dispatcher).use = throwInvalidHookError;
2969
-}
2967
if (enableUseMemoCacheHook) {
2968
(ContextOnlyDispatcher: Dispatcher).useMemoCache = throwInvalidHookError;
2969
}
@@ -2977,6 +2974,7 @@ if (enableUseEffectEventHook) {
2974
const HooksDispatcherOnMount: Dispatcher = {
2975
readContext,
2976
2977
+ use,
2978
useCallback: mountCallback,
2979
useContext: readContext,
2980
useEffect: mountEffect,
@@ -2997,9 +2995,6 @@ const HooksDispatcherOnMount: Dispatcher = {
2995
if (enableCache) {
2996
(HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
2997
}
3000
-if (enableUseHook) {
3001
- (HooksDispatcherOnMount: Dispatcher).use = use;
3002
-}
2998
if (enableUseMemoCacheHook) {
2999
(HooksDispatcherOnMount: Dispatcher).useMemoCache = useMemoCache;
3000
}
@@ -3009,6 +3004,7 @@ if (enableUseEffectEventHook) {
3004
const HooksDispatcherOnUpdate: Dispatcher = {
3005
readContext,
3006
3007
+ use,
3008
useCallback: updateCallback,
3009
useContext: readContext,
3010
useEffect: updateEffect,
@@ -3032,9 +3028,6 @@ if (enableCache) {
3028
if (enableUseMemoCacheHook) {
3029
(HooksDispatcherOnUpdate: Dispatcher).useMemoCache = useMemoCache;
3030
}
3035
-if (enableUseHook) {
3036
- (HooksDispatcherOnUpdate: Dispatcher).use = use;
3037
-}
3031
if (enableUseEffectEventHook) {
3032
(HooksDispatcherOnUpdate: Dispatcher).useEffectEvent = updateEvent;
3033
}
@@ -3042,6 +3035,7 @@ if (enableUseEffectEventHook) {
3035
const HooksDispatcherOnRerender: Dispatcher = {
3036
readContext,
3037
3038
+ use,
3039
useCallback: updateCallback,
3040
useContext: readContext,
3041
useEffect: updateEffect,
@@ -3062,9 +3056,6 @@ const HooksDispatcherOnRerender: Dispatcher = {
3056
if (enableCache) {
3057
(HooksDispatcherOnRerender: Dispatcher).useCacheRefresh = updateRefresh;
3058
}
3065
-if (enableUseHook) {
3066
- (HooksDispatcherOnRerender: Dispatcher).use = use;
3067
-}
3059
if (enableUseMemoCacheHook) {
3060
(HooksDispatcherOnRerender: Dispatcher).useMemoCache = useMemoCache;
3061
}
@@ -3103,6 +3094,7 @@ if (__DEV__) {
3094
readContext<T>(context: ReactContext<T>): T {
3095
return readContext(context);
3096
},
3097
+ use,
3098
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
3099
currentHookNameInDev = 'useCallback';
3100
mountHookTypesDev();
@@ -3243,9 +3235,6 @@ if (__DEV__) {
3235
return mountRefresh();
3236
};
3237
}
3246
- if (enableUseHook) {
3247
- (HooksDispatcherOnMountInDEV: Dispatcher).use = use;
3248
- }
3238
if (enableUseMemoCacheHook) {
3239
(HooksDispatcherOnMountInDEV: Dispatcher).useMemoCache = useMemoCache;
3240
}
@@ -3264,6 +3253,7 @@ if (__DEV__) {
3253
readContext<T>(context: ReactContext<T>): T {
3254
return readContext(context);
3255
},
3256
+ use,
3257
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
3258
currentHookNameInDev = 'useCallback';
3259
updateHookTypesDev();
@@ -3398,9 +3388,6 @@ if (__DEV__) {
3388
return mountRefresh();
3389
};
3390
}
3401
- if (enableUseHook) {
3402
- (HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).use = use;
3403
- }
3391
if (enableUseMemoCacheHook) {
3392
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useMemoCache =
3393
useMemoCache;
@@ -3420,6 +3407,7 @@ if (__DEV__) {
3407
readContext<T>(context: ReactContext<T>): T {
3408
return readContext(context);
3409
},
3410
+ use,
3411
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
3412
currentHookNameInDev = 'useCallback';
3413
updateHookTypesDev();
@@ -3557,9 +3545,6 @@ if (__DEV__) {
3545
return updateRefresh();
3546
};
3547
}
3560
- if (enableUseHook) {
3561
- (HooksDispatcherOnUpdateInDEV: Dispatcher).use = use;
3562
- }
3548
if (enableUseMemoCacheHook) {
3549
(HooksDispatcherOnUpdateInDEV: Dispatcher).useMemoCache = useMemoCache;
3550
}
@@ -3578,7 +3563,7 @@ if (__DEV__) {
3563
readContext<T>(context: ReactContext<T>): T {
3564
return readContext(context);
3565
},
3581
-
3566
+ use,
3567
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
3568
currentHookNameInDev = 'useCallback';
3569
updateHookTypesDev();
@@ -3716,9 +3701,6 @@ if (__DEV__) {
3701
return updateRefresh();
3702
};
3703
}
3719
- if (enableUseHook) {
3720
- (HooksDispatcherOnRerenderInDEV: Dispatcher).use = use;
3721
- }
3704
if (enableUseMemoCacheHook) {
3705
(HooksDispatcherOnRerenderInDEV: Dispatcher).useMemoCache = useMemoCache;
3706
}
@@ -3738,6 +3720,10 @@ if (__DEV__) {
3720
warnInvalidContextAccess();
3721
return readContext(context);
3722
},
3723
+ use<T>(usable: Usable<T>): T {
3724
+ warnInvalidHookAccess();
3725
+ return use(usable);
3726
+ },
3727
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
3728
currentHookNameInDev = 'useCallback';
3729
warnInvalidHookAccess();
@@ -3888,14 +3874,6 @@ if (__DEV__) {
3874
return mountRefresh();
3875
};
3876
}
3891
- if (enableUseHook) {
3892
- (InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).use = function <T>(
3893
- usable: Usable<T>,
3894
- ): T {
3895
- warnInvalidHookAccess();
3896
- return use(usable);
3897
- };
3898
- }
3877
if (enableUseMemoCacheHook) {
3878
(InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useMemoCache =
3879
function (size: number): Array<any> {
@@ -3920,6 +3898,10 @@ if (__DEV__) {
3898
warnInvalidContextAccess();
3899
return readContext(context);
3900
},
3901
+ use<T>(usable: Usable<T>): T {
3902
+ warnInvalidHookAccess();
3903
+ return use(usable);
3904
+ },
3905
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
3906
currentHookNameInDev = 'useCallback';
3907
warnInvalidHookAccess();
@@ -4073,14 +4055,6 @@ if (__DEV__) {
4055
return updateRefresh();
4056
};
4057
}
4076
- if (enableUseHook) {
4077
- (InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).use = function <T>(
4078
- usable: Usable<T>,
4079
- ): T {
4080
- warnInvalidHookAccess();
4081
- return use(usable);
4082
- };
4083
- }
4058
if (enableUseMemoCacheHook) {
4059
(InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useMemoCache =
4060
function (size: number): Array<any> {
@@ -4105,7 +4079,10 @@ if (__DEV__) {
4079
warnInvalidContextAccess();
4080
return readContext(context);
4081
},
4108
-
4082
+ use<T>(usable: Usable<T>): T {
4083
+ warnInvalidHookAccess();
4084
+ return use(usable);
4085
+ },
4086
useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
4087
currentHookNameInDev = 'useCallback';
4088
warnInvalidHookAccess();
@@ -4259,14 +4236,6 @@ if (__DEV__) {
4236
return updateRefresh();
4237
};
4238
}
4262
- if (enableUseHook) {
4263
- (InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).use = function <
4264
- T,
4265
- >(usable: Usable<T>): T {
4266
- warnInvalidHookAccess();
4267
- return use(usable);
4268
- };
4269
- }
4239
if (enableUseMemoCacheHook) {
4240
(InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useMemoCache =
4241
function (size: number): Array<any> {
packages/react-reconciler/src/ReactInternalTypes.js
+1
-1
@@ -372,7 +372,7 @@ type BasicStateAction<S> = (S => S) | S;
372
type Dispatch<A> = A => void;
373
374
export type Dispatcher = {
375
- use?: <T>(Usable<T>) => T,
375
+ use: <T>(Usable<T>) => T,
376
readContext<T>(context: ReactContext<T>): T,
377
useState<S>(initialState: (() => S) | S): [S, Dispatch<BasicStateAction<S>>],
378
useReducer<S, I, A>(
packages/react-reconciler/src/__tests__/ReactIsomorphicAct-test.js
-3
@@ -206,7 +206,6 @@ describe('isomorphic act()', () => {
206
});
207
208
// @gate __DEV__
209
- // @gate enableUseHook
209
test('unwraps promises by yielding to microtasks (async act scope)', async () => {
210
const promise = Promise.resolve('Async');
211
@@ -232,7 +231,6 @@ describe('isomorphic act()', () => {
231
});
232
233
// @gate __DEV__
235
- // @gate enableUseHook
234
test('unwraps promises by yielding to microtasks (non-async act scope)', async () => {
235
const promise = Promise.resolve('Async');
236
@@ -260,7 +258,6 @@ describe('isomorphic act()', () => {
258
});
259
260
// @gate __DEV__
263
- // @gate enableUseHook
261
test('warns if a promise is used in a non-awaited `act` scope', async () => {
262
const promise = new Promise(() => {});
263
packages/react-reconciler/src/__tests__/ReactUse-test.js
-20
@@ -184,7 +184,6 @@ describe('ReactUse', () => {
184
expect(root).toMatchRenderedOutput('Loading...');
185
});
186
187
- // @gate enableUseHook
187
test('basic use(promise)', async () => {
188
const promiseA = Promise.resolve('A');
189
const promiseB = Promise.resolve('B');
@@ -213,7 +212,6 @@ describe('ReactUse', () => {
212
expect(root).toMatchRenderedOutput('ABC');
213
});
214
216
- // @gate enableUseHook
215
test("using a promise that's not cached between attempts", async () => {
216
function Async() {
217
const text =
@@ -241,7 +239,6 @@ describe('ReactUse', () => {
239
expect(root).toMatchRenderedOutput('ABC');
240
});
241
244
- // @gate enableUseHook
242
test('using a rejected promise will throw', async () => {
243
class ErrorBoundary extends React.Component {
244
state = {error: null};
@@ -286,7 +283,6 @@ describe('ReactUse', () => {
283
assertLog(['Oops!', 'Oops!']);
284
});
285
289
- // @gate enableUseHook
286
test('use(promise) in multiple components', async () => {
287
// This tests that the state for tracking promises is reset per component.
288
const promiseA = Promise.resolve('A');
@@ -320,7 +316,6 @@ describe('ReactUse', () => {
316
expect(root).toMatchRenderedOutput('ABCD');
317
});
318
323
- // @gate enableUseHook
319
test('use(promise) in multiple sibling components', async () => {
320
// This tests that the state for tracking promises is reset per component.
321
@@ -356,7 +351,6 @@ describe('ReactUse', () => {
351
expect(root).toMatchRenderedOutput('Loading...');
352
});
353
359
- // @gate enableUseHook
354
test('erroring in the same component as an uncached promise does not result in an infinite loop', async () => {
355
class ErrorBoundary extends React.Component {
356
state = {error: null};
@@ -434,7 +428,6 @@ describe('ReactUse', () => {
428
expect(root).toMatchRenderedOutput('Caught an error: Oops!');
429
});
430
437
- // @gate enableUseHook
431
test('basic use(context)', async () => {
432
const ContextA = React.createContext('');
433
const ContextB = React.createContext('B');
@@ -458,7 +451,6 @@ describe('ReactUse', () => {
451
expect(root).toMatchRenderedOutput('AB');
452
});
453
461
- // @gate enableUseHook
454
test('interrupting while yielded should reset contexts', async () => {
455
let resolve;
456
const promise = new Promise(r => {
@@ -505,7 +497,6 @@ describe('ReactUse', () => {
497
expect(root).toMatchRenderedOutput(<div>Hello world!</div>);
498
});
499
508
- // @gate enableUseHook || !__DEV__
500
test('warns if use(promise) is wrapped with try/catch block', async () => {
501
function Async() {
502
try {
@@ -541,7 +532,6 @@ describe('ReactUse', () => {
532
}
533
});
534
544
- // @gate enableUseHook
535
test('during a transition, can unwrap async operations even if nothing is cached', async () => {
536
function App() {
537
return <Text text={use(getAsyncText('Async'))} />;
@@ -577,7 +567,6 @@ describe('ReactUse', () => {
567
expect(root).toMatchRenderedOutput('Async');
568
});
569
580
- // @gate enableUseHook
570
test("does not prevent a Suspense fallback from showing if it's a new boundary, even during a transition", async () => {
571
function App() {
572
return <Text text={use(getAsyncText('Async'))} />;
@@ -620,7 +609,6 @@ describe('ReactUse', () => {
609
expect(root).toMatchRenderedOutput('Async');
610
});
611
623
- // @gate enableUseHook
612
test('when waiting for data to resolve, a fresh update will trigger a restart', async () => {
613
function App() {
614
return <Text text={use(getAsyncText('Will never resolve'))} />;
@@ -652,7 +640,6 @@ describe('ReactUse', () => {
640
assertLog(['Something different']);
641
});
642
655
- // @gate enableUseHook
643
test('when waiting for data to resolve, an update on a different root does not cause work to be dropped', async () => {
644
const getCachedAsyncText = cache(getAsyncText);
645
@@ -693,7 +680,6 @@ describe('ReactUse', () => {
680
expect(root1).toMatchRenderedOutput('Hi');
681
});
682
696
- // @gate enableUseHook
683
test('while suspended, hooks cannot be called (i.e. current dispatcher is unset correctly)', async () => {
684
function App() {
685
return <Text text={use(getAsyncText('Will never resolve'))} />;
@@ -722,7 +708,6 @@ describe('ReactUse', () => {
708
);
709
});
710
725
- // @gate enableUseHook
711
test('unwraps thenable that fulfills synchronously without suspending', async () => {
712
function App() {
713
const thenable = {
@@ -750,7 +735,6 @@ describe('ReactUse', () => {
735
expect(root).toMatchRenderedOutput('Hi');
736
});
737
753
- // @gate enableUseHook
738
test('does not suspend indefinitely if an interleaved update was skipped', async () => {
739
function Child({childShouldSuspend}) {
740
return (
@@ -979,7 +963,6 @@ describe('ReactUse', () => {
963
expect(root).toMatchRenderedOutput('aguacate avocat');
964
});
965
982
- // @gate enableUseHook
966
test(
967
'wrap an async function with useMemo to skip running the function ' +
968
'twice when loading new data',
@@ -1012,7 +995,6 @@ describe('ReactUse', () => {
995
},
996
);
997
1015
- // @gate enableUseHook
998
test('load multiple nested Suspense boundaries', async () => {
999
const getCachedAsyncText = cache(getAsyncText);
1000
@@ -1056,7 +1038,6 @@ describe('ReactUse', () => {
1038
expect(root).toMatchRenderedOutput('ABC');
1039
});
1040
1059
- // @gate enableUseHook
1041
test('load multiple nested Suspense boundaries (uncached requests)', async () => {
1042
// This the same as the previous test, except the requests are not cached.
1043
// The tree should still eventually resolve, despite the
@@ -1139,7 +1120,6 @@ describe('ReactUse', () => {
1120
expect(root).toMatchRenderedOutput('ABC');
1121
});
1122
1142
- // @gate enableUseHook
1123
test('use() combined with render phase updates', async () => {
1124
function Async() {
1125
const a = use(Promise.resolve('A'));
packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js
-19
@@ -130,7 +130,6 @@ describe('ReactFlightDOM', () => {
130
});
131
});
132
133
- // @gate enableUseHook
133
it('should resolve the root', async () => {
134
// Model
135
function Text({children}) {
@@ -180,7 +179,6 @@ describe('ReactFlightDOM', () => {
179
);
180
});
181
183
- // @gate enableUseHook
182
it('should not get confused by $', async () => {
183
// Model
184
function RootModel() {
@@ -215,7 +213,6 @@ describe('ReactFlightDOM', () => {
213
expect(container.innerHTML).toBe('<p>$1</p>');
214
});
215
218
- // @gate enableUseHook
216
it('should not get confused by @', async () => {
217
// Model
218
function RootModel() {
@@ -250,7 +247,6 @@ describe('ReactFlightDOM', () => {
247
expect(container.innerHTML).toBe('<p>@div</p>');
248
});
249
253
- // @gate enableUseHook
250
it('should be able to esm compat test module references', async () => {
251
const ESMCompatModule = {
252
__esModule: true,
@@ -300,7 +296,6 @@ describe('ReactFlightDOM', () => {
296
expect(container.innerHTML).toBe('<p>Hello World</p>');
297
});
298
303
- // @gate enableUseHook
299
it('should be able to render a named component export', async () => {
300
const Module = {
301
Component: function ({greeting}) {
@@ -338,7 +333,6 @@ describe('ReactFlightDOM', () => {
333
expect(container.innerHTML).toBe('<p>Hello World</p>');
334
});
335
341
- // @gate enableUseHook
336
it('should be able to render a module split named component export', async () => {
337
const Module = {
338
// This gets split into a separate module from the original one.
@@ -377,7 +371,6 @@ describe('ReactFlightDOM', () => {
371
expect(container.innerHTML).toBe('<p>Hello World</p>');
372
});
373
380
- // @gate enableUseHook
374
it('should unwrap async module references', async () => {
375
const AsyncModule = Promise.resolve(function AsyncModule({text}) {
376
return 'Async: ' + text;
@@ -418,7 +411,6 @@ describe('ReactFlightDOM', () => {
411
expect(container.innerHTML).toBe('<p>Async: Module</p>');
412
});
413
421
- // @gate enableUseHook
414
it('should unwrap async module references using use', async () => {
415
const AsyncModule = Promise.resolve('Async Text');
416
@@ -457,7 +449,6 @@ describe('ReactFlightDOM', () => {
449
expect(container.innerHTML).toBe('<p>Async Text</p>');
450
});
451
460
- // @gate enableUseHook
452
it('should be able to import a name called "then"', async () => {
453
const thenExports = {
454
then: function then() {
@@ -531,7 +522,6 @@ describe('ReactFlightDOM', () => {
522
);
523
});
524
534
- // @gate enableUseHook
525
it('should progressively reveal server components', async () => {
526
let reportedErrors = [];
527
@@ -728,7 +718,6 @@ describe('ReactFlightDOM', () => {
718
expect(reportedErrors).toEqual([]);
719
});
720
731
- // @gate enableUseHook
721
it('should preserve state of client components on refetch', async () => {
722
// Client
723
@@ -814,7 +803,6 @@ describe('ReactFlightDOM', () => {
803
expect(inputB.value).toBe('goodbye');
804
});
805
817
- // @gate enableUseHook
806
it('should be able to complete after aborting and throw the reason client-side', async () => {
807
const reportedErrors = [];
808
@@ -873,7 +861,6 @@ describe('ReactFlightDOM', () => {
861
expect(reportedErrors).toEqual(['for reasons']);
862
});
863
876
- // @gate enableUseHook
864
it('should be able to recover from a direct reference erroring client-side', async () => {
865
const reportedErrors = [];
866
@@ -919,7 +906,6 @@ describe('ReactFlightDOM', () => {
906
expect(reportedErrors).toEqual([]);
907
});
908
922
- // @gate enableUseHook
909
it('should be able to recover from a direct reference erroring client-side async', async () => {
910
const reportedErrors = [];
911
@@ -977,7 +963,6 @@ describe('ReactFlightDOM', () => {
963
expect(reportedErrors).toEqual([]);
964
});
965
980
- // @gate enableUseHook
966
it('should be able to recover from a direct reference erroring server-side', async () => {
967
const reportedErrors = [];
968
@@ -1044,7 +1029,6 @@ describe('ReactFlightDOM', () => {
1029
expect(reportedErrors).toEqual(['bug in the bundler']);
1030
});
1031
1047
- // @gate enableUseHook
1032
it('should pass a Promise through props and be able use() it on the client', async () => {
1033
async function getData() {
1034
return 'async hello';
@@ -1090,7 +1074,6 @@ describe('ReactFlightDOM', () => {
1074
expect(container.innerHTML).toBe('<p>async hello</p>');
1075
});
1076
1093
- // @gate enableUseHook
1077
it('should throw on the client if a passed promise eventually rejects', async () => {
1078
const reportedErrors = [];
1079
const theError = new Error('Server throw');
@@ -1158,7 +1141,6 @@ describe('ReactFlightDOM', () => {
1141
expect(reportedErrors).toEqual([theError]);
1142
});
1143
1161
- // @gate enableUseHook
1144
it('should support ReactDOM.preload when rendering in Fiber', async () => {
1145
function Component() {
1146
return <p>hello world</p>;
@@ -1214,7 +1196,6 @@ describe('ReactFlightDOM', () => {
1196
expect(container.innerHTML).toBe('<p>hello world</p>');
1197
});
1198
1217
- // @gate enableUseHook
1199
it('should support ReactDOM.preload when rendering in Fizz', async () => {
1200
function Component() {
1201
return <p>hello world</p>;
packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js
-8
@@ -182,7 +182,6 @@ describe('ReactFlightDOMBrowser', () => {
182
});
183
});
184
185
- // @gate enableUseHook
185
it('should progressively reveal server components', async () => {
186
let reportedErrors = [];
187
@@ -492,7 +491,6 @@ describe('ReactFlightDOMBrowser', () => {
491
expect(isDone).toBeTruthy();
492
});
493
495
- // @gate enableUseHook
494
it('should be able to complete after aborting and throw the reason client-side', async () => {
495
const reportedErrors = [];
496
@@ -576,7 +574,6 @@ describe('ReactFlightDOMBrowser', () => {
574
expect(reportedErrors).toEqual(['for reasons']);
575
});
576
579
- // @gate enableUseHook
577
it('basic use(promise)', async () => {
578
function Server() {
579
return (
@@ -605,7 +602,6 @@ describe('ReactFlightDOMBrowser', () => {
602
expect(container.innerHTML).toBe('ABC');
603
});
604
608
- // @gate enableUseHook
605
it('basic use(context)', async () => {
606
const ContextA = React.createServerContext('ContextA', '');
607
const ContextB = React.createServerContext('ContextB', 'B');
@@ -639,7 +635,6 @@ describe('ReactFlightDOMBrowser', () => {
635
expect(container.innerHTML).toBe('AB');
636
});
637
642
- // @gate enableUseHook
638
it('use(promise) in multiple components', async () => {
639
function Child({prefix}) {
640
return prefix + use(Promise.resolve('C')) + use(Promise.resolve('D'));
@@ -670,7 +665,6 @@ describe('ReactFlightDOMBrowser', () => {
665
expect(container.innerHTML).toBe('ABCD');
666
});
667
673
- // @gate enableUseHook
668
it('using a rejected promise will throw', async () => {
669
const promiseA = Promise.resolve('A');
670
const promiseB = Promise.reject(new Error('Oops!'));
@@ -732,7 +726,6 @@ describe('ReactFlightDOMBrowser', () => {
726
expect(reportedErrors[0].message).toBe('Oops!');
727
});
728
735
- // @gate enableUseHook
729
it("use a promise that's already been instrumented and resolved", async () => {
730
const thenable = {
731
status: 'fulfilled',
@@ -760,7 +753,6 @@ describe('ReactFlightDOMBrowser', () => {
753
expect(container.innerHTML).toBe('Hi');
754
});
755
763
- // @gate enableUseHook
756
it('unwraps thenable that fulfills synchronously without suspending', async () => {
757
function Server() {
758
const thenable = {
packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js
-1
@@ -54,7 +54,6 @@ describe('ReactFlightDOMEdge', () => {
54
}
55
}
56
57
- // @gate enableUseHook
57
it('should allow an alternative module mapping to be used for SSR', async () => {
58
function ClientComponent() {
59
return <span>Client Component</span>;
packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js
-1
@@ -56,7 +56,6 @@ describe('ReactFlightDOMNode', () => {
56
});
57
}
58
59
- // @gate enableUseHook
59
it('should allow an alternative module mapping to be used for SSR', async () => {
60
function ClientComponent() {
61
return <span>Client Component</span>;
packages/react-server/src/ReactFizzHooks.js
+1
-4
@@ -31,7 +31,6 @@ import {makeId} from './ReactFizzConfig';
31
32
import {
33
enableCache,
34
- enableUseHook,
34
enableUseEffectEventHook,
35
enableUseMemoCacheHook,
36
} from 'shared/ReactFeatureFlags';
@@ -610,6 +609,7 @@ function noop(): void {}
609
610
export const HooksDispatcher: Dispatcher = {
611
readContext,
612
+ use,
613
useContext,
614
useMemo,
615
useReducer,
@@ -641,9 +641,6 @@ if (enableUseEffectEventHook) {
641
if (enableUseMemoCacheHook) {
642
HooksDispatcher.useMemoCache = useMemoCache;
643
}
644
-if (enableUseHook) {
645
- HooksDispatcher.use = use;
646
-}
644
645
export let currentResponseState: null | ResponseState = (null: any);
646
export function setCurrentResponseState(
packages/react-server/src/ReactFlightHooks.js
+1
-2
@@ -16,7 +16,6 @@ import {
16
REACT_MEMO_CACHE_SENTINEL,
17
} from 'shared/ReactSymbols';
18
import {readContext as readContextImpl} from './ReactFlightNewContext';
19
-import {enableUseHook} from 'shared/ReactFeatureFlags';
19
import {createThenableState, trackUsedThenable} from './ReactFlightThenable';
20
import {isClientReference} from './ReactFlightServerConfig';
21
@@ -100,7 +99,7 @@ export const HooksDispatcher: Dispatcher = {
99
}
100
return data;
101
},
103
- use: enableUseHook ? use : (unsupportedHook: any),
102
+ use,
103
};
104
105
function unsupportedHook(): void {
packages/react/src/__tests__/ReactFetch-test.js
-2
@@ -135,7 +135,6 @@ describe('ReactFetch', () => {
135
expect(fetchCount).toBe(1);
136
});
137
138
- // @gate enableUseHook
138
it('can opt-out of deduping fetches inside of render with custom signal', async () => {
139
const controller = new AbortController();
140
function useCustomHook() {
@@ -154,7 +153,6 @@ describe('ReactFetch', () => {
153
expect(fetchCount).not.toBe(1);
154
});
155
157
- // @gate enableUseHook
156
it('opts out of deduping for POST requests', async () => {
157
function useCustomHook() {
158
return use(
packages/shared/ReactFeatureFlags.js
-2
@@ -106,8 +106,6 @@ export const enableHostSingletons = true;
106
107
export const enableFloat = true;
108
109
-export const enableUseHook = true;
110
-
109
// Enables unstable_useMemoCache hook, intended as a compilation target for
110
// auto-memoization.
111
export const enableUseMemoCacheHook = __EXPERIMENTAL__;
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -53,7 +53,6 @@ export const disableModulePatternComponents = false;
53
export const enableSuspenseAvoidThisFallback = false;
54
export const enableSuspenseAvoidThisFallbackFizz = false;
55
export const enableCPUSuspense = true;
56
-export const enableUseHook = true;
56
export const enableUseMemoCacheHook = true;
57
export const enableUseEffectEventHook = false;
58
export const enableClientRenderFallbackOnTextMismatch = true;
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -39,7 +39,6 @@ export const disableModulePatternComponents = false;
39
export const enableSuspenseAvoidThisFallback = false;
40
export const enableSuspenseAvoidThisFallbackFizz = false;
41
export const enableCPUSuspense = false;
42
-export const enableUseHook = true;
42
export const enableUseMemoCacheHook = false;
43
export const enableUseEffectEventHook = false;
44
export const enableClientRenderFallbackOnTextMismatch = true;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -39,7 +39,6 @@ export const disableModulePatternComponents = false;
39
export const enableSuspenseAvoidThisFallback = false;
40
export const enableSuspenseAvoidThisFallbackFizz = false;
41
export const enableCPUSuspense = false;
42
-export const enableUseHook = true;
42
export const enableUseMemoCacheHook = false;
43
export const enableUseEffectEventHook = false;
44
export const enableClientRenderFallbackOnTextMismatch = true;
packages/shared/forks/ReactFeatureFlags.test-renderer.native.js
-1
@@ -43,7 +43,6 @@ export const enableGetInspectorDataForInstanceInProduction = false;
43
export const enableSuspenseAvoidThisFallback = false;
44
export const enableSuspenseAvoidThisFallbackFizz = false;
45
export const enableCPUSuspense = false;
46
-export const enableUseHook = true;
46
export const enableUseMemoCacheHook = false;
47
export const enableUseEffectEventHook = false;
48
export const enableClientRenderFallbackOnTextMismatch = true;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -39,7 +39,6 @@ export const disableModulePatternComponents = true;
39
export const enableSuspenseAvoidThisFallback = true;
40
export const enableSuspenseAvoidThisFallbackFizz = false;
41
export const enableCPUSuspense = false;
42
-export const enableUseHook = true;
42
export const enableUseMemoCacheHook = false;
43
export const enableUseEffectEventHook = false;
44
export const enableClientRenderFallbackOnTextMismatch = true;
packages/shared/forks/ReactFeatureFlags.www.js
-1
@@ -51,7 +51,6 @@ export const enableSuspenseAvoidThisFallbackFizz = false;
51
export const disableSchedulerTimeoutInWorkLoop = false;
52
export const enableCPUSuspense = true;
53
export const enableFloat = true;
54
-export const enableUseHook = true;
54
export const enableUseMemoCacheHook = true;
55
export const enableUseEffectEventHook = true;
56
export const enableHostSingletons = true;