Skip to content

Commit 7008630

Browse files
committed
tmp
1 parent 179e40e commit 7008630

File tree

4 files changed

+62
-58
lines changed

4 files changed

+62
-58
lines changed

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,9 @@ function updateOffscreenComponent(
664664
nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
665665
if (enableCache) {
666666
// Save the cache pool so we can resume later.
667-
const prevCachePool = prevState.cachePool;
668-
if (prevCachePool !== null) {
669-
// push the cache pool even though we're going to bail out
670-
// because otherwise there'd be a context mismatch
671-
restoreSpawnedCachePool(workInProgress, prevCachePool);
672-
}
667+
// push the cache pool even though we're going to bail out
668+
// because otherwise there'd be a context mismatch
669+
restoreSpawnedCachePool(workInProgress, null);
673670
spawnedCachePool = getOffscreenDeferredCachePool();
674671
}
675672
} else {
@@ -711,12 +708,10 @@ function updateOffscreenComponent(
711708
// using the same cache. Unless the parent changed, since that means
712709
// there was a refresh.
713710
const prevCachePool = prevState.cachePool;
714-
if (prevCachePool !== null) {
715-
spawnedCachePool = restoreSpawnedCachePool(
716-
workInProgress,
717-
prevCachePool,
718-
);
719-
}
711+
spawnedCachePool = restoreSpawnedCachePool(
712+
workInProgress,
713+
prevCachePool,
714+
);
720715
}
721716

722717
// Rendering at offscreen, so we can clear the base lanes.
@@ -743,12 +738,10 @@ function updateOffscreenComponent(
743738
// using the same cache. Unless the parent changed, since that means
744739
// there was a refresh.
745740
const prevCachePool = prevState.cachePool;
746-
if (prevCachePool !== null) {
747-
spawnedCachePool = restoreSpawnedCachePool(
748-
workInProgress,
749-
prevCachePool,
750-
);
751-
}
741+
spawnedCachePool = restoreSpawnedCachePool(
742+
workInProgress,
743+
prevCachePool,
744+
);
752745
}
753746

754747
// Since we're not hidden anymore, reset the state
@@ -758,6 +751,15 @@ function updateOffscreenComponent(
758751
// special to do. Need to push to the stack regardless, though, to avoid
759752
// a push/pop misalignment.
760753
subtreeRenderLanes = renderLanes;
754+
755+
if (enableCache) {
756+
// If the render that spawned this one accessed the cache pool, resume
757+
// using the same cache. Unless the parent changed, since that means
758+
// there was a refresh.
759+
if (current !== null) {
760+
restoreSpawnedCachePool(workInProgress, null);
761+
}
762+
}
761763
}
762764
pushRenderLanes(workInProgress, subtreeRenderLanes);
763765
}
@@ -2071,6 +2073,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
20712073

20722074
const nextPrimaryChildren = nextProps.children;
20732075
const nextFallbackChildren = nextProps.fallback;
2076+
20742077
if (showFallback) {
20752078
const fallbackFragment = mountSuspenseFallbackChildren(
20762079
workInProgress,

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

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,34 +200,57 @@ export function popRootCachePool(root: FiberRoot, renderLanes: Lanes) {
200200

201201
export function restoreSpawnedCachePool(
202202
offscreenWorkInProgress: Fiber,
203-
prevCachePool: SpawnedCachePool,
203+
prevCachePool: SpawnedCachePool | null,
204204
): SpawnedCachePool | null {
205205
if (!enableCache) {
206206
return (null: any);
207207
}
208-
const nextParentCache = isPrimaryRenderer
209-
? CacheContext._currentValue
210-
: CacheContext._currentValue2;
211-
if (nextParentCache !== prevCachePool.parent) {
212-
// There was a refresh. Don't bother restoring anything since the refresh
213-
// will override it.
208+
// console.log(
209+
// '::: push pool',
210+
// prevCachePool,
211+
// new Error().stack
212+
// .split('\n')
213+
// .slice(2, 6)
214+
// .join('\n'),
215+
// resumedCache.current,
216+
// );
217+
218+
if (prevCachePool === null) {
219+
push(resumedCache, resumedCache.current, offscreenWorkInProgress);
214220
return null;
215221
} else {
216-
// No refresh. Resume with the previous cache. New Cache boundaries in the
217-
// subtree use this one instead of requesting a fresh one (see
218-
// peekCacheFromPool).
219-
push(resumedCache, prevCachePool.pool, offscreenWorkInProgress);
220-
221-
// Return the cache pool to signal that we did in fact push it. We will
222-
// assign this to the field on the fiber so we know to pop the context.
223-
return prevCachePool;
222+
const nextParentCache = isPrimaryRenderer
223+
? CacheContext._currentValue
224+
: CacheContext._currentValue2;
225+
if (nextParentCache !== prevCachePool.parent) {
226+
// There was a refresh. Don't bother restoring anything since the refresh
227+
// will override it.
228+
return null;
229+
} else {
230+
// No refresh. Resume with the previous cache. New Cache boundaries in the
231+
// subtree use this one instead of requesting a fresh one (see
232+
// peekCacheFromPool).
233+
push(resumedCache, prevCachePool.pool, offscreenWorkInProgress);
234+
235+
// Return the cache pool to signal that we did in fact push it. We will
236+
// assign this to the field on the fiber so we know to pop the context.
237+
return prevCachePool;
238+
}
224239
}
225240
}
226241

227242
export function popCachePool(workInProgress: Fiber) {
228243
if (!enableCache) {
229244
return;
230245
}
246+
247+
// console.log(
248+
// '::: pop pool',
249+
// new Error().stack
250+
// .split('\n')
251+
// .slice(2, 6)
252+
// .join('\n'),
253+
// );
231254
pop(resumedCache, workInProgress);
232255
}
233256

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,14 +1550,7 @@ function completeWork(
15501550
// Run passive effects to retain/release the cache.
15511551
workInProgress.flags |= Passive;
15521552
}
1553-
let prevState: OffscreenState | null = null;
1554-
if (
1555-
workInProgress.alternate !== null &&
1556-
workInProgress.alternate.memoizedState !== null
1557-
) {
1558-
prevState = workInProgress.alternate.memoizedState;
1559-
}
1560-
if (prevState !== null && prevState.cachePool !== null) {
1553+
if (workInProgress.alternate !== null) {
15611554
popCachePool(workInProgress);
15621555
}
15631556
}

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {Fiber, FiberRoot} from './ReactInternalTypes';
1212
import type {Lanes} from './ReactFiberLane.new';
1313
import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
1414
import type {Cache} from './ReactFiberCacheComponent.new';
15-
import type {OffscreenState} from './ReactFiberOffscreenComponent';
1615

1716
import {resetWorkInProgressVersions as resetMutableSourceWorkInProgressVersions} from './ReactMutableSource.new';
1817
import {
@@ -153,15 +152,8 @@ function unwindWork(workInProgress: Fiber, renderLanes: Lanes) {
153152
case OffscreenComponent:
154153
case LegacyHiddenComponent:
155154
popRenderLanes(workInProgress);
156-
let prevState: OffscreenState | null = null;
157155
if (enableCache) {
158-
if (
159-
workInProgress.alternate !== null &&
160-
workInProgress.alternate.memoizedState !== null
161-
) {
162-
prevState = workInProgress.alternate.memoizedState;
163-
}
164-
if (prevState !== null && prevState.cachePool !== null) {
156+
if (workInProgress.alternate !== null) {
165157
popCachePool(workInProgress);
166158
}
167159
}
@@ -225,14 +217,7 @@ function unwindInterruptedWork(interruptedWork: Fiber, renderLanes: Lanes) {
225217
case LegacyHiddenComponent:
226218
popRenderLanes(interruptedWork);
227219
if (enableCache) {
228-
let prevState: OffscreenState | null = null;
229-
if (
230-
interruptedWork.alternate !== null &&
231-
interruptedWork.alternate.memoizedState !== null
232-
) {
233-
prevState = interruptedWork.alternate.memoizedState;
234-
}
235-
if (prevState !== null && prevState.cachePool !== null) {
220+
if (interruptedWork.alternate !== null) {
236221
popCachePool(interruptedWork);
237222
}
238223
}

0 commit comments

Comments
 (0)