Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Cache Code #23393

Merged
merged 2 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,7 @@ import {
getWorkInProgressTransitions,
} from './ReactFiberWorkLoop.new';
import {setWorkInProgressVersion} from './ReactMutableSource.new';
import {
requestCacheFromPool,
pushCacheProvider,
pushRootCachePool,
CacheContext,
getSuspendedCachePool,
pushSpawnedCachePool,
getOffscreenDeferredCachePool,
} from './ReactFiberCacheComponent.new';
import {pushCacheProvider, CacheContext} from './ReactFiberCacheComponent.new';
import {createCapturedValue} from './ReactCapturedValue';
import {createClassErrorUpdate} from './ReactFiberThrow.new';
import {completeSuspendedOffscreenHostContainer} from './ReactFiberCompleteWork.new';
Expand All @@ -248,6 +240,13 @@ import {
pushTreeId,
pushMaterializedTreeId,
} from './ReactFiberTreeContext.new';
import {
requestCacheFromPool,
pushRootTransition,
getSuspendedCache,
pushTransition,
getOffscreenDeferredCache,
} from './ReactFiberTransition.new';

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

Expand Down Expand Up @@ -652,7 +651,7 @@ function updateOffscreenComponent(
// push the cache pool even though we're going to bail out
// because otherwise there'd be a context mismatch
if (current !== null) {
pushSpawnedCachePool(workInProgress, null);
pushTransition(workInProgress, null);
}
}
pushRenderLanes(workInProgress, renderLanes);
Expand All @@ -666,7 +665,7 @@ function updateOffscreenComponent(
nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
if (enableCache) {
// Save the cache pool so we can resume later.
spawnedCachePool = getOffscreenDeferredCachePool();
spawnedCachePool = getOffscreenDeferredCache();
}
} else {
nextBaseLanes = renderLanes;
Expand All @@ -686,7 +685,7 @@ function updateOffscreenComponent(
// push the cache pool even though we're going to bail out
// because otherwise there'd be a context mismatch
if (current !== null) {
pushSpawnedCachePool(workInProgress, null);
pushTransition(workInProgress, null);
}
}

Expand Down Expand Up @@ -724,7 +723,7 @@ function updateOffscreenComponent(
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
const prevCachePool = prevState !== null ? prevState.cachePool : null;
pushSpawnedCachePool(workInProgress, prevCachePool);
pushTransition(workInProgress, prevCachePool);
}

pushRenderLanes(workInProgress, subtreeRenderLanes);
Expand All @@ -742,7 +741,7 @@ function updateOffscreenComponent(
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
const prevCachePool = prevState.cachePool;
pushSpawnedCachePool(workInProgress, prevCachePool);
pushTransition(workInProgress, prevCachePool);
}

// Since we're not hidden anymore, reset the state
Expand All @@ -758,7 +757,7 @@ function updateOffscreenComponent(
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
if (current !== null) {
pushSpawnedCachePool(workInProgress, null);
pushTransition(workInProgress, null);
}
}
}
Expand Down Expand Up @@ -1329,7 +1328,7 @@ function updateHostRoot(current, workInProgress, renderLanes) {

if (enableCache) {
const nextCache: Cache = nextState.cache;
pushRootCachePool(root);
pushRootTransition(root);
pushCacheProvider(workInProgress, nextCache);
if (nextCache !== prevState.cache) {
// The root cache refreshed.
Expand Down Expand Up @@ -1910,7 +1909,7 @@ const SUSPENDED_MARKER: SuspenseState = {
function mountSuspenseOffscreenState(renderLanes: Lanes): OffscreenState {
return {
baseLanes: renderLanes,
cachePool: getSuspendedCachePool(),
cachePool: getSuspendedCache(),
};
}

Expand Down Expand Up @@ -1939,7 +1938,7 @@ function updateSuspenseOffscreenState(
}
} else {
// If there's no previous cache pool, grab the current one.
cachePool = getSuspendedCachePool();
cachePool = getSuspendedCache();
}
}
return {
Expand Down Expand Up @@ -3504,7 +3503,7 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
if (enableCache) {
const cache: Cache = current.memoizedState.cache;
pushCacheProvider(workInProgress, cache);
pushRootCachePool(root);
pushRootTransition(root);
}
if (enableTransitionTracing) {
workInProgress.memoizedState.transitions = getWorkInProgressTransitions();
Expand Down
37 changes: 18 additions & 19 deletions packages/react-reconciler/src/ReactFiberBeginWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,7 @@ import {
getWorkInProgressTransitions,
} from './ReactFiberWorkLoop.old';
import {setWorkInProgressVersion} from './ReactMutableSource.old';
import {
requestCacheFromPool,
pushCacheProvider,
pushRootCachePool,
CacheContext,
getSuspendedCachePool,
pushSpawnedCachePool,
getOffscreenDeferredCachePool,
} from './ReactFiberCacheComponent.old';
import {pushCacheProvider, CacheContext} from './ReactFiberCacheComponent.old';
import {createCapturedValue} from './ReactCapturedValue';
import {createClassErrorUpdate} from './ReactFiberThrow.old';
import {completeSuspendedOffscreenHostContainer} from './ReactFiberCompleteWork.old';
Expand All @@ -248,6 +240,13 @@ import {
pushTreeId,
pushMaterializedTreeId,
} from './ReactFiberTreeContext.old';
import {
requestCacheFromPool,
pushRootTransition,
getSuspendedCache,
pushTransition,
getOffscreenDeferredCache,
} from './ReactFiberTransition.old';

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

Expand Down Expand Up @@ -652,7 +651,7 @@ function updateOffscreenComponent(
// push the cache pool even though we're going to bail out
// because otherwise there'd be a context mismatch
if (current !== null) {
pushSpawnedCachePool(workInProgress, null);
pushTransition(workInProgress, null);
}
}
pushRenderLanes(workInProgress, renderLanes);
Expand All @@ -666,7 +665,7 @@ function updateOffscreenComponent(
nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
if (enableCache) {
// Save the cache pool so we can resume later.
spawnedCachePool = getOffscreenDeferredCachePool();
spawnedCachePool = getOffscreenDeferredCache();
}
} else {
nextBaseLanes = renderLanes;
Expand All @@ -686,7 +685,7 @@ function updateOffscreenComponent(
// push the cache pool even though we're going to bail out
// because otherwise there'd be a context mismatch
if (current !== null) {
pushSpawnedCachePool(workInProgress, null);
pushTransition(workInProgress, null);
}
}

Expand Down Expand Up @@ -724,7 +723,7 @@ function updateOffscreenComponent(
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
const prevCachePool = prevState !== null ? prevState.cachePool : null;
pushSpawnedCachePool(workInProgress, prevCachePool);
pushTransition(workInProgress, prevCachePool);
}

pushRenderLanes(workInProgress, subtreeRenderLanes);
Expand All @@ -742,7 +741,7 @@ function updateOffscreenComponent(
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
const prevCachePool = prevState.cachePool;
pushSpawnedCachePool(workInProgress, prevCachePool);
pushTransition(workInProgress, prevCachePool);
}

// Since we're not hidden anymore, reset the state
Expand All @@ -758,7 +757,7 @@ function updateOffscreenComponent(
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
if (current !== null) {
pushSpawnedCachePool(workInProgress, null);
pushTransition(workInProgress, null);
}
}
}
Expand Down Expand Up @@ -1329,7 +1328,7 @@ function updateHostRoot(current, workInProgress, renderLanes) {

if (enableCache) {
const nextCache: Cache = nextState.cache;
pushRootCachePool(root);
pushRootTransition(root);
pushCacheProvider(workInProgress, nextCache);
if (nextCache !== prevState.cache) {
// The root cache refreshed.
Expand Down Expand Up @@ -1910,7 +1909,7 @@ const SUSPENDED_MARKER: SuspenseState = {
function mountSuspenseOffscreenState(renderLanes: Lanes): OffscreenState {
return {
baseLanes: renderLanes,
cachePool: getSuspendedCachePool(),
cachePool: getSuspendedCache(),
};
}

Expand Down Expand Up @@ -1939,7 +1938,7 @@ function updateSuspenseOffscreenState(
}
} else {
// If there's no previous cache pool, grab the current one.
cachePool = getSuspendedCachePool();
cachePool = getSuspendedCache();
}
}
return {
Expand Down Expand Up @@ -3504,7 +3503,7 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
if (enableCache) {
const cache: Cache = current.memoizedState.cache;
pushCacheProvider(workInProgress, cache);
pushRootCachePool(root);
pushRootTransition(root);
}
if (enableTransitionTracing) {
workInProgress.memoizedState.transitions = getWorkInProgressTransitions();
Expand Down
Loading