@@ -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
284282type 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} ;
39863970if (enableCache) {
39873971 ( ContextOnlyDispatcher : Dispatcher ) . useCacheRefresh = throwInvalidHookError ;
39883972}
3989- if (enableUseMemoCacheHook) {
3990- ( ContextOnlyDispatcher : Dispatcher ) . useMemoCache = throwInvalidHookError ;
3991- }
39923973if (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} ;
40274009if (enableCache) {
40284010 ( HooksDispatcherOnMount : Dispatcher ) . useCacheRefresh = mountRefresh ;
40294011}
4030- if (enableUseMemoCacheHook) {
4031- ( HooksDispatcherOnMount : Dispatcher ) . useMemoCache = useMemoCache ;
4032- }
40334012if (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} ;
40684048if (enableCache) {
40694049 ( HooksDispatcherOnUpdate : Dispatcher ) . useCacheRefresh = updateRefresh ;
40704050}
4071- if (enableUseMemoCacheHook) {
4072- ( HooksDispatcherOnUpdate : Dispatcher ) . useMemoCache = useMemoCache ;
4073- }
40744051if (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} ;
41104088if (enableCache) {
41114089 ( HooksDispatcherOnRerender : Dispatcher ) . useCacheRefresh = updateRefresh ;
41124090}
4113- if (enableUseMemoCacheHook) {
4114- ( HooksDispatcherOnRerender : Dispatcher ) . useMemoCache = useMemoCache ;
4115- }
41164091if (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 > (
0 commit comments