Skip to content

Commit 6ed28ff

Browse files
committed
old
1 parent 55dd695 commit 6ed28ff

File tree

6 files changed

+337
-178
lines changed

6 files changed

+337
-178
lines changed

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,7 @@ import {
229229
getWorkInProgressTransitions,
230230
} from './ReactFiberWorkLoop.old';
231231
import {setWorkInProgressVersion} from './ReactMutableSource.old';
232-
import {
233-
requestCacheFromPool,
234-
pushCacheProvider,
235-
pushRootCachePool,
236-
CacheContext,
237-
getSuspendedCachePool,
238-
pushSpawnedCachePool,
239-
getOffscreenDeferredCachePool,
240-
} from './ReactFiberCacheComponent.old';
232+
import {pushCacheProvider, CacheContext} from './ReactFiberCacheComponent.old';
241233
import {createCapturedValue} from './ReactCapturedValue';
242234
import {createClassErrorUpdate} from './ReactFiberThrow.old';
243235
import {completeSuspendedOffscreenHostContainer} from './ReactFiberCompleteWork.old';
@@ -248,6 +240,13 @@ import {
248240
pushTreeId,
249241
pushMaterializedTreeId,
250242
} from './ReactFiberTreeContext.old';
243+
import {
244+
requestCache,
245+
pushRootTransition,
246+
getSuspendedCache,
247+
pushTransition,
248+
getOffscreenDeferredCache,
249+
} from './ReactFiberTransition.old';
251250

252251
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
253252

@@ -652,7 +651,7 @@ function updateOffscreenComponent(
652651
// push the cache pool even though we're going to bail out
653652
// because otherwise there'd be a context mismatch
654653
if (current !== null) {
655-
pushSpawnedCachePool(workInProgress, null);
654+
pushTransition(workInProgress, null);
656655
}
657656
}
658657
pushRenderLanes(workInProgress, renderLanes);
@@ -666,7 +665,7 @@ function updateOffscreenComponent(
666665
nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
667666
if (enableCache) {
668667
// Save the cache pool so we can resume later.
669-
spawnedCachePool = getOffscreenDeferredCachePool();
668+
spawnedCachePool = getOffscreenDeferredCache();
670669
}
671670
} else {
672671
nextBaseLanes = renderLanes;
@@ -686,7 +685,7 @@ function updateOffscreenComponent(
686685
// push the cache pool even though we're going to bail out
687686
// because otherwise there'd be a context mismatch
688687
if (current !== null) {
689-
pushSpawnedCachePool(workInProgress, null);
688+
pushTransition(workInProgress, null);
690689
}
691690
}
692691

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

730729
pushRenderLanes(workInProgress, subtreeRenderLanes);
@@ -742,7 +741,7 @@ function updateOffscreenComponent(
742741
// using the same cache. Unless the parent changed, since that means
743742
// there was a refresh.
744743
const prevCachePool = prevState.cachePool;
745-
pushSpawnedCachePool(workInProgress, prevCachePool);
744+
pushTransition(workInProgress, prevCachePool);
746745
}
747746

748747
// Since we're not hidden anymore, reset the state
@@ -758,7 +757,7 @@ function updateOffscreenComponent(
758757
// using the same cache. Unless the parent changed, since that means
759758
// there was a refresh.
760759
if (current !== null) {
761-
pushSpawnedCachePool(workInProgress, null);
760+
pushTransition(workInProgress, null);
762761
}
763762
}
764763
}
@@ -847,7 +846,7 @@ function updateCacheComponent(
847846

848847
if (current === null) {
849848
// Initial mount. Request a fresh cache from the pool.
850-
const freshCache = requestCacheFromPool(renderLanes);
849+
const freshCache = requestCache(renderLanes);
851850
const initialState: CacheComponentState = {
852851
parent: parentCache,
853852
cache: freshCache,
@@ -1329,7 +1328,7 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13291328

13301329
if (enableCache) {
13311330
const nextCache: Cache = nextState.cache;
1332-
pushRootCachePool(root);
1331+
pushRootTransition(root);
13331332
pushCacheProvider(workInProgress, nextCache);
13341333
if (nextCache !== prevState.cache) {
13351334
// The root cache refreshed.
@@ -1910,7 +1909,7 @@ const SUSPENDED_MARKER: SuspenseState = {
19101909
function mountSuspenseOffscreenState(renderLanes: Lanes): OffscreenState {
19111910
return {
19121911
baseLanes: renderLanes,
1913-
cachePool: getSuspendedCachePool(),
1912+
cachePool: getSuspendedCache(),
19141913
};
19151914
}
19161915

@@ -1939,7 +1938,7 @@ function updateSuspenseOffscreenState(
19391938
}
19401939
} else {
19411940
// If there's no previous cache pool, grab the current one.
1942-
cachePool = getSuspendedCachePool();
1941+
cachePool = getSuspendedCache();
19431942
}
19441943
}
19451944
return {
@@ -3504,7 +3503,7 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
35043503
if (enableCache) {
35053504
const cache: Cache = current.memoizedState.cache;
35063505
pushCacheProvider(workInProgress, cache);
3507-
pushRootCachePool(root);
3506+
pushRootTransition(root);
35083507
}
35093508
if (enableTransitionTracing) {
35103509
workInProgress.memoizedState.transitions = getWorkInProgressTransitions();

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

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@
88
*/
99

1010
import type {ReactContext} from 'shared/ReactTypes';
11-
import type {FiberRoot} from './ReactInternalTypes';
12-
import type {Lanes} from './ReactFiberLane.old';
13-
import type {StackCursor} from './ReactFiberStack.old';
1411

1512
import {enableCache} from 'shared/ReactFeatureFlags';
1613
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
1714

18-
import {isPrimaryRenderer} from './ReactFiberHostConfig';
19-
import {createCursor, push, pop} from './ReactFiberStack.old';
2015
import {pushProvider, popProvider} from './ReactFiberNewContext.old';
2116
import * as Scheduler from 'scheduler';
22-
import {getWorkInProgressRoot} from './ReactFiberWorkLoop.old';
2317

2418
export type Cache = {|
2519
controller: AbortController,
@@ -62,10 +56,6 @@ if (__DEV__ && enableCache) {
6256
CacheContext._currentRenderer2 = null;
6357
}
6458

65-
// When retrying a Suspense/Offscreen boundary, we restore the cache that was
66-
// used during the previous render by placing it here, on the stack.
67-
const resumedCache: StackCursor<Cache | null> = createCursor(null);
68-
6959
// Creates a new empty Cache instance with a ref-count of 0. The caller is responsible
7060
// for retaining the cache once it is in use (retainCache), and releasing the cache
7161
// once it is no longer needed (releaseCache).
@@ -131,135 +121,3 @@ export function popCacheProvider(workInProgress: Fiber, cache: Cache) {
131121
}
132122
popProvider(CacheContext, workInProgress);
133123
}
134-
135-
function peekCacheFromPool(): Cache | null {
136-
if (!enableCache) {
137-
return (null: any);
138-
}
139-
140-
// Check if the cache pool already has a cache we can use.
141-
142-
// If we're rendering inside a Suspense boundary that is currently hidden,
143-
// we should use the same cache that we used during the previous render, if
144-
// one exists.
145-
const cacheResumedFromPreviousRender = resumedCache.current;
146-
if (cacheResumedFromPreviousRender !== null) {
147-
return cacheResumedFromPreviousRender;
148-
}
149-
150-
// Otherwise, check the root's cache pool.
151-
const root = (getWorkInProgressRoot(): any);
152-
const cacheFromRootCachePool = root.pooledCache;
153-
154-
return cacheFromRootCachePool;
155-
}
156-
157-
export function requestCacheFromPool(renderLanes: Lanes): Cache {
158-
// Similar to previous function, except if there's not already a cache in the
159-
// pool, we allocate a new one.
160-
const cacheFromPool = peekCacheFromPool();
161-
if (cacheFromPool !== null) {
162-
return cacheFromPool;
163-
}
164-
165-
// Create a fresh cache and add it to the root cache pool. A cache can have
166-
// multiple owners:
167-
// - A cache pool that lives on the FiberRoot. This is where all fresh caches
168-
// are originally created (TODO: except during refreshes, until we implement
169-
// this correctly). The root takes ownership immediately when the cache is
170-
// created. Conceptually, root.pooledCache is an Option<Arc<Cache>> (owned),
171-
// and the return value of this function is a &Arc<Cache> (borrowed).
172-
// - One of several fiber types: host root, cache boundary, suspense
173-
// component. These retain and release in the commit phase.
174-
175-
const root = (getWorkInProgressRoot(): any);
176-
const freshCache = createCache();
177-
root.pooledCache = freshCache;
178-
retainCache(freshCache);
179-
if (freshCache !== null) {
180-
root.pooledCacheLanes |= renderLanes;
181-
}
182-
return freshCache;
183-
}
184-
185-
export function pushRootCachePool(root: FiberRoot) {
186-
if (!enableCache) {
187-
return;
188-
}
189-
// Note: This function currently does nothing but I'll leave it here for
190-
// code organization purposes in case that changes.
191-
}
192-
193-
export function popRootCachePool(root: FiberRoot, renderLanes: Lanes) {
194-
if (!enableCache) {
195-
return;
196-
}
197-
// Note: This function currently does nothing but I'll leave it here for
198-
// code organization purposes in case that changes.
199-
}
200-
201-
export function pushSpawnedCachePool(
202-
offscreenWorkInProgress: Fiber,
203-
prevCachePool: SpawnedCachePool | null,
204-
): void {
205-
if (!enableCache) {
206-
return;
207-
}
208-
209-
if (prevCachePool === null) {
210-
push(resumedCache, resumedCache.current, offscreenWorkInProgress);
211-
} else {
212-
push(resumedCache, prevCachePool.pool, offscreenWorkInProgress);
213-
}
214-
}
215-
216-
export function popCachePool(workInProgress: Fiber) {
217-
if (!enableCache) {
218-
return;
219-
}
220-
221-
pop(resumedCache, workInProgress);
222-
}
223-
224-
export function getSuspendedCachePool(): SpawnedCachePool | null {
225-
if (!enableCache) {
226-
return null;
227-
}
228-
// This function is called when a Suspense boundary suspends. It returns the
229-
// cache that would have been used to render fresh data during this render,
230-
// if there was any, so that we can resume rendering with the same cache when
231-
// we receive more data.
232-
const cacheFromPool = peekCacheFromPool();
233-
if (cacheFromPool === null) {
234-
return null;
235-
}
236-
237-
return {
238-
// We must also save the parent, so that when we resume we can detect
239-
// a refresh.
240-
parent: isPrimaryRenderer
241-
? CacheContext._currentValue
242-
: CacheContext._currentValue2,
243-
pool: cacheFromPool,
244-
};
245-
}
246-
247-
export function getOffscreenDeferredCachePool(): SpawnedCachePool | null {
248-
if (!enableCache) {
249-
return null;
250-
}
251-
252-
const cacheFromPool = peekCacheFromPool();
253-
if (cacheFromPool === null) {
254-
return null;
255-
}
256-
257-
return {
258-
// We must also store the parent, so that when we resume we can detect
259-
// a refresh.
260-
parent: isPrimaryRenderer
261-
? CacheContext._currentValue
262-
: CacheContext._currentValue2,
263-
pool: cacheFromPool,
264-
};
265-
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,9 @@ import {
162162
import {resetChildFibers} from './ReactChildFiber.old';
163163
import {createScopeInstance} from './ReactFiberScope.old';
164164
import {transferActualDuration} from './ReactProfilerTimer.old';
165-
import {
166-
popCacheProvider,
167-
popRootCachePool,
168-
popCachePool,
169-
} from './ReactFiberCacheComponent.old';
165+
import {popCacheProvider} from './ReactFiberCacheComponent.old';
170166
import {popTreeContext} from './ReactFiberTreeContext.old';
167+
import {popRootTransition, popTransition} from './ReactFiberTransition.old';
171168

172169
function markUpdate(workInProgress: Fiber) {
173170
// Tag the fiber with an update effect. This turns a Placement into
@@ -864,7 +861,7 @@ function completeWork(
864861
case HostRoot: {
865862
const fiberRoot = (workInProgress.stateNode: FiberRoot);
866863
if (enableCache) {
867-
popRootCachePool(fiberRoot, renderLanes);
864+
popRootTransition(fiberRoot, renderLanes);
868865

869866
let previousCache: Cache | null = null;
870867
if (current !== null) {
@@ -1553,7 +1550,7 @@ function completeWork(
15531550
workInProgress.flags |= Passive;
15541551
}
15551552
if (current !== null) {
1556-
popCachePool(workInProgress);
1553+
popTransition(workInProgress);
15571554
}
15581555
}
15591556

0 commit comments

Comments
 (0)