@@ -32,6 +32,7 @@ import {
32
32
enableLazyContextPropagation ,
33
33
enableUseMutableSource ,
34
34
enableTransitionTracing ,
35
+ enableUseMemoCacheHook ,
35
36
} from 'shared/ReactFeatureFlags' ;
36
37
37
38
import {
@@ -721,6 +722,10 @@ function createFunctionComponentUpdateQueue(): FunctionComponentUpdateQueue {
721
722
} ;
722
723
}
723
724
725
+ function useMemoCache ( size : number ) : Array < any > {
726
+ throw new Error ( 'Not implemented.' ) ;
727
+ }
728
+
724
729
function basicStateReducer < S > (state: S, action: BasicStateAction< S > ): S {
725
730
// $FlowFixMe: Flow doesn't like mixed types
726
731
return typeof action === 'function' ? action ( state ) : action ;
@@ -2416,6 +2421,9 @@ if (enableCache) {
2416
2421
( ContextOnlyDispatcher : Dispatcher ) . getCacheForType = getCacheForType ;
2417
2422
( ContextOnlyDispatcher : Dispatcher ) . useCacheRefresh = throwInvalidHookError ;
2418
2423
}
2424
+ if (enableUseMemoCacheHook) {
2425
+ ( ContextOnlyDispatcher : Dispatcher ) . useMemoCache = throwInvalidHookError ;
2426
+ }
2419
2427
2420
2428
const HooksDispatcherOnMount: Dispatcher = {
2421
2429
readContext ,
@@ -2444,6 +2452,9 @@ if (enableCache) {
2444
2452
( HooksDispatcherOnMount : Dispatcher ) . getCacheForType = getCacheForType ;
2445
2453
( HooksDispatcherOnMount : Dispatcher ) . useCacheRefresh = mountRefresh ;
2446
2454
}
2455
+ if (enableUseMemoCacheHook) {
2456
+ ( HooksDispatcherOnMount : Dispatcher ) . useMemoCache = useMemoCache ;
2457
+ }
2447
2458
const HooksDispatcherOnUpdate: Dispatcher = {
2448
2459
readContext ,
2449
2460
@@ -2471,6 +2482,9 @@ if (enableCache) {
2471
2482
( HooksDispatcherOnUpdate : Dispatcher ) . getCacheForType = getCacheForType ;
2472
2483
( HooksDispatcherOnUpdate : Dispatcher ) . useCacheRefresh = updateRefresh ;
2473
2484
}
2485
+ if (enableUseMemoCacheHook) {
2486
+ ( HooksDispatcherOnUpdate : Dispatcher ) . useMemoCache = useMemoCache ;
2487
+ }
2474
2488
2475
2489
const HooksDispatcherOnRerender: Dispatcher = {
2476
2490
readContext ,
@@ -2499,6 +2513,9 @@ if (enableCache) {
2499
2513
( HooksDispatcherOnRerender : Dispatcher ) . getCacheForType = getCacheForType ;
2500
2514
( HooksDispatcherOnRerender : Dispatcher ) . useCacheRefresh = updateRefresh ;
2501
2515
}
2516
+ if (enableUseMemoCacheHook) {
2517
+ ( HooksDispatcherOnRerender : Dispatcher ) . useMemoCache = useMemoCache ;
2518
+ }
2502
2519
2503
2520
let HooksDispatcherOnMountInDEV: Dispatcher | null = null;
2504
2521
let HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher | null = null;
@@ -2674,6 +2691,9 @@ if (__DEV__) {
2674
2691
return mountRefresh ( ) ;
2675
2692
} ;
2676
2693
}
2694
+ if (enableUseMemoCacheHook) {
2695
+ ( HooksDispatcherOnMountInDEV : Dispatcher ) . useMemoCache = useMemoCache ;
2696
+ }
2677
2697
2678
2698
HooksDispatcherOnMountWithHookTypesInDEV = {
2679
2699
readContext < T > ( context : ReactContext < T > ) : T {
@@ -2816,6 +2836,9 @@ if (__DEV__) {
2816
2836
return mountRefresh ( ) ;
2817
2837
} ;
2818
2838
}
2839
+ if (enableUseMemoCacheHook) {
2840
+ ( HooksDispatcherOnMountWithHookTypesInDEV : Dispatcher ) . useMemoCache = useMemoCache ;
2841
+ }
2819
2842
2820
2843
HooksDispatcherOnUpdateInDEV = {
2821
2844
readContext < T > ( context : ReactContext < T > ) : T {
@@ -2958,6 +2981,9 @@ if (__DEV__) {
2958
2981
return updateRefresh ( ) ;
2959
2982
} ;
2960
2983
}
2984
+ if (enableUseMemoCacheHook) {
2985
+ ( HooksDispatcherOnUpdateInDEV : Dispatcher ) . useMemoCache = useMemoCache ;
2986
+ }
2961
2987
2962
2988
HooksDispatcherOnRerenderInDEV = {
2963
2989
readContext < T > ( context : ReactContext < T > ) : T {
@@ -3101,6 +3127,9 @@ if (__DEV__) {
3101
3127
return updateRefresh ( ) ;
3102
3128
} ;
3103
3129
}
3130
+ if (enableUseMemoCacheHook) {
3131
+ ( HooksDispatcherOnRerenderInDEV : Dispatcher ) . useMemoCache = useMemoCache ;
3132
+ }
3104
3133
3105
3134
InvalidNestedHooksDispatcherOnMountInDEV = {
3106
3135
readContext < T > ( context : ReactContext < T > ) : T {
@@ -3260,6 +3289,14 @@ if (__DEV__) {
3260
3289
return mountRefresh ( ) ;
3261
3290
} ;
3262
3291
}
3292
+ if (enableUseMemoCacheHook) {
3293
+ ( InvalidNestedHooksDispatcherOnMountInDEV : Dispatcher ) . useMemoCache = function (
3294
+ size : number ,
3295
+ ) : Array < any > {
3296
+ warnInvalidHookAccess ( ) ;
3297
+ return useMemoCache ( size ) ;
3298
+ } ;
3299
+ }
3263
3300
3264
3301
InvalidNestedHooksDispatcherOnUpdateInDEV = {
3265
3302
readContext < T > (context: ReactContext< T > ): T {
@@ -3419,6 +3456,14 @@ if (__DEV__) {
3419
3456
return updateRefresh ( ) ;
3420
3457
} ;
3421
3458
}
3459
+ if (enableUseMemoCacheHook) {
3460
+ ( InvalidNestedHooksDispatcherOnUpdateInDEV : Dispatcher ) . useMemoCache = function (
3461
+ size : number ,
3462
+ ) : Array < any > {
3463
+ warnInvalidHookAccess ( ) ;
3464
+ return useMemoCache ( size ) ;
3465
+ } ;
3466
+ }
3422
3467
3423
3468
InvalidNestedHooksDispatcherOnRerenderInDEV = {
3424
3469
readContext < T > (context: ReactContext< T > ): T {
@@ -3579,4 +3624,12 @@ if (__DEV__) {
3579
3624
return updateRefresh ( ) ;
3580
3625
} ;
3581
3626
}
3627
+ if (enableUseMemoCacheHook) {
3628
+ ( InvalidNestedHooksDispatcherOnRerenderInDEV : Dispatcher ) . useMemoCache = function (
3629
+ size : number ,
3630
+ ) : Array < any > {
3631
+ warnInvalidHookAccess ( ) ;
3632
+ return useMemoCache ( size ) ;
3633
+ } ;
3634
+ }
3582
3635
}
0 commit comments