[flags] Cleanup enableCache (#31778)
This is landed everywhere
Ricky committed
Dec 15, 2024 at 12:34 UTC
e06c72fcf4632ad3117add713a25f6354631f037
22 files changed
+282
-458
packages/react-dom/src/__tests__/ReactCompositeComponent-test.js
+5
-10
@@ -537,7 +537,6 @@ describe('ReactCompositeComponent', () => {
537
});
538
539
it('should cleanup even if render() fatals', async () => {
540
- const dispatcherEnabled = __DEV__ || gate(flags => flags.enableCache);
540
const ownerEnabled = __DEV__;
541
542
let stashedDispatcher;
@@ -551,7 +550,7 @@ describe('ReactCompositeComponent', () => {
550
}
551
552
const instance = <BadComponent />;
554
- expect(ReactSharedInternals.A).toBe(dispatcherEnabled ? null : undefined);
553
+ expect(ReactSharedInternals.A).toBe(null);
554
555
const root = ReactDOMClient.createRoot(document.createElement('div'));
556
await expect(async () => {
@@ -560,15 +559,11 @@ describe('ReactCompositeComponent', () => {
559
});
560
}).rejects.toThrow();
561
563
- expect(ReactSharedInternals.A).toBe(dispatcherEnabled ? null : undefined);
564
- if (dispatcherEnabled) {
565
- if (ownerEnabled) {
566
- expect(stashedDispatcher.getOwner()).toBe(null);
567
- } else {
568
- expect(stashedDispatcher.getOwner).toBe(undefined);
569
- }
562
+ expect(ReactSharedInternals.A).toBe(null);
563
+ if (ownerEnabled) {
564
+ expect(stashedDispatcher.getOwner()).toBe(null);
565
} else {
571
- expect(stashedDispatcher).toBe(undefined);
566
+ expect(stashedDispatcher.getOwner).toBe(undefined);
567
}
568
});
569
packages/react-markup/src/__tests__/ReactMarkupServer-test.js
-1
@@ -209,7 +209,6 @@ if (!__EXPERIMENTAL__) {
209
);
210
});
211
212
- // @gate enableCache
212
it('supports cache', async () => {
213
let counter = 0;
214
const getCount = React.cache(() => {
packages/react-reconciler/src/ReactFiberAsyncDispatcher.js
-4
@@ -10,16 +10,12 @@
10
import type {AsyncDispatcher, Fiber} from './ReactInternalTypes';
11
import type {Cache} from './ReactFiberCacheComponent';
12
13
-import {enableCache} from 'shared/ReactFeatureFlags';
13
import {readContext} from './ReactFiberNewContext';
14
import {CacheContext} from './ReactFiberCacheComponent';
15
16
import {current as currentOwner} from './ReactCurrentFiber';
17
18
function getCacheForType<T>(resourceType: () => T): T {
20
- if (!enableCache) {
21
- throw new Error('Not implemented.');
22
- }
19
const cache: Cache = readContext(CacheContext);
20
let cacheForType: T | void = (cache.data.get(resourceType): any);
21
if (cacheForType === undefined) {
packages/react-reconciler/src/ReactFiberBeginWork.js
+49
-72
@@ -100,7 +100,6 @@ import {
100
enableProfilerCommitHooks,
101
enableProfilerTimer,
102
enableScopeAPI,
103
- enableCache,
103
enableLazyContextPropagation,
104
enableSchedulingProfiler,
105
enableTransitionTracing,
@@ -714,12 +713,10 @@ function updateOffscreenComponent(
713
cachePool: null,
714
};
715
workInProgress.memoizedState = nextState;
717
- if (enableCache) {
718
- // push the cache pool even though we're going to bail out
719
- // because otherwise there'd be a context mismatch
720
- if (current !== null) {
721
- pushTransition(workInProgress, null, null);
722
- }
716
+ // push the cache pool even though we're going to bail out
717
+ // because otherwise there'd be a context mismatch
718
+ if (current !== null) {
719
+ pushTransition(workInProgress, null, null);
720
}
721
reuseHiddenContextOnStack(workInProgress);
722
pushOffscreenSuspenseHandler(workInProgress);
@@ -753,7 +750,7 @@ function updateOffscreenComponent(
750
cachePool: null,
751
};
752
workInProgress.memoizedState = nextState;
756
- if (enableCache && current !== null) {
753
+ if (current !== null) {
754
// If the render that spawned this one accessed the cache pool, resume
755
// using the same cache. Unless the parent changed, since that means
756
// there was a refresh.
@@ -776,12 +773,10 @@ function updateOffscreenComponent(
773
if (prevState !== null) {
774
// We're going from hidden -> visible.
775
let prevCachePool = null;
779
- if (enableCache) {
780
- // If the render that spawned this one accessed the cache pool, resume
781
- // using the same cache. Unless the parent changed, since that means
782
- // there was a refresh.
783
- prevCachePool = prevState.cachePool;
784
- }
776
+ // If the render that spawned this one accessed the cache pool, resume
777
+ // using the same cache. Unless the parent changed, since that means
778
+ // there was a refresh.
779
+ prevCachePool = prevState.cachePool;
780
781
let transitions = null;
782
if (enableTransitionTracing) {
@@ -806,13 +801,11 @@ function updateOffscreenComponent(
801
// special to do. Need to push to the stack regardless, though, to avoid
802
// a push/pop misalignment.
803
809
- if (enableCache) {
810
- // If the render that spawned this one accessed the cache pool, resume
811
- // using the same cache. Unless the parent changed, since that means
812
- // there was a refresh.
813
- if (current !== null) {
814
- pushTransition(workInProgress, null, null);
815
- }
804
+ // If the render that spawned this one accessed the cache pool, resume
805
+ // using the same cache. Unless the parent changed, since that means
806
+ // there was a refresh.
807
+ if (current !== null) {
808
+ pushTransition(workInProgress, null, null);
809
}
810
811
// We're about to bail out, but we need to push this to the stack anyway
@@ -835,15 +828,13 @@ function deferHiddenOffscreenComponent(
828
const nextState: OffscreenState = {
829
baseLanes: nextBaseLanes,
830
// Save the cache pool so we can resume later.
838
- cachePool: enableCache ? getOffscreenDeferredCache() : null,
831
+ cachePool: getOffscreenDeferredCache(),
832
};
833
workInProgress.memoizedState = nextState;
841
- if (enableCache) {
842
- // push the cache pool even though we're going to bail out
843
- // because otherwise there'd be a context mismatch
844
- if (current !== null) {
845
- pushTransition(workInProgress, null, null);
846
- }
834
+ // push the cache pool even though we're going to bail out
835
+ // because otherwise there'd be a context mismatch
836
+ if (current !== null) {
837
+ pushTransition(workInProgress, null, null);
838
}
839
840
// We're about to bail out, but we need to push this to the stack anyway
@@ -876,10 +867,6 @@ function updateCacheComponent(
867
workInProgress: Fiber,
868
renderLanes: Lanes,
869
) {
879
- if (!enableCache) {
880
- return null;
881
- }
882
-
870
prepareToReadContext(workInProgress, renderLanes);
871
const parentCache = readContext(CacheContext);
872
@@ -1480,13 +1467,11 @@ function updateHostRoot(
1467
pushRootMarkerInstance(workInProgress);
1468
}
1469
1483
- if (enableCache) {
1484
- const nextCache: Cache = nextState.cache;
1485
- pushCacheProvider(workInProgress, nextCache);
1486
- if (nextCache !== prevState.cache) {
1487
- // The root cache refreshed.
1488
- propagateContextChange(workInProgress, CacheContext, renderLanes);
1489
- }
1470
+ const nextCache: Cache = nextState.cache;
1471
+ pushCacheProvider(workInProgress, nextCache);
1472
+ if (nextCache !== prevState.cache) {
1473
+ // The root cache refreshed.
1474
+ propagateContextChange(workInProgress, CacheContext, renderLanes);
1475
}
1476
1477
// This would ideally go inside processUpdateQueue, but because it suspends,
@@ -1990,28 +1975,26 @@ function updateSuspenseOffscreenState(
1975
renderLanes: Lanes,
1976
): OffscreenState {
1977
let cachePool: SpawnedCachePool | null = null;
1993
- if (enableCache) {
1994
- const prevCachePool: SpawnedCachePool | null = prevOffscreenState.cachePool;
1995
- if (prevCachePool !== null) {
1996
- const parentCache = isPrimaryRenderer
1997
- ? CacheContext._currentValue
1998
- : CacheContext._currentValue2;
1999
- if (prevCachePool.parent !== parentCache) {
2000
- // Detected a refresh in the parent. This overrides any previously
2001
- // suspended cache.
2002
- cachePool = {
2003
- parent: parentCache,
2004
- pool: parentCache,
2005
- };
2006
- } else {
2007
- // We can reuse the cache from last time. The only thing that would have
2008
- // overridden it is a parent refresh, which we checked for above.
2009
- cachePool = prevCachePool;
2010
- }
1978
+ const prevCachePool: SpawnedCachePool | null = prevOffscreenState.cachePool;
1979
+ if (prevCachePool !== null) {
1980
+ const parentCache = isPrimaryRenderer
1981
+ ? CacheContext._currentValue
1982
+ : CacheContext._currentValue2;
1983
+ if (prevCachePool.parent !== parentCache) {
1984
+ // Detected a refresh in the parent. This overrides any previously
1985
+ // suspended cache.
1986
+ cachePool = {
1987
+ parent: parentCache,
1988
+ pool: parentCache,
1989
+ };
1990
} else {
2012
- // If there's no previous cache pool, grab the current one.
2013
- cachePool = getSuspendedCache();
1991
+ // We can reuse the cache from last time. The only thing that would have
1992
+ // overridden it is a parent refresh, which we checked for above.
1993
+ cachePool = prevCachePool;
1994
}
1995
+ } else {
1996
+ // If there's no previous cache pool, grab the current one.
1997
+ cachePool = getSuspendedCache();
1998
}
1999
return {
2000
baseLanes: mergeLanes(prevOffscreenState.baseLanes, renderLanes),
@@ -3599,7 +3582,7 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
3582
// the begin phase. There's still some bookkeeping we that needs to be done
3583
// in this optimized path, mostly pushing stuff onto the stack.
3584
switch (workInProgress.tag) {
3602
- case HostRoot:
3585
+ case HostRoot: {
3586
pushHostRootContext(workInProgress);
3587
const root: FiberRoot = workInProgress.stateNode;
3588
pushRootTransition(workInProgress, root, renderLanes);
@@ -3608,12 +3591,11 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
3591
pushRootMarkerInstance(workInProgress);
3592
}
3593
3611
- if (enableCache) {
3612
- const cache: Cache = current.memoizedState.cache;
3613
- pushCacheProvider(workInProgress, cache);
3614
- }
3594
+ const cache: Cache = current.memoizedState.cache;
3595
+ pushCacheProvider(workInProgress, cache);
3596
resetHydrationState();
3597
break;
3598
+ }
3599
case HostSingleton:
3600
case HostComponent:
3601
pushHostContext(workInProgress);
@@ -3795,10 +3777,8 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
3777
return updateOffscreenComponent(current, workInProgress, renderLanes);
3778
}
3779
case CacheComponent: {
3798
- if (enableCache) {
3799
- const cache: Cache = current.memoizedState.cache;
3800
- pushCacheProvider(workInProgress, cache);
3801
- }
3780
+ const cache: Cache = current.memoizedState.cache;
3781
+ pushCacheProvider(workInProgress, cache);
3782
break;
3783
}
3784
case TracingMarkerComponent: {
@@ -4085,10 +4065,7 @@ function beginWork(
4065
break;
4066
}
4067
case CacheComponent: {
4088
- if (enableCache) {
4089
- return updateCacheComponent(current, workInProgress, renderLanes);
4090
- }
4091
- break;
4068
+ return updateCacheComponent(current, workInProgress, renderLanes);
4069
}
4070
case TracingMarkerComponent: {
4071
if (enableTransitionTracing) {
packages/react-reconciler/src/ReactFiberCacheComponent.js
+15
-37
@@ -10,7 +10,6 @@
10
import type {ReactContext} from 'shared/ReactTypes';
11
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
12
13
-import {enableCache} from 'shared/ReactFeatureFlags';
13
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
14
15
import {pushProvider, popProvider} from './ReactFiberNewContext';
@@ -18,8 +17,8 @@ import * as Scheduler from 'scheduler';
17
18
// In environments without AbortController (e.g. tests)
19
// replace it with a lightweight shim that only has the features we use.
21
-const AbortControllerLocal: typeof AbortController = enableCache
22
- ? typeof AbortController !== 'undefined'
20
+const AbortControllerLocal: typeof AbortController =
21
+ typeof AbortController !== 'undefined'
22
? AbortController
23
: // $FlowFixMe[missing-this-annot]
24
// $FlowFixMe[prop-missing]
@@ -36,9 +35,7 @@ const AbortControllerLocal: typeof AbortController = enableCache
35
signal.aborted = true;
36
listeners.forEach(listener => listener());
37
};
39
- }
40
- : // $FlowFixMe[incompatible-type]
41
- null;
38
+ };
39
40
export type Cache = {
41
controller: AbortController,
@@ -63,20 +60,18 @@ const {
60
unstable_NormalPriority: NormalPriority,
61
} = Scheduler;
62
66
-export const CacheContext: ReactContext<Cache> = enableCache
67
- ? {
68
- $$typeof: REACT_CONTEXT_TYPE,
69
- // We don't use Consumer/Provider for Cache components. So we'll cheat.
70
- Consumer: (null: any),
71
- Provider: (null: any),
72
- // We'll initialize these at the root.
73
- _currentValue: (null: any),
74
- _currentValue2: (null: any),
75
- _threadCount: 0,
76
- }
77
- : (null: any);
63
+export const CacheContext: ReactContext<Cache> = {
64
+ $$typeof: REACT_CONTEXT_TYPE,
65
+ // We don't use Consumer/Provider for Cache components. So we'll cheat.
66
+ Consumer: (null: any),
67
+ Provider: (null: any),
68
+ // We'll initialize these at the root.
69
+ _currentValue: (null: any),
70
+ _currentValue2: (null: any),
71
+ _threadCount: 0,
72
+};
73
79
-if (__DEV__ && enableCache) {
74
+if (__DEV__) {
75
CacheContext._currentRenderer = null;
76
CacheContext._currentRenderer2 = null;
77
}
@@ -85,22 +80,14 @@ if (__DEV__ && enableCache) {
80
// for retaining the cache once it is in use (retainCache), and releasing the cache
81
// once it is no longer needed (releaseCache).
82
export function createCache(): Cache {
88
- if (!enableCache) {
89
- return (null: any);
90
- }
91
- const cache: Cache = {
83
+ return {
84
controller: new AbortControllerLocal(),
85
data: new Map(),
86
refCount: 0,
87
};
96
-
97
- return cache;
88
}
89
90
export function retainCache(cache: Cache) {
101
- if (!enableCache) {
102
- return;
103
- }
91
if (__DEV__) {
92
if (cache.controller.signal.aborted) {
93
console.warn(
@@ -114,9 +101,6 @@ export function retainCache(cache: Cache) {
101
102
// Cleanup a cache instance, potentially freeing it if there are no more references
103
export function releaseCache(cache: Cache) {
117
- if (!enableCache) {
118
- return;
119
- }
104
cache.refCount--;
105
if (__DEV__) {
106
if (cache.refCount < 0) {
@@ -134,15 +118,9 @@ export function releaseCache(cache: Cache) {
118
}
119
120
export function pushCacheProvider(workInProgress: Fiber, cache: Cache) {
137
- if (!enableCache) {
138
- return;
139
- }
121
pushProvider(workInProgress, CacheContext, cache);
122
}
123
124
export function popCacheProvider(workInProgress: Fiber, cache: Cache) {
144
- if (!enableCache) {
145
- return;
146
- }
125
popProvider(CacheContext, workInProgress);
126
}
packages/react-reconciler/src/ReactFiberCommitWork.js
+86
-103
@@ -47,7 +47,6 @@ import {
47
enableSuspenseCallback,
48
enableScopeAPI,
49
enableUpdaterTracking,
50
- enableCache,
50
enableTransitionTracing,
51
enableUseEffectEventHook,
52
enableLegacyHidden,
@@ -2455,33 +2454,31 @@ function commitOffscreenPassiveMountEffects(
2454
finishedWork: Fiber,
2455
instance: OffscreenInstance,
2456
) {
2458
- if (enableCache) {
2459
- let previousCache: Cache | null = null;
2460
- if (
2461
- current !== null &&
2462
- current.memoizedState !== null &&
2463
- current.memoizedState.cachePool !== null
2464
- ) {
2465
- previousCache = current.memoizedState.cachePool.pool;
2466
- }
2467
- let nextCache: Cache | null = null;
2468
- if (
2469
- finishedWork.memoizedState !== null &&
2470
- finishedWork.memoizedState.cachePool !== null
2471
- ) {
2472
- nextCache = finishedWork.memoizedState.cachePool.pool;
2457
+ let previousCache: Cache | null = null;
2458
+ if (
2459
+ current !== null &&
2460
+ current.memoizedState !== null &&
2461
+ current.memoizedState.cachePool !== null
2462
+ ) {
2463
+ previousCache = current.memoizedState.cachePool.pool;
2464
+ }
2465
+ let nextCache: Cache | null = null;
2466
+ if (
2467
+ finishedWork.memoizedState !== null &&
2468
+ finishedWork.memoizedState.cachePool !== null
2469
+ ) {
2470
+ nextCache = finishedWork.memoizedState.cachePool.pool;
2471
+ }
2472
+ // Retain/release the cache used for pending (suspended) nodes.
2473
+ // Note that this is only reached in the non-suspended/visible case:
2474
+ // when the content is suspended/hidden, the retain/release occurs
2475
+ // via the parent Suspense component (see case above).
2476
+ if (nextCache !== previousCache) {
2477
+ if (nextCache != null) {
2478
+ retainCache(nextCache);
2479
}
2474
- // Retain/release the cache used for pending (suspended) nodes.
2475
- // Note that this is only reached in the non-suspended/visible case:
2476
- // when the content is suspended/hidden, the retain/release occurs
2477
- // via the parent Suspense component (see case above).
2478
- if (nextCache !== previousCache) {
2479
- if (nextCache != null) {
2480
- retainCache(nextCache);
2481
- }
2482
- if (previousCache != null) {
2483
- releaseCache(previousCache);
2484
- }
2480
+ if (previousCache != null) {
2481
+ releaseCache(previousCache);
2482
}
2483
}
2484
@@ -2552,22 +2549,20 @@ function commitCachePassiveMountEffect(
2549
current: Fiber | null,
2550
finishedWork: Fiber,
2551
) {
2555
- if (enableCache) {
2556
- let previousCache: Cache | null = null;
2557
- if (finishedWork.alternate !== null) {
2558
- previousCache = finishedWork.alternate.memoizedState.cache;
2559
- }
2560
- const nextCache = finishedWork.memoizedState.cache;
2561
- // Retain/release the cache. In theory the cache component
2562
- // could be "borrowing" a cache instance owned by some parent,
2563
- // in which case we could avoid retaining/releasing. But it
2564
- // is non-trivial to determine when that is the case, so we
2565
- // always retain/release.
2566
- if (nextCache !== previousCache) {
2567
- retainCache(nextCache);
2568
- if (previousCache != null) {
2569
- releaseCache(previousCache);
2570
- }
2552
+ let previousCache: Cache | null = null;
2553
+ if (finishedWork.alternate !== null) {
2554
+ previousCache = finishedWork.alternate.memoizedState.cache;
2555
+ }
2556
+ const nextCache = finishedWork.memoizedState.cache;
2557
+ // Retain/release the cache. In theory the cache component
2558
+ // could be "borrowing" a cache instance owned by some parent,
2559
+ // in which case we could avoid retaining/releasing. But it
2560
+ // is non-trivial to determine when that is the case, so we
2561
+ // always retain/release.
2562
+ if (nextCache !== previousCache) {
2563
+ retainCache(nextCache);
2564
+ if (previousCache != null) {
2565
+ releaseCache(previousCache);
2566
}
2567
}
2568
}
@@ -2712,23 +2707,21 @@ function commitPassiveMountOnFiber(
2707
endTime,
2708
);
2709
if (flags & Passive) {
2715
- if (enableCache) {
2716
- let previousCache: Cache | null = null;
2717
- if (finishedWork.alternate !== null) {
2718
- previousCache = finishedWork.alternate.memoizedState.cache;
2719
- }
2720
- const nextCache = finishedWork.memoizedState.cache;
2721
- // Retain/release the root cache.
2722
- // Note that on initial mount, previousCache and nextCache will be the same
2723
- // and this retain won't occur. To counter this, we instead retain the HostRoot's
2724
- // initial cache when creating the root itself (see createFiberRoot() in
2725
- // ReactFiberRoot.js). Subsequent updates that change the cache are reflected
2726
- // here, such that previous/next caches are retained correctly.
2727
- if (nextCache !== previousCache) {
2728
- retainCache(nextCache);
2729
- if (previousCache != null) {
2730
- releaseCache(previousCache);
2731
- }
2710
+ let previousCache: Cache | null = null;
2711
+ if (finishedWork.alternate !== null) {
2712
+ previousCache = finishedWork.alternate.memoizedState.cache;
2713
+ }
2714
+ const nextCache = finishedWork.memoizedState.cache;
2715
+ // Retain/release the root cache.
2716
+ // Note that on initial mount, previousCache and nextCache will be the same
2717
+ // and this retain won't occur. To counter this, we instead retain the HostRoot's
2718
+ // initial cache when creating the root itself (see createFiberRoot() in
2719
+ // ReactFiberRoot.js). Subsequent updates that change the cache are reflected
2720
+ // here, such that previous/next caches are retained correctly.
2721
+ if (nextCache !== previousCache) {
2722
+ retainCache(nextCache);
2723
+ if (previousCache != null) {
2724
+ releaseCache(previousCache);
2725
}
2726
}
2727
@@ -2845,17 +2838,15 @@ function commitPassiveMountOnFiber(
2838
if (disableLegacyMode || finishedWork.mode & ConcurrentMode) {
2839
// The effects are currently disconnected. Since the tree is hidden,
2840
// don't connect them. This also applies to the initial render.
2848
- if (enableCache || enableTransitionTracing) {
2849
- // "Atomic" effects are ones that need to fire on every commit,
2850
- // even during pre-rendering. An example is updating the reference
2851
- // count on cache instances.
2852
- recursivelyTraverseAtomicPassiveEffects(
2853
- finishedRoot,
2854
- finishedWork,
2855
- committedLanes,
2856
- committedTransitions,
2857
- );
2858
- }
2841
+ // "Atomic" effects are ones that need to fire on every commit,
2842
+ // even during pre-rendering. An example is updating the reference
2843
+ // count on cache instances.
2844
+ recursivelyTraverseAtomicPassiveEffects(
2845
+ finishedRoot,
2846
+ finishedWork,
2847
+ committedLanes,
2848
+ committedTransitions,
2849
+ );
2850
} else {
2851
// Legacy Mode: Fire the effects even if the tree is hidden.
2852
instance._visibility |= OffscreenPassiveEffectsConnected;
@@ -3065,17 +3056,15 @@ export function reconnectPassiveEffects(
3056
if (disableLegacyMode || finishedWork.mode & ConcurrentMode) {
3057
// The effects are currently disconnected. Since the tree is hidden,
3058
// don't connect them. This also applies to the initial render.
3068
- if (enableCache || enableTransitionTracing) {
3069
- // "Atomic" effects are ones that need to fire on every commit,
3070
- // even during pre-rendering. An example is updating the reference
3071
- // count on cache instances.
3072
- recursivelyTraverseAtomicPassiveEffects(
3073
- finishedRoot,
3074
- finishedWork,
3075
- committedLanes,
3076
- committedTransitions,
3077
- );
3078
- }
3059
+ // "Atomic" effects are ones that need to fire on every commit,
3060
+ // even during pre-rendering. An example is updating the reference
3061
+ // count on cache instances.
3062
+ recursivelyTraverseAtomicPassiveEffects(
3063
+ finishedRoot,
3064
+ finishedWork,
3065
+ committedLanes,
3066
+ committedTransitions,
3067
+ );
3068
} else {
3069
// Legacy Mode: Fire the effects even if the tree is hidden.
3070
instance._visibility |= OffscreenPassiveEffectsConnected;
@@ -3618,27 +3607,23 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber(
3607
// the cache instance owned by the root will never be freed.
3608
// When effects are run, the cache should be freed here:
3609
// case HostRoot: {
3621
- // if (enableCache) {
3622
- // const cache = current.memoizedState.cache;
3623
- // releaseCache(cache);
3624
- // }
3610
+ // const cache = current.memoizedState.cache;
3611
+ // releaseCache(cache);
3612
// break;
3613
// }
3614
case LegacyHiddenComponent:
3615
case OffscreenComponent: {
3629
- if (enableCache) {
3630
- if (
3631
- current.memoizedState !== null &&
3632
- current.memoizedState.cachePool !== null
3633
- ) {
3634
- const cache: Cache = current.memoizedState.cachePool.pool;
3635
- // Retain/release the cache used for pending (suspended) nodes.
3636
- // Note that this is only reached in the non-suspended/visible case:
3637
- // when the content is suspended/hidden, the retain/release occurs
3638
- // via the parent Suspense component (see case above).
3639
- if (cache != null) {
3640
- retainCache(cache);
3641
- }
3616
+ if (
3617
+ current.memoizedState !== null &&
3618
+ current.memoizedState.cachePool !== null
3619
+ ) {
3620
+ const cache: Cache = current.memoizedState.cachePool.pool;
3621
+ // Retain/release the cache used for pending (suspended) nodes.
3622
+ // Note that this is only reached in the non-suspended/visible case:
3623
+ // when the content is suspended/hidden, the retain/release occurs
3624
+ // via the parent Suspense component (see case above).
3625
+ if (cache != null) {
3626
+ retainCache(cache);
3627
}
3628
}
3629
break;
@@ -3681,10 +3666,8 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber(
3666
break;
3667
}
3668
case CacheComponent: {
3684
- if (enableCache) {
3685
- const cache = current.memoizedState.cache;
3686
- releaseCache(cache);
3687
- }
3669
+ const cache = current.memoizedState.cache;
3670
+ releaseCache(cache);
3671
break;
3672
}
3673
case TracingMarkerComponent: {
packages/react-reconciler/src/ReactFiberCompleteWork.js
+38
-45
@@ -37,7 +37,6 @@ import {
37
enableScopeAPI,
38
enablePersistedModeClonedFlag,
39
enableProfilerTimer,
40
- enableCache,
40
enableTransitionTracing,
41
enableRenderableContext,
42
passChildrenWhenCloningPersistedNodes,
@@ -985,18 +984,16 @@ function completeWork(
984
}
985
}
986
988
- if (enableCache) {
989
- let previousCache: Cache | null = null;
990
- if (current !== null) {
991
- previousCache = current.memoizedState.cache;
992
- }
993
- const cache: Cache = workInProgress.memoizedState.cache;
994
- if (cache !== previousCache) {
995
- // Run passive effects to retain/release the cache.
996
- workInProgress.flags |= Passive;
997
- }
998
- popCacheProvider(workInProgress, cache);
987
+ let previousCache: Cache | null = null;
988
+ if (current !== null) {
989
+ previousCache = current.memoizedState.cache;
990
+ }
991
+ const cache: Cache = workInProgress.memoizedState.cache;
992
+ if (cache !== previousCache) {
993
+ // Run passive effects to retain/release the cache.
994
+ workInProgress.flags |= Passive;
995
}
996
+ popCacheProvider(workInProgress, cache);
997
998
if (enableTransitionTracing) {
999
popRootMarkerInstance(workInProgress);
@@ -1384,7 +1381,7 @@ function completeWork(
1381
current !== null &&
1382
(current.memoizedState: null | SuspenseState) !== null;
1383
1387
- if (enableCache && nextDidTimeout) {
1384
+ if (nextDidTimeout) {
1385
const offscreenFiber: Fiber = (workInProgress.child: any);
1386
let previousCache: Cache | null = null;
1387
if (
@@ -1783,26 +1780,24 @@ function completeWork(
1780
scheduleRetryEffect(workInProgress, retryQueue);
1781
}
1782
1786
- if (enableCache) {
1787
- let previousCache: Cache | null = null;
1788
- if (
1789
- current !== null &&
1790
- current.memoizedState !== null &&
1791
- current.memoizedState.cachePool !== null
1792
- ) {
1793
- previousCache = current.memoizedState.cachePool.pool;
1794
- }
1795
- let cache: Cache | null = null;
1796
- if (
1797
- workInProgress.memoizedState !== null &&
1798
- workInProgress.memoizedState.cachePool !== null
1799
- ) {
1800
- cache = workInProgress.memoizedState.cachePool.pool;
1801
- }
1802
- if (cache !== previousCache) {
1803
- // Run passive effects to retain/release the cache.
1804
- workInProgress.flags |= Passive;
1805
- }
1783
+ let previousCache: Cache | null = null;
1784
+ if (
1785
+ current !== null &&
1786
+ current.memoizedState !== null &&
1787
+ current.memoizedState.cachePool !== null
1788
+ ) {
1789
+ previousCache = current.memoizedState.cachePool.pool;
1790
+ }
1791
+ let cache: Cache | null = null;
1792
+ if (
1793
+ workInProgress.memoizedState !== null &&
1794
+ workInProgress.memoizedState.cachePool !== null
1795
+ ) {
1796
+ cache = workInProgress.memoizedState.cachePool.pool;
1797
+ }
1798
+ if (cache !== previousCache) {
1799
+ // Run passive effects to retain/release the cache.
1800
+ workInProgress.flags |= Passive;
1801
}
1802
1803
popTransition(workInProgress, current);
@@ -1810,19 +1805,17 @@ function completeWork(
1805
return null;
1806
}
1807
case CacheComponent: {
1813
- if (enableCache) {
1814
- let previousCache: Cache | null = null;
1815
- if (current !== null) {
1816
- previousCache = current.memoizedState.cache;
1817
- }
1818
- const cache: Cache = workInProgress.memoizedState.cache;
1819
- if (cache !== previousCache) {
1820
- // Run passive effects to retain/release the cache.
1821
- workInProgress.flags |= Passive;
1822
- }
1823
- popCacheProvider(workInProgress, cache);
1824
- bubbleProperties(workInProgress);
1808
+ let previousCache: Cache | null = null;
1809
+ if (current !== null) {
1810
+ previousCache = current.memoizedState.cache;
1811
}
1812
+ const cache: Cache = workInProgress.memoizedState.cache;
1813
+ if (cache !== previousCache) {
1814
+ // Run passive effects to retain/release the cache.
1815
+ workInProgress.flags |= Passive;
1816
+ }
1817
+ popCacheProvider(workInProgress, cache);
1818
+ bubbleProperties(workInProgress);
1819
return null;
1820
}
1821
case TracingMarkerComponent: {
packages/react-reconciler/src/ReactFiberHooks.js
+39
-72
@@ -36,7 +36,6 @@ import {
36
import ReactSharedInternals from 'shared/ReactSharedInternals';
37
import {
38
enableSchedulingProfiler,
39
- enableCache,
39
enableLazyContextPropagation,
40
enableTransitionTracing,
41
enableUseEffectEventHook,
@@ -3591,9 +3590,6 @@ function updateRefresh(): any {
3590
}
3591
3592
function refreshCache<T>(fiber: Fiber, seedKey: ?() => T, seedValue: T): void {
3594
- if (!enableCache) {
3595
- return;
3596
- }
3593
// TODO: Does Cache work in legacy mode? Should decide and write a test.
3594
// TODO: Consider warning if the refresh is at discrete priority, or if we
3595
// otherwise suspect that it wasn't batched properly.
@@ -3954,10 +3950,8 @@ export const ContextOnlyDispatcher: Dispatcher = {
3950
useActionState: throwInvalidHookError,
3951
useOptimistic: throwInvalidHookError,
3952
useMemoCache: throwInvalidHookError,
3953
+ useCacheRefresh: throwInvalidHookError,
3954
};
3958
-if (enableCache) {
3959
- (ContextOnlyDispatcher: Dispatcher).useCacheRefresh = throwInvalidHookError;
3960
-}
3955
if (enableUseEffectEventHook) {
3956
(ContextOnlyDispatcher: Dispatcher).useEffectEvent = throwInvalidHookError;
3957
}
@@ -3993,10 +3987,8 @@ const HooksDispatcherOnMount: Dispatcher = {
3987
useActionState: mountActionState,
3988
useOptimistic: mountOptimistic,
3989
useMemoCache,
3990
+ useCacheRefresh: mountRefresh,
3991
};
3997
-if (enableCache) {
3998
- (HooksDispatcherOnMount: Dispatcher).useCacheRefresh = mountRefresh;
3999
-}
3992
if (enableUseEffectEventHook) {
3993
(HooksDispatcherOnMount: Dispatcher).useEffectEvent = mountEvent;
3994
}
@@ -4032,10 +4024,8 @@ const HooksDispatcherOnUpdate: Dispatcher = {
4024
useActionState: updateActionState,
4025
useOptimistic: updateOptimistic,
4026
useMemoCache,
4027
+ useCacheRefresh: updateRefresh,
4028
};
4036
-if (enableCache) {
4037
- (HooksDispatcherOnUpdate: Dispatcher).useCacheRefresh = updateRefresh;
4038
-}
4029
if (enableUseEffectEventHook) {
4030
(HooksDispatcherOnUpdate: Dispatcher).useEffectEvent = updateEvent;
4031
}
@@ -4072,10 +4062,8 @@ const HooksDispatcherOnRerender: Dispatcher = {
4062
useActionState: rerenderActionState,
4063
useOptimistic: rerenderOptimistic,
4064
useMemoCache,
4065
+ useCacheRefresh: updateRefresh,
4066
};
4076
-if (enableCache) {
4077
- (HooksDispatcherOnRerender: Dispatcher).useCacheRefresh = updateRefresh;
4078
-}
4067
if (enableUseEffectEventHook) {
4068
(HooksDispatcherOnRerender: Dispatcher).useEffectEvent = updateEvent;
4069
}
@@ -4271,15 +4259,12 @@ if (__DEV__) {
4259
},
4260
useHostTransitionStatus,
4261
useMemoCache,
4262
+ useCacheRefresh() {
4263
+ currentHookNameInDev = 'useCacheRefresh';
4264
+ mountHookTypesDev();
4265
+ return mountRefresh();
4266
+ },
4267
};
4275
- if (enableCache) {
4276
- (HooksDispatcherOnMountInDEV: Dispatcher).useCacheRefresh =
4277
- function useCacheRefresh() {
4278
- currentHookNameInDev = 'useCacheRefresh';
4279
- mountHookTypesDev();
4280
- return mountRefresh();
4281
- };
4282
- }
4268
if (enableUseEffectEventHook) {
4269
(HooksDispatcherOnMountInDEV: Dispatcher).useEffectEvent =
4270
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -4473,15 +4458,12 @@ if (__DEV__) {
4458
},
4459
useHostTransitionStatus,
4460
useMemoCache,
4461
+ useCacheRefresh() {
4462
+ currentHookNameInDev = 'useCacheRefresh';
4463
+ updateHookTypesDev();
4464
+ return mountRefresh();
4465
+ },
4466
};
4477
- if (enableCache) {
4478
- (HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useCacheRefresh =
4479
- function useCacheRefresh() {
4480
- currentHookNameInDev = 'useCacheRefresh';
4481
- updateHookTypesDev();
4482
- return mountRefresh();
4483
- };
4484
- }
4467
if (enableUseEffectEventHook) {
4468
(HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher).useEffectEvent =
4469
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -4674,15 +4656,12 @@ if (__DEV__) {
4656
},
4657
useHostTransitionStatus,
4658
useMemoCache,
4659
+ useCacheRefresh() {
4660
+ currentHookNameInDev = 'useCacheRefresh';
4661
+ updateHookTypesDev();
4662
+ return updateRefresh();
4663
+ },
4664
};
4678
- if (enableCache) {
4679
- (HooksDispatcherOnUpdateInDEV: Dispatcher).useCacheRefresh =
4680
- function useCacheRefresh() {
4681
- currentHookNameInDev = 'useCacheRefresh';
4682
- updateHookTypesDev();
4683
- return updateRefresh();
4684
- };
4685
- }
4665
if (enableUseEffectEventHook) {
4666
(HooksDispatcherOnUpdateInDEV: Dispatcher).useEffectEvent =
4667
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -4875,15 +4854,12 @@ if (__DEV__) {
4854
},
4855
useHostTransitionStatus,
4856
useMemoCache,
4857
+ useCacheRefresh() {
4858
+ currentHookNameInDev = 'useCacheRefresh';
4859
+ updateHookTypesDev();
4860
+ return updateRefresh();
4861
+ },
4862
};
4879
- if (enableCache) {
4880
- (HooksDispatcherOnRerenderInDEV: Dispatcher).useCacheRefresh =
4881
- function useCacheRefresh() {
4882
- currentHookNameInDev = 'useCacheRefresh';
4883
- updateHookTypesDev();
4884
- return updateRefresh();
4885
- };
4886
- }
4863
if (enableUseEffectEventHook) {
4864
(HooksDispatcherOnRerenderInDEV: Dispatcher).useEffectEvent =
4865
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -5100,15 +5076,12 @@ if (__DEV__) {
5076
return useMemoCache(size);
5077
},
5078
useHostTransitionStatus,
5079
+ useCacheRefresh() {
5080
+ currentHookNameInDev = 'useCacheRefresh';
5081
+ mountHookTypesDev();
5082
+ return mountRefresh();
5083
+ },
5084
};
5104
- if (enableCache) {
5105
- (InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useCacheRefresh =
5106
- function useCacheRefresh() {
5107
- currentHookNameInDev = 'useCacheRefresh';
5108
- mountHookTypesDev();
5109
- return mountRefresh();
5110
- };
5111
- }
5085
if (enableUseEffectEventHook) {
5086
(InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher).useEffectEvent =
5087
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -5328,15 +5301,12 @@ if (__DEV__) {
5301
return useMemoCache(size);
5302
},
5303
useHostTransitionStatus,
5304
+ useCacheRefresh() {
5305
+ currentHookNameInDev = 'useCacheRefresh';
5306
+ updateHookTypesDev();
5307
+ return updateRefresh();
5308
+ },
5309
};
5332
- if (enableCache) {
5333
- (InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useCacheRefresh =
5334
- function useCacheRefresh() {
5335
- currentHookNameInDev = 'useCacheRefresh';
5336
- updateHookTypesDev();
5337
- return updateRefresh();
5338
- };
5339
- }
5310
if (enableUseEffectEventHook) {
5311
(InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher).useEffectEvent =
5312
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
@@ -5556,15 +5526,12 @@ if (__DEV__) {
5526
return useMemoCache(size);
5527
},
5528
useHostTransitionStatus,
5529
+ useCacheRefresh() {
5530
+ currentHookNameInDev = 'useCacheRefresh';
5531
+ updateHookTypesDev();
5532
+ return updateRefresh();
5533
+ },
5534
};
5560
- if (enableCache) {
5561
- (InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useCacheRefresh =
5562
- function useCacheRefresh() {
5563
- currentHookNameInDev = 'useCacheRefresh';
5564
- updateHookTypesDev();
5565
- return updateRefresh();
5566
- };
5567
- }
5535
if (enableUseEffectEventHook) {
5536
(InvalidNestedHooksDispatcherOnRerenderInDEV: Dispatcher).useEffectEvent =
5537
function useEffectEvent<Args, Return, F: (...Array<Args>) => Return>(
packages/react-reconciler/src/ReactFiberRoot.js
+20
-32
@@ -28,7 +28,6 @@ import {
28
} from './ReactFiberLane';
29
import {
30
enableSuspenseCallback,
31
- enableCache,
31
enableProfilerCommitHooks,
32
enableProfilerTimer,
33
enableUpdaterTracking,
@@ -91,10 +90,8 @@ function FiberRootNode(
90
this.onCaughtError = onCaughtError;
91
this.onRecoverableError = onRecoverableError;
92
94
- if (enableCache) {
95
- this.pooledCache = null;
96
- this.pooledCacheLanes = NoLanes;
97
- }
93
+ this.pooledCache = null;
94
+ this.pooledCacheLanes = NoLanes;
95
96
if (enableSuspenseCallback) {
97
this.hydrationCallbacks = null;
@@ -196,33 +193,24 @@ export function createFiberRoot(
193
root.current = uninitializedFiber;
194
uninitializedFiber.stateNode = root;
195
199
- if (enableCache) {
200
- const initialCache = createCache();
201
- retainCache(initialCache);
202
-
203
- // The pooledCache is a fresh cache instance that is used temporarily
204
- // for newly mounted boundaries during a render. In general, the
205
- // pooledCache is always cleared from the root at the end of a render:
206
- // it is either released when render commits, or moved to an Offscreen
207
- // component if rendering suspends. Because the lifetime of the pooled
208
- // cache is distinct from the main memoizedState.cache, it must be
209
- // retained separately.
210
- root.pooledCache = initialCache;
211
- retainCache(initialCache);
212
- const initialState: RootState = {
213
- element: initialChildren,
214
- isDehydrated: hydrate,
215
- cache: initialCache,
216
- };
217
- uninitializedFiber.memoizedState = initialState;
218
- } else {
219
- const initialState: RootState = {
220
- element: initialChildren,
221
- isDehydrated: hydrate,
222
- cache: (null: any), // not enabled yet
223
- };
224
- uninitializedFiber.memoizedState = initialState;
225
- }
196
+ const initialCache = createCache();
197
+ retainCache(initialCache);
198
+
199
+ // The pooledCache is a fresh cache instance that is used temporarily
200
+ // for newly mounted boundaries during a render. In general, the
201
+ // pooledCache is always cleared from the root at the end of a render:
202
+ // it is either released when render commits, or moved to an Offscreen
203
+ // component if rendering suspends. Because the lifetime of the pooled
204
+ // cache is distinct from the main memoizedState.cache, it must be
205
+ // retained separately.
206
+ root.pooledCache = initialCache;
207
+ retainCache(initialCache);
208
+ const initialState: RootState = {
209
+ element: initialChildren,
210
+ isDehydrated: hydrate,
211
+ cache: initialCache,
212
+ };
213
+ uninitializedFiber.memoizedState = initialState;
214
215
initializeUpdateQueue(uninitializedFiber);
216
packages/react-reconciler/src/ReactFiberTransition.js
+6
-21
@@ -16,7 +16,7 @@ import type {
16
Transition,
17
} from './ReactFiberTracingMarkerComponent';
18
19
-import {enableCache, enableTransitionTracing} from 'shared/ReactFeatureFlags';
19
+import {enableTransitionTracing} from 'shared/ReactFeatureFlags';
20
import {isPrimaryRenderer} from './ReactFiberConfig';
21
import {createCursor, push, pop} from './ReactFiberStack';
22
import {
@@ -98,10 +98,6 @@ const transitionStack: StackCursor<Array<Transition> | null> =
98
createCursor(null);
99
100
function peekCacheFromPool(): Cache | null {
101
- if (!enableCache) {
102
- return (null: any);
103
- }
104
-
101
// Check if the cache pool already has a cache we can use.
102
103
// If we're rendering inside a Suspense boundary that is currently hidden,
@@ -173,12 +169,10 @@ export function pushTransition(
169
prevCachePool: SpawnedCachePool | null,
170
newTransitions: Array<Transition> | null,
171
): void {
176
- if (enableCache) {
177
- if (prevCachePool === null) {
178
- push(resumedCache, resumedCache.current, offscreenWorkInProgress);
179
- } else {
180
- push(resumedCache, prevCachePool.pool, offscreenWorkInProgress);
181
- }
172
+ if (prevCachePool === null) {
173
+ push(resumedCache, resumedCache.current, offscreenWorkInProgress);
174
+ } else {
175
+ push(resumedCache, prevCachePool.pool, offscreenWorkInProgress);
176
}
177
178
if (enableTransitionTracing) {
@@ -202,9 +196,7 @@ export function popTransition(workInProgress: Fiber, current: Fiber | null) {
196
pop(transitionStack, workInProgress);
197
}
198
205
- if (enableCache) {
206
- pop(resumedCache, workInProgress);
207
- }
199
+ pop(resumedCache, workInProgress);
200
}
201
}
202
@@ -217,9 +209,6 @@ export function getPendingTransitions(): Array<Transition> | null {
209
}
210
211
export function getSuspendedCache(): SpawnedCachePool | null {
220
- if (!enableCache) {
221
- return null;
222
- }
212
// This function is called when a Suspense boundary suspends. It returns the
213
// cache that would have been used to render fresh data during this render,
214
// if there was any, so that we can resume rendering with the same cache when
@@ -240,10 +229,6 @@ export function getSuspendedCache(): SpawnedCachePool | null {
229
}
230
231
export function getOffscreenDeferredCache(): SpawnedCachePool | null {
243
- if (!enableCache) {
244
- return null;
245
- }
246
-
232
const cacheFromPool = peekCacheFromPool();
233
if (cacheFromPool === null) {
234
return null;
packages/react-reconciler/src/ReactFiberUnwindWork.js
+8
-17
@@ -33,7 +33,6 @@ import {DidCapture, NoFlags, ShouldCapture} from './ReactFiberFlags';
33
import {NoMode, ProfileMode} from './ReactTypeOfMode';
34
import {
35
enableProfilerTimer,
36
- enableCache,
36
enableTransitionTracing,
37
enableRenderableContext,
38
} from 'shared/ReactFeatureFlags';
@@ -91,10 +90,8 @@ function unwindWork(
90
}
91
case HostRoot: {
92
const root: FiberRoot = workInProgress.stateNode;
94
- if (enableCache) {
95
- const cache: Cache = workInProgress.memoizedState.cache;
96
- popCacheProvider(workInProgress, cache);
97
- }
93
+ const cache: Cache = workInProgress.memoizedState.cache;
94
+ popCacheProvider(workInProgress, cache);
95
96
if (enableTransitionTracing) {
97
popRootMarkerInstance(workInProgress);
@@ -189,10 +186,8 @@ function unwindWork(
186
return null;
187
}
188
case CacheComponent:
192
- if (enableCache) {
193
- const cache: Cache = workInProgress.memoizedState.cache;
194
- popCacheProvider(workInProgress, cache);
195
- }
189
+ const cache: Cache = workInProgress.memoizedState.cache;
190
+ popCacheProvider(workInProgress, cache);
191
return null;
192
case TracingMarkerComponent:
193
if (enableTransitionTracing) {
@@ -226,10 +221,8 @@ function unwindInterruptedWork(
221
}
222
case HostRoot: {
223
const root: FiberRoot = interruptedWork.stateNode;
229
- if (enableCache) {
230
- const cache: Cache = interruptedWork.memoizedState.cache;
231
- popCacheProvider(interruptedWork, cache);
232
- }
224
+ const cache: Cache = interruptedWork.memoizedState.cache;
225
+ popCacheProvider(interruptedWork, cache);
226
227
if (enableTransitionTracing) {
228
popRootMarkerInstance(interruptedWork);
@@ -271,10 +264,8 @@ function unwindInterruptedWork(
264
popTransition(interruptedWork, current);
265
break;
266
case CacheComponent:
274
- if (enableCache) {
275
- const cache: Cache = interruptedWork.memoizedState.cache;
276
- popCacheProvider(interruptedWork, cache);
277
- }
267
+ const cache: Cache = interruptedWork.memoizedState.cache;
268
+ popCacheProvider(interruptedWork, cache);
269
break;
270
case TracingMarkerComponent:
271
if (enableTransitionTracing) {
packages/react-reconciler/src/ReactFiberWorkLoop.js
+12
-21
@@ -31,7 +31,6 @@ import {
31
enableProfilerNestedUpdatePhase,
32
enableSchedulingProfiler,
33
enableUpdaterTracking,
34
- enableCache,
34
enableTransitionTracing,
35
useModernStrictMode,
36
disableLegacyContext,
@@ -2113,19 +2112,13 @@ function popDispatcher(prevDispatcher: any) {
2112
}
2113
2114
function pushAsyncDispatcher() {
2116
- if (enableCache || __DEV__) {
2117
- const prevAsyncDispatcher = ReactSharedInternals.A;
2118
- ReactSharedInternals.A = DefaultAsyncDispatcher;
2119
- return prevAsyncDispatcher;
2120
- } else {
2121
- return null;
2122
- }
2115
+ const prevAsyncDispatcher = ReactSharedInternals.A;
2116
+ ReactSharedInternals.A = DefaultAsyncDispatcher;
2117
+ return prevAsyncDispatcher;
2118
}
2119
2120
function popAsyncDispatcher(prevAsyncDispatcher: any) {
2126
- if (enableCache || __DEV__) {
2127
- ReactSharedInternals.A = prevAsyncDispatcher;
2128
- }
2121
+ ReactSharedInternals.A = prevAsyncDispatcher;
2122
}
2123
2124
export function markCommitTimeOfFallback() {
@@ -3587,16 +3580,14 @@ function makeErrorInfo(componentStack: ?string) {
3580
}
3581
3582
function releaseRootPooledCache(root: FiberRoot, remainingLanes: Lanes) {
3590
- if (enableCache) {
3591
- const pooledCacheLanes = (root.pooledCacheLanes &= remainingLanes);
3592
- if (pooledCacheLanes === NoLanes) {
3593
- // None of the remaining work relies on the cache pool. Clear it so
3594
- // subsequent requests get a new cache
3595
- const pooledCache = root.pooledCache;
3596
- if (pooledCache != null) {
3597
- root.pooledCache = null;
3598
- releaseCache(pooledCache);
3599
- }
3583
+ const pooledCacheLanes = (root.pooledCacheLanes &= remainingLanes);
3584
+ if (pooledCacheLanes === NoLanes) {
3585
+ // None of the remaining work relies on the cache pool. Clear it so
3586
+ // subsequent requests get a new cache
3587
+ const pooledCache = root.pooledCache;
3588
+ if (pooledCache != null) {
3589
+ root.pooledCache = null;
3590
+ releaseCache(pooledCache);
3591
}
3592
}
3593
}
packages/react-reconciler/src/__tests__/ReactCache-test.js
-3
@@ -30,7 +30,6 @@ describe('ReactCache', () => {
30
__unmockReact();
31
});
32
33
- // @gate enableCache
33
it('cache objects and primitive arguments and a mix of them', async () => {
34
const types = cache((a, b) => ({a: typeof a, b: typeof b}));
35
function Print({a, b}) {
@@ -170,7 +169,6 @@ describe('ReactCache', () => {
169
).toEqual('number number true false false false ');
170
});
171
173
- // @gate enableCache
172
it('cached functions that throw should cache the error', async () => {
173
const throws = cache(v => {
174
throw new Error(v);
@@ -203,7 +201,6 @@ describe('ReactCache', () => {
201
expect(z).not.toBe(x);
202
});
203
206
- // @gate enableCache
204
it('introspection of returned wrapper function is same on client and server', async () => {
205
// When the variant flag is true, test the client version of `cache`.
206
if (gate(flags => flags.variant)) {
packages/react-server/src/ReactFizzHooks.js
+1
-4
@@ -39,7 +39,6 @@ import {
39
import {createFastHash} from './ReactServerStreamConfig';
40
41
import {
42
- enableCache,
42
enableUseEffectEventHook,
43
enableUseResourceEffectHook,
44
} from 'shared/ReactFeatureFlags';
@@ -859,11 +858,9 @@ export const HooksDispatcher: Dispatcher = supportsClientAPIs
858
useFormState: useActionState,
859
useHostTransitionStatus,
860
useMemoCache,
861
+ useCacheRefresh,
862
};
863
864
-if (enableCache) {
865
- HooksDispatcher.useCacheRefresh = useCacheRefresh;
866
-}
864
if (enableUseEffectEventHook) {
865
HooksDispatcher.useEffectEvent = useEffectEvent;
866
}
packages/react-server/src/ReactFizzServer.js
+3
-9
@@ -152,7 +152,6 @@ import {
152
disableLegacyContext,
153
disableLegacyContextForFunctionComponents,
154
enableScopeAPI,
155
- enableCache,
155
enablePostpone,
156
enableHalt,
157
enableRenderableContext,
@@ -4416,11 +4415,8 @@ export function performWork(request: Request): void {
4415
const prevContext = getActiveContext();
4416
const prevDispatcher = ReactSharedInternals.H;
4417
ReactSharedInternals.H = HooksDispatcher;
4419
- let prevAsyncDispatcher = null;
4420
- if (enableCache || __DEV__) {
4421
- prevAsyncDispatcher = ReactSharedInternals.A;
4422
- ReactSharedInternals.A = DefaultAsyncDispatcher;
4423
- }
4418
+ const prevAsyncDispatcher = ReactSharedInternals.A;
4419
+ ReactSharedInternals.A = DefaultAsyncDispatcher;
4420
4421
const prevRequest = currentRequest;
4422
currentRequest = request;
@@ -4450,9 +4446,7 @@ export function performWork(request: Request): void {
4446
} finally {
4447
setCurrentResumableState(prevResumableState);
4448
ReactSharedInternals.H = prevDispatcher;
4453
- if (enableCache) {
4454
- ReactSharedInternals.A = prevAsyncDispatcher;
4455
- }
4449
+ ReactSharedInternals.A = prevAsyncDispatcher;
4450
4451
if (__DEV__) {
4452
ReactSharedInternals.getCurrentStack = prevGetCurrentStackImpl;
packages/shared/ReactFeatureFlags.js
-1
@@ -77,7 +77,6 @@ export const enableLegacyFBSupport = false;
77
// likely to include in an upcoming release.
78
// -----------------------------------------------------------------------------
79
80
-export const enableCache = true;
80
export const enableLegacyCache = __EXPERIMENTAL__;
81
82
export const enableAsyncIterableChildren = __EXPERIMENTAL__;
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -44,7 +44,6 @@ export const disableSchedulerTimeoutInWorkLoop = false;
44
export const disableTextareaChildren = false;
45
export const enableAsyncDebugInfo = false;
46
export const enableAsyncIterableChildren = false;
47
-export const enableCache = true;
47
export const enableCPUSuspense = true;
48
export const enableCreateEventHandleAPI = false;
49
export const enableDeferRootSchedulingToMicrotask = true;
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -31,7 +31,6 @@ export const disableSchedulerTimeoutInWorkLoop = false;
31
export const disableTextareaChildren = false;
32
export const enableAsyncDebugInfo = false;
33
export const enableAsyncIterableChildren = false;
34
-export const enableCache = true;
34
export const enableCPUSuspense = false;
35
export const enableCreateEventHandleAPI = false;
36
export const enableDeferRootSchedulingToMicrotask = true;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -18,7 +18,6 @@ export const enableProfilerCommitHooks = __PROFILE__;
18
export const enableProfilerNestedUpdatePhase = __PROFILE__;
19
export const enableComponentPerformanceTrack = false;
20
export const enableUpdaterTracking = false;
21
-export const enableCache = true;
21
export const enableLegacyCache = __EXPERIMENTAL__;
22
export const enableAsyncIterableChildren = false;
23
export const enableTaint = true;
packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js
-1
@@ -23,7 +23,6 @@ export const disableSchedulerTimeoutInWorkLoop = false;
23
export const disableTextareaChildren = false;
24
export const enableAsyncDebugInfo = false;
25
export const enableAsyncIterableChildren = false;
26
-export const enableCache = true;
26
export const enableCPUSuspense = true;
27
export const enableCreateEventHandleAPI = false;
28
export const enableDeferRootSchedulingToMicrotask = true;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -18,7 +18,6 @@ export const enableProfilerCommitHooks = __PROFILE__;
18
export const enableProfilerNestedUpdatePhase = __PROFILE__;
19
export const enableComponentPerformanceTrack = false;
20
export const enableUpdaterTracking = false;
21
-export const enableCache = true;
21
export const enableLegacyCache = true;
22
export const enableAsyncIterableChildren = false;
23
export const enableTaint = true;
packages/shared/forks/ReactFeatureFlags.www.js
-1
@@ -69,7 +69,6 @@ export const enableSchedulingProfiler: boolean =
69
export const disableLegacyContext = __EXPERIMENTAL__;
70
export const enableGetInspectorDataForInstanceInProduction = false;
71
72
-export const enableCache = true;
72
export const enableLegacyCache = true;
73
74
export const enableAsyncIterableChildren = false;