@@ -24,6 +24,7 @@ import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.new';
24
24
import type { Wakeable } from 'shared/ReactTypes' ;
25
25
import type { OffscreenState } from './ReactFiberOffscreenComponent' ;
26
26
import type { HookFlags } from './ReactHookEffectTags' ;
27
+ import type { Cache } from './ReactFiberCacheComponent.new' ;
27
28
28
29
import {
29
30
enableCreateEventHandleAPI ,
@@ -38,6 +39,7 @@ import {
38
39
enableSuspenseLayoutEffectSemantics ,
39
40
enableUpdaterTracking ,
40
41
warnAboutCallbackRefReturningFunction ,
42
+ enableCache ,
41
43
} from 'shared/ReactFeatureFlags' ;
42
44
import {
43
45
FunctionComponent ,
@@ -57,6 +59,7 @@ import {
57
59
ScopeComponent ,
58
60
OffscreenComponent ,
59
61
LegacyHiddenComponent ,
62
+ CacheComponent ,
60
63
} from './ReactWorkTags' ;
61
64
import { detachDeletedInstance } from './ReactFiberHostConfig' ;
62
65
import {
@@ -143,6 +146,7 @@ import {
143
146
import { didWarnAboutReassigningProps } from './ReactFiberBeginWork.new' ;
144
147
import { doesFiberContain } from './ReactFiberTreeReflection' ;
145
148
import { invokeGuardedCallback , clearCaughtError } from 'shared/ReactErrorUtils' ;
149
+ import { releaseCache , retainCache } from './ReactFiberCacheComponent.new' ;
146
150
147
151
let didWarnAboutUndefinedSnapshotBeforeUpdate : Set < mixed > | null = null ;
148
152
if ( __DEV__ ) {
@@ -2594,6 +2598,8 @@ function commitPassiveMountEffects_complete(
2594
2598
function commitPassiveMountOnFiber (
2595
2599
finishedRoot : FiberRoot ,
2596
2600
finishedWork : Fiber ,
2601
+ // maybe thread through previous fiber or cache from previous fiber
2602
+ //
2597
2603
) : void {
2598
2604
switch ( finishedWork . tag ) {
2599
2605
case FunctionComponent :
@@ -2615,6 +2621,46 @@ function commitPassiveMountOnFiber(
2615
2621
}
2616
2622
break ;
2617
2623
}
2624
+ case HostRoot : {
2625
+ if ( enableCache ) {
2626
+ // todo compare caches here
2627
+ // if caches not same
2628
+ // - retain next cache
2629
+ // - if prev cache non-null: release (or move to unmount phase?)
2630
+ // add comment that retain/release on child is technically not required
2631
+ const previousCache : Cache =
2632
+ finishedWork . alternate ?. memoizedState . cache ;
2633
+ const nextCache : Cache = finishedWork . memoizedState . cache ;
2634
+ if ( nextCache !== previousCache ) {
2635
+ console . log ( 'retain/release HostRoot cache' ) ;
2636
+ // retainCache(nextCache); root is already the owner, no need to retain
2637
+ if ( previousCache != null ) {
2638
+ releaseCache ( previousCache ) ;
2639
+ }
2640
+ }
2641
+ }
2642
+ break ;
2643
+ }
2644
+ case CacheComponent : {
2645
+ if ( enableCache ) {
2646
+ // todo compare caches here
2647
+ // if caches not same
2648
+ // - retain next cache
2649
+ // - if prev cache non-null: release (or move to unmount phase?)
2650
+ // add comment that retain/release on child is technically not required
2651
+ const previousCache : Cache =
2652
+ finishedWork . alternate ?. memoizedState . cache ;
2653
+ const nextCache : Cache = finishedWork . memoizedState . cache ;
2654
+ if ( nextCache !== previousCache ) {
2655
+ console . log ( 'retain/release CacheComponent cache' ) ;
2656
+ retainCache ( nextCache ) ;
2657
+ if ( previousCache != null ) {
2658
+ releaseCache ( previousCache ) ;
2659
+ }
2660
+ }
2661
+ }
2662
+ break ;
2663
+ }
2618
2664
}
2619
2665
}
2620
2666
@@ -2821,6 +2867,22 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber(
2821
2867
}
2822
2868
break ;
2823
2869
}
2870
+ case HostRoot : {
2871
+ if ( enableCache ) {
2872
+ const cache = current . memoizedState . cache ;
2873
+ console . log ( 'release HostRoot cache' ) ;
2874
+ releaseCache ( cache ) ;
2875
+ }
2876
+ break ;
2877
+ }
2878
+ case CacheComponent : {
2879
+ if ( enableCache ) {
2880
+ const cache = current . memoizedState . cache ;
2881
+ console . log ( 'release CacheComponent cache' ) ;
2882
+ releaseCache ( cache ) ;
2883
+ }
2884
+ break ;
2885
+ }
2824
2886
}
2825
2887
}
2826
2888
0 commit comments