Skip to content

Commit 2e25ee3

Browse files
authored
[flags] Cleanup enableUseMemoCacheHook (#31767)
Based off #31766 This has already landed everywhere.
1 parent a1b3bd0 commit 2e25ee3

File tree

11 files changed

+33
-97
lines changed

11 files changed

+33
-97
lines changed

packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,6 @@ describe('ReactHooksInspectionIntegration', () => {
15731573
});
15741574

15751575
describe('useMemoCache', () => {
1576-
// @gate enableUseMemoCacheHook
15771576
it('should not be inspectable', async () => {
15781577
function Foo() {
15791578
const $ = useMemoCache(1);
@@ -1601,7 +1600,6 @@ describe('ReactHooksInspectionIntegration', () => {
16011600
expect(tree.length).toEqual(0);
16021601
});
16031602

1604-
// @gate enableUseMemoCacheHook
16051603
it('should work in combination with other hooks', async () => {
16061604
function useSomething() {
16071605
const [something] = React.useState(null);

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 32 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import {
4040
enableCache,
4141
enableLazyContextPropagation,
4242
enableTransitionTracing,
43-
enableUseMemoCacheHook,
4443
enableUseEffectEventHook,
4544
enableLegacyCache,
4645
debugRenderPhaseSideEffectsForStrictMode,
@@ -277,8 +276,7 @@ export type FunctionComponentUpdateQueue = {
277276
lastEffect: Effect | null,
278277
events: Array<EventFunctionPayload<any, any, any>> | null,
279278
stores: Array<StoreConsistencyCheck<any>> | null,
280-
// NOTE: optional, only set when enableUseMemoCacheHook is enabled
281-
memoCache?: MemoCache | null,
279+
memoCache: MemoCache | null,
282280
};
283281

284282
type BasicStateAction<S> = (S => S) | S;
@@ -1127,25 +1125,12 @@ function unstable_useContextWithBailout<T>(
11271125
return readContextAndCompare(context, select);
11281126
}
11291127

1130-
// NOTE: defining two versions of this function to avoid size impact when this feature is disabled.
1131-
// Previously this function was inlined, the additional `memoCache` property makes it not inlined.
1132-
let createFunctionComponentUpdateQueue: () => FunctionComponentUpdateQueue;
1133-
if (enableUseMemoCacheHook) {
1134-
createFunctionComponentUpdateQueue = () => {
1135-
return {
1136-
lastEffect: null,
1137-
events: null,
1138-
stores: null,
1139-
memoCache: null,
1140-
};
1141-
};
1142-
} else {
1143-
createFunctionComponentUpdateQueue = () => {
1144-
return {
1145-
lastEffect: null,
1146-
events: null,
1147-
stores: null,
1148-
};
1128+
function createFunctionComponentUpdateQueue(): FunctionComponentUpdateQueue {
1129+
return {
1130+
lastEffect: null,
1131+
events: null,
1132+
stores: null,
1133+
memoCache: null,
11491134
};
11501135
}
11511136

@@ -1155,13 +1140,11 @@ function resetFunctionComponentUpdateQueue(
11551140
updateQueue.lastEffect = null;
11561141
updateQueue.events = null;
11571142
updateQueue.stores = null;
1158-
if (enableUseMemoCacheHook) {
1159-
if (updateQueue.memoCache != null) {
1160-
// NOTE: this function intentionally does not reset memoCache data. We reuse updateQueue for the memo
1161-
// cache to avoid increasing the size of fibers that don't need a cache, but we don't want to reset
1162-
// the cache when other properties are reset.
1163-
updateQueue.memoCache.index = 0;
1164-
}
1143+
if (updateQueue.memoCache != null) {
1144+
// NOTE: this function intentionally does not reset memoCache data. We reuse updateQueue for the memo
1145+
// cache to avoid increasing the size of fibers that don't need a cache, but we don't want to reset
1146+
// the cache when other properties are reset.
1147+
updateQueue.memoCache.index = 0;
11651148
}
11661149
}
11671150

@@ -3982,13 +3965,11 @@ export const ContextOnlyDispatcher: Dispatcher = {
39823965
useFormState: throwInvalidHookError,
39833966
useActionState: throwInvalidHookError,
39843967
useOptimistic: throwInvalidHookError,
3968+
useMemoCache: throwInvalidHookError,
39853969
};
39863970
if (enableCache) {
39873971
(ContextOnlyDispatcher: Dispatcher).useCacheRefresh = throwInvalidHookError;
39883972
}
3989-
if (enableUseMemoCacheHook) {
3990-
(ContextOnlyDispatcher: Dispatcher).useMemoCache = throwInvalidHookError;
3991-
}
39923973
if (enableUseEffectEventHook) {
39933974
(ContextOnlyDispatcher: Dispatcher).useEffectEvent = throwInvalidHookError;
39943975
}
@@ -4023,13 +4004,11 @@ const HooksDispatcherOnMount: Dispatcher = {
40234004
useFormState: mountActionState,
40244005
useActionState: mountActionState,
40254006
useOptimistic: mountOptimistic,
4007+
useMemoCache,
40264008
};
40274009
if (enableCache) {
40284010
(HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
40294011
}
4030-
if (enableUseMemoCacheHook) {
4031-
(HooksDispatcherOnMount: Dispatcher).useMemoCache = useMemoCache;
4032-
}
40334012
if (enableUseEffectEventHook) {
40344013
(HooksDispatcherOnMount: Dispatcher).useEffectEvent = mountEvent;
40354014
}
@@ -4064,13 +4043,11 @@ const HooksDispatcherOnUpdate: Dispatcher = {
40644043
useFormState: updateActionState,
40654044
useActionState: updateActionState,
40664045
useOptimistic: updateOptimistic,
4046+
useMemoCache,
40674047
};
40684048
if (enableCache) {
40694049
(HooksDispatcherOnUpdate: Dispatcher).useCacheRefresh = updateRefresh;
40704050
}
4071-
if (enableUseMemoCacheHook) {
4072-
(HooksDispatcherOnUpdate: Dispatcher).useMemoCache = useMemoCache;
4073-
}
40744051
if (enableUseEffectEventHook) {
40754052
(HooksDispatcherOnUpdate: Dispatcher).useEffectEvent = updateEvent;
40764053
}
@@ -4106,13 +4083,11 @@ const HooksDispatcherOnRerender: Dispatcher = {
41064083
useFormState: rerenderActionState,
41074084
useActionState: rerenderActionState,
41084085
useOptimistic: rerenderOptimistic,
4086+
useMemoCache,
41094087
};
41104088
if (enableCache) {
41114089
(HooksDispatcherOnRerender: Dispatcher).useCacheRefresh = updateRefresh;
41124090
}
4113-
if (enableUseMemoCacheHook) {
4114-
(HooksDispatcherOnRerender: Dispatcher).useMemoCache = useMemoCache;
4115-
}
41164091
if (enableUseEffectEventHook) {
41174092
(HooksDispatcherOnRerender: Dispatcher).useEffectEvent = updateEvent;
41184093
}
@@ -4307,6 +4282,7 @@ if (__DEV__) {
43074282
return mountOptimistic(passthrough, reducer);
43084283
},
43094284
useHostTransitionStatus,
4285+
useMemoCache,
43104286
};
43114287
if (enableCache) {
43124288
(HooksDispatcherOnMountInDEV: Dispatcher).useCacheRefresh =
@@ -4316,9 +4292,6 @@ if (__DEV__) {
43164292
return mountRefresh();
43174293
};
43184294
}
4319-
if (enableUseMemoCacheHook) {
4320-
(HooksDispatcherOnMountInDEV: Dispatcher).useMemoCache = useMemoCache;
4321-
}
43224295
if (enableUseEffectEventHook) {
43234296
(HooksDispatcherOnMountInDEV: Dispatcher).useEffectEvent =
43244297
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -4511,6 +4484,7 @@ if (__DEV__) {
45114484
return mountOptimistic(passthrough, reducer);
45124485
},
45134486
useHostTransitionStatus,
4487+
useMemoCache,
45144488
};
45154489
if (enableCache) {
45164490
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useCacheRefresh =
@@ -4520,10 +4494,6 @@ if (__DEV__) {
45204494
return mountRefresh();
45214495
};
45224496
}
4523-
if (enableUseMemoCacheHook) {
4524-
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useMemoCache =
4525-
useMemoCache;
4526-
}
45274497
if (enableUseEffectEventHook) {
45284498
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useEffectEvent =
45294499
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -4715,6 +4685,7 @@ if (__DEV__) {
47154685
return updateOptimistic(passthrough, reducer);
47164686
},
47174687
useHostTransitionStatus,
4688+
useMemoCache,
47184689
};
47194690
if (enableCache) {
47204691
(HooksDispatcherOnUpdateInDEV: Dispatcher).useCacheRefresh =
@@ -4724,9 +4695,6 @@ if (__DEV__) {
47244695
return updateRefresh();
47254696
};
47264697
}
4727-
if (enableUseMemoCacheHook) {
4728-
(HooksDispatcherOnUpdateInDEV: Dispatcher).useMemoCache = useMemoCache;
4729-
}
47304698
if (enableUseEffectEventHook) {
47314699
(HooksDispatcherOnUpdateInDEV: Dispatcher).useEffectEvent =
47324700
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -4918,6 +4886,7 @@ if (__DEV__) {
49184886
return rerenderOptimistic(passthrough, reducer);
49194887
},
49204888
useHostTransitionStatus,
4889+
useMemoCache,
49214890
};
49224891
if (enableCache) {
49234892
(HooksDispatcherOnRerenderInDEV: Dispatcher).useCacheRefresh =
@@ -4927,9 +4896,6 @@ if (__DEV__) {
49274896
return updateRefresh();
49284897
};
49294898
}
4930-
if (enableUseMemoCacheHook) {
4931-
(HooksDispatcherOnRerenderInDEV: Dispatcher).useMemoCache = useMemoCache;
4932-
}
49334899
if (enableUseEffectEventHook) {
49344900
(HooksDispatcherOnRerenderInDEV: Dispatcher).useEffectEvent =
49354901
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -5141,6 +5107,10 @@ if (__DEV__) {
51415107
mountHookTypesDev();
51425108
return mountOptimistic(passthrough, reducer);
51435109
},
5110+
useMemoCache(size: number): Array<any> {
5111+
warnInvalidHookAccess();
5112+
return useMemoCache(size);
5113+
},
51445114
useHostTransitionStatus,
51455115
};
51465116
if (enableCache) {
@@ -5151,13 +5121,6 @@ if (__DEV__) {
51515121
return mountRefresh();
51525122
};
51535123
}
5154-
if (enableUseMemoCacheHook) {
5155-
(InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useMemoCache =
5156-
function (size: number): Array<any> {
5157-
warnInvalidHookAccess();
5158-
return useMemoCache(size);
5159-
};
5160-
}
51615124
if (enableUseEffectEventHook) {
51625125
(InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useEffectEvent =
51635126
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -5372,6 +5335,10 @@ if (__DEV__) {
53725335
updateHookTypesDev();
53735336
return updateOptimistic(passthrough, reducer);
53745337
},
5338+
useMemoCache(size: number): Array<any> {
5339+
warnInvalidHookAccess();
5340+
return useMemoCache(size);
5341+
},
53755342
useHostTransitionStatus,
53765343
};
53775344
if (enableCache) {
@@ -5382,13 +5349,6 @@ if (__DEV__) {
53825349
return updateRefresh();
53835350
};
53845351
}
5385-
if (enableUseMemoCacheHook) {
5386-
(InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useMemoCache =
5387-
function (size: number): Array<any> {
5388-
warnInvalidHookAccess();
5389-
return useMemoCache(size);
5390-
};
5391-
}
53925352
if (enableUseEffectEventHook) {
53935353
(InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useEffectEvent =
53945354
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -5603,6 +5563,10 @@ if (__DEV__) {
56035563
updateHookTypesDev();
56045564
return rerenderOptimistic(passthrough, reducer);
56055565
},
5566+
useMemoCache(size: number): Array<any> {
5567+
warnInvalidHookAccess();
5568+
return useMemoCache(size);
5569+
},
56065570
useHostTransitionStatus,
56075571
};
56085572
if (enableCache) {
@@ -5613,13 +5577,6 @@ if (__DEV__) {
56135577
return updateRefresh();
56145578
};
56155579
}
5616-
if (enableUseMemoCacheHook) {
5617-
(InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useMemoCache =
5618-
function (size: number): Array<any> {
5619-
warnInvalidHookAccess();
5620-
return useMemoCache(size);
5621-
};
5622-
}
56235580
if (enableUseEffectEventHook) {
56245581
(InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useEffectEvent =
56255582
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ describe('useMemoCache()', () => {
5858
ErrorBoundary = _ErrorBoundary;
5959
});
6060

61-
// @gate enableUseMemoCacheHook
6261
it('render component using cache', async () => {
6362
function Component(props) {
6463
const cache = useMemoCache(1);
@@ -75,7 +74,6 @@ describe('useMemoCache()', () => {
7574
expect(root).toMatchRenderedOutput('Ok');
7675
});
7776

78-
// @gate enableUseMemoCacheHook
7977
it('update component using cache', async () => {
8078
let setX;
8179
let forceUpdate;
@@ -145,7 +143,6 @@ describe('useMemoCache()', () => {
145143
expect(data).toBe(data1); // confirm that the cache persisted across renders
146144
});
147145

148-
// @gate enableUseMemoCacheHook
149146
it('update component using cache with setstate during render', async () => {
150147
let setN;
151148
function Component(props) {
@@ -210,7 +207,6 @@ describe('useMemoCache()', () => {
210207
expect(data).toBe(data0);
211208
});
212209

213-
// @gate enableUseMemoCacheHook
214210
it('update component using cache with throw during render', async () => {
215211
let setN;
216212
let shouldFail = true;
@@ -293,7 +289,6 @@ describe('useMemoCache()', () => {
293289
expect(data).toBe(data1); // confirm that the cache persisted across renders
294290
});
295291

296-
// @gate enableUseMemoCacheHook
297292
it('update component and custom hook with caches', async () => {
298293
let setX;
299294
let forceUpdate;
@@ -370,7 +365,6 @@ describe('useMemoCache()', () => {
370365
expect(data).toBe(data1); // confirm that the cache persisted across renders
371366
});
372367

373-
// @gate enableUseMemoCacheHook
374368
it('reuses computations from suspended/interrupted render attempts during an update', async () => {
375369
// This test demonstrates the benefit of a shared memo cache. By "shared" I
376370
// mean multiple concurrent render attempts of the same component/hook use
@@ -624,7 +618,6 @@ describe('useMemoCache()', () => {
624618
);
625619
});
626620

627-
// @gate enableUseMemoCacheHook
628621
it('(repro) infinite renders when used with setState during render', async () => {
629622
// Output of react compiler on `useUserMemo`
630623
function useCompilerMemo(value) {

packages/react-server/src/ReactFizzHooks.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import {createFastHash} from './ReactServerStreamConfig';
4141
import {
4242
enableCache,
4343
enableUseEffectEventHook,
44-
enableUseMemoCacheHook,
4544
enableUseResourceEffectHook,
4645
} from 'shared/ReactFeatureFlags';
4746
import is from 'shared/objectIs';
@@ -859,6 +858,7 @@ export const HooksDispatcher: Dispatcher = supportsClientAPIs
859858
useActionState,
860859
useFormState: useActionState,
861860
useHostTransitionStatus,
861+
useMemoCache,
862862
};
863863

864864
if (enableCache) {
@@ -867,9 +867,6 @@ if (enableCache) {
867867
if (enableUseEffectEventHook) {
868868
HooksDispatcher.useEffectEvent = useEffectEvent;
869869
}
870-
if (enableUseMemoCacheHook) {
871-
HooksDispatcher.useMemoCache = useMemoCache;
872-
}
873870
if (enableUseResourceEffectHook) {
874871
HooksDispatcher.useResourceEffect = supportsClientAPIs
875872
? noop

packages/shared/ReactFeatureFlags.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ export const enableCPUSuspense = __EXPERIMENTAL__;
115115

116116
export const enableHydrationLaneScheduling = true;
117117

118-
// Enables useMemoCache hook, intended as a compilation target for
119-
// auto-memoization.
120-
export const enableUseMemoCacheHook = true;
121118
// Test this at Meta before enabling.
122119
export const enableNoCloningMemoCache = false;
123120

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export const enableTransitionTracing = false;
8080
export const enableTrustedTypesIntegration = false;
8181
export const enableUpdaterTracking = __PROFILE__;
8282
export const enableUseEffectEventHook = false;
83-
export const enableUseMemoCacheHook = true;
8483
export const favorSafetyOverHydrationPerf = true;
8584
export const renameElementSymbol = false;
8685
export const retryLaneExpirationMs = 5000;

0 commit comments

Comments
 (0)