Skip to content

Commit dcf04a4

Browse files
committed
wrap new functions in feature flag
1 parent faf84fe commit dcf04a4

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

packages/react-reconciler/src/ReactFiberCacheComponent.new.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ const prevFreshCacheOnStack: StackCursor<Cache | null> = createCursor(null);
7373
// for retaining the cache once it is in use (retainCache), and releasing the cache
7474
// once it is no longer needed (releaseCache).
7575
export function createCache(): Cache {
76+
if (!enableCache) {
77+
return (null: any);
78+
}
7679
const cache: Cache = {
7780
controller: new AbortController(),
7881
data: new Map(),
@@ -83,6 +86,9 @@ export function createCache(): Cache {
8386
}
8487

8588
export function retainCache(cache: Cache) {
89+
if (!enableCache) {
90+
return;
91+
}
8692
if (__DEV__) {
8793
if (cache.controller.signal.aborted) {
8894
console.warn(
@@ -96,6 +102,9 @@ export function retainCache(cache: Cache) {
96102

97103
// Cleanup a cache instance, potentially freeing it if there are no more references
98104
export function releaseCache(cache: Cache) {
105+
if (!enableCache) {
106+
return;
107+
}
99108
cache.refCount--;
100109
if (__DEV__) {
101110
if (cache.refCount < 0) {

packages/react-reconciler/src/ReactFiberCacheComponent.old.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ const prevFreshCacheOnStack: StackCursor<Cache | null> = createCursor(null);
7373
// for retaining the cache once it is in use (retainCache), and releasing the cache
7474
// once it is no longer needed (releaseCache).
7575
export function createCache(): Cache {
76+
if (!enableCache) {
77+
return (null: any);
78+
}
7679
const cache: Cache = {
7780
controller: new AbortController(),
7881
data: new Map(),
@@ -83,6 +86,9 @@ export function createCache(): Cache {
8386
}
8487

8588
export function retainCache(cache: Cache) {
89+
if (!enableCache) {
90+
return;
91+
}
8692
if (__DEV__) {
8793
if (cache.controller.signal.aborted) {
8894
console.warn(
@@ -96,6 +102,9 @@ export function retainCache(cache: Cache) {
96102

97103
// Cleanup a cache instance, potentially freeing it if there are no more references
98104
export function releaseCache(cache: Cache) {
105+
if (!enableCache) {
106+
return;
107+
}
99108
cache.refCount--;
100109
if (__DEV__) {
101110
if (cache.refCount < 0) {

packages/react-reconciler/src/ReactFiberHooks.new.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,9 @@ function updateRefresh() {
21242124
}
21252125

21262126
function refreshCache<T>(fiber: Fiber, seedKey: ?() => T, seedValue: T) {
2127+
if (!enableCache) {
2128+
return;
2129+
}
21272130
// TODO: Does Cache work in legacy mode? Should decide and write a test.
21282131
// TODO: Consider warning if the refresh is at discrete priority, or if we
21292132
// otherwise suspect that it wasn't batched properly.

packages/react-reconciler/src/ReactFiberHooks.old.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,9 @@ function updateRefresh() {
21242124
}
21252125

21262126
function refreshCache<T>(fiber: Fiber, seedKey: ?() => T, seedValue: T) {
2127+
if (!enableCache) {
2128+
return;
2129+
}
21272130
// TODO: Does Cache work in legacy mode? Should decide and write a test.
21282131
// TODO: Consider warning if the refresh is at discrete priority, or if we
21292132
// otherwise suspect that it wasn't batched properly.

0 commit comments

Comments
 (0)