Skip to content

Commit c8157b2

Browse files
committed
tmp
1 parent 179e40e commit c8157b2

10 files changed

+146
-174
lines changed

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

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ import {
236236
pushRootCachePool,
237237
CacheContext,
238238
getSuspendedCachePool,
239-
restoreSpawnedCachePool,
239+
pushSpawnedCachePool,
240240
getOffscreenDeferredCachePool,
241241
} from './ReactFiberCacheComponent.new';
242242
import {createCapturedValue} from './ReactCapturedValue';
@@ -637,11 +637,6 @@ function updateOffscreenComponent(
637637
const prevState: OffscreenState | null =
638638
current !== null ? current.memoizedState : null;
639639

640-
// If this is not null, this is a cache pool that was carried over from the
641-
// previous render. We will push this to the cache pool context so that we can
642-
// resume in-flight requests.
643-
let spawnedCachePool: SpawnedCachePool | null = null;
644-
645640
if (
646641
nextProps.mode === 'hidden' ||
647642
nextProps.mode === 'unstable-defer-without-hiding'
@@ -654,8 +649,16 @@ function updateOffscreenComponent(
654649
cachePool: null,
655650
};
656651
workInProgress.memoizedState = nextState;
652+
if (enableCache) {
653+
// push the cache pool even though we're going to bail out
654+
// because otherwise there'd be a context mismatch
655+
if (current !== null) {
656+
pushSpawnedCachePool(workInProgress, null);
657+
}
658+
}
657659
pushRenderLanes(workInProgress, renderLanes);
658660
} else if (!includesSomeLane(renderLanes, (OffscreenLane: Lane))) {
661+
let spawnedCachePool: SpawnedCachePool | null = null;
659662
// We're hidden, and we're not rendering at Offscreen. We will bail out
660663
// and resume this tree later.
661664
let nextBaseLanes;
@@ -664,12 +667,6 @@ function updateOffscreenComponent(
664667
nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
665668
if (enableCache) {
666669
// 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-
}
673670
spawnedCachePool = getOffscreenDeferredCachePool();
674671
}
675672
} else {
@@ -686,6 +683,14 @@ function updateOffscreenComponent(
686683
};
687684
workInProgress.memoizedState = nextState;
688685
workInProgress.updateQueue = null;
686+
if (enableCache) {
687+
// push the cache pool even though we're going to bail out
688+
// because otherwise there'd be a context mismatch
689+
if (current !== null) {
690+
pushSpawnedCachePool(workInProgress, null);
691+
}
692+
}
693+
689694
// We're about to bail out, but we need to push this to the stack anyway
690695
// to avoid a push/pop misalignment.
691696
pushRenderLanes(workInProgress, nextBaseLanes);
@@ -706,19 +711,6 @@ function updateOffscreenComponent(
706711
// This is the second render. The surrounding visible content has already
707712
// committed. Now we resume rendering the hidden tree.
708713

709-
if (enableCache && prevState !== null) {
710-
// If the render that spawned this one accessed the cache pool, resume
711-
// using the same cache. Unless the parent changed, since that means
712-
// there was a refresh.
713-
const prevCachePool = prevState.cachePool;
714-
if (prevCachePool !== null) {
715-
spawnedCachePool = restoreSpawnedCachePool(
716-
workInProgress,
717-
prevCachePool,
718-
);
719-
}
720-
}
721-
722714
// Rendering at offscreen, so we can clear the base lanes.
723715
const nextState: OffscreenState = {
724716
baseLanes: NoLanes,
@@ -728,6 +720,14 @@ function updateOffscreenComponent(
728720
// Push the lanes that were skipped when we bailed out.
729721
const subtreeRenderLanes =
730722
prevState !== null ? prevState.baseLanes : renderLanes;
723+
if (enableCache && current !== null) {
724+
// If the render that spawned this one accessed the cache pool, resume
725+
// using the same cache. Unless the parent changed, since that means
726+
// there was a refresh.
727+
const prevCachePool = prevState !== null ? prevState.cachePool : null;
728+
pushSpawnedCachePool(workInProgress, prevCachePool);
729+
}
730+
731731
pushRenderLanes(workInProgress, subtreeRenderLanes);
732732
}
733733
} else {
@@ -743,12 +743,7 @@ function updateOffscreenComponent(
743743
// using the same cache. Unless the parent changed, since that means
744744
// there was a refresh.
745745
const prevCachePool = prevState.cachePool;
746-
if (prevCachePool !== null) {
747-
spawnedCachePool = restoreSpawnedCachePool(
748-
workInProgress,
749-
prevCachePool,
750-
);
751-
}
746+
pushSpawnedCachePool(workInProgress, prevCachePool);
752747
}
753748

754749
// Since we're not hidden anymore, reset the state
@@ -758,6 +753,15 @@ function updateOffscreenComponent(
758753
// special to do. Need to push to the stack regardless, though, to avoid
759754
// a push/pop misalignment.
760755
subtreeRenderLanes = renderLanes;
756+
757+
if (enableCache) {
758+
// If the render that spawned this one accessed the cache pool, resume
759+
// using the same cache. Unless the parent changed, since that means
760+
// there was a refresh.
761+
if (current !== null) {
762+
pushSpawnedCachePool(workInProgress, null);
763+
}
764+
}
761765
}
762766
pushRenderLanes(workInProgress, subtreeRenderLanes);
763767
}
@@ -2071,6 +2075,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
20712075

20722076
const nextPrimaryChildren = nextProps.children;
20732077
const nextFallbackChildren = nextProps.fallback;
2078+
20742079
if (showFallback) {
20752080
const fallbackFragment = mountSuspenseFallbackChildren(
20762081
workInProgress,

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

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ import {
236236
pushRootCachePool,
237237
CacheContext,
238238
getSuspendedCachePool,
239-
restoreSpawnedCachePool,
239+
pushSpawnedCachePool,
240240
getOffscreenDeferredCachePool,
241241
} from './ReactFiberCacheComponent.old';
242242
import {createCapturedValue} from './ReactCapturedValue';
@@ -637,11 +637,6 @@ function updateOffscreenComponent(
637637
const prevState: OffscreenState | null =
638638
current !== null ? current.memoizedState : null;
639639

640-
// If this is not null, this is a cache pool that was carried over from the
641-
// previous render. We will push this to the cache pool context so that we can
642-
// resume in-flight requests.
643-
let spawnedCachePool: SpawnedCachePool | null = null;
644-
645640
if (
646641
nextProps.mode === 'hidden' ||
647642
nextProps.mode === 'unstable-defer-without-hiding'
@@ -654,8 +649,16 @@ function updateOffscreenComponent(
654649
cachePool: null,
655650
};
656651
workInProgress.memoizedState = nextState;
652+
if (enableCache) {
653+
// push the cache pool even though we're going to bail out
654+
// because otherwise there'd be a context mismatch
655+
if (current !== null) {
656+
pushSpawnedCachePool(workInProgress, null);
657+
}
658+
}
657659
pushRenderLanes(workInProgress, renderLanes);
658660
} else if (!includesSomeLane(renderLanes, (OffscreenLane: Lane))) {
661+
let spawnedCachePool: SpawnedCachePool | null = null;
659662
// We're hidden, and we're not rendering at Offscreen. We will bail out
660663
// and resume this tree later.
661664
let nextBaseLanes;
@@ -664,12 +667,6 @@ function updateOffscreenComponent(
664667
nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
665668
if (enableCache) {
666669
// 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-
}
673670
spawnedCachePool = getOffscreenDeferredCachePool();
674671
}
675672
} else {
@@ -686,6 +683,14 @@ function updateOffscreenComponent(
686683
};
687684
workInProgress.memoizedState = nextState;
688685
workInProgress.updateQueue = null;
686+
if (enableCache) {
687+
// push the cache pool even though we're going to bail out
688+
// because otherwise there'd be a context mismatch
689+
if (current !== null) {
690+
pushSpawnedCachePool(workInProgress, null);
691+
}
692+
}
693+
689694
// We're about to bail out, but we need to push this to the stack anyway
690695
// to avoid a push/pop misalignment.
691696
pushRenderLanes(workInProgress, nextBaseLanes);
@@ -706,19 +711,6 @@ function updateOffscreenComponent(
706711
// This is the second render. The surrounding visible content has already
707712
// committed. Now we resume rendering the hidden tree.
708713

709-
if (enableCache && prevState !== null) {
710-
// If the render that spawned this one accessed the cache pool, resume
711-
// using the same cache. Unless the parent changed, since that means
712-
// there was a refresh.
713-
const prevCachePool = prevState.cachePool;
714-
if (prevCachePool !== null) {
715-
spawnedCachePool = restoreSpawnedCachePool(
716-
workInProgress,
717-
prevCachePool,
718-
);
719-
}
720-
}
721-
722714
// Rendering at offscreen, so we can clear the base lanes.
723715
const nextState: OffscreenState = {
724716
baseLanes: NoLanes,
@@ -728,6 +720,14 @@ function updateOffscreenComponent(
728720
// Push the lanes that were skipped when we bailed out.
729721
const subtreeRenderLanes =
730722
prevState !== null ? prevState.baseLanes : renderLanes;
723+
if (enableCache && current !== null) {
724+
// If the render that spawned this one accessed the cache pool, resume
725+
// using the same cache. Unless the parent changed, since that means
726+
// there was a refresh.
727+
const prevCachePool = prevState !== null ? prevState.cachePool : null;
728+
pushSpawnedCachePool(workInProgress, prevCachePool);
729+
}
730+
731731
pushRenderLanes(workInProgress, subtreeRenderLanes);
732732
}
733733
} else {
@@ -743,12 +743,7 @@ function updateOffscreenComponent(
743743
// using the same cache. Unless the parent changed, since that means
744744
// there was a refresh.
745745
const prevCachePool = prevState.cachePool;
746-
if (prevCachePool !== null) {
747-
spawnedCachePool = restoreSpawnedCachePool(
748-
workInProgress,
749-
prevCachePool,
750-
);
751-
}
746+
pushSpawnedCachePool(workInProgress, prevCachePool);
752747
}
753748

754749
// Since we're not hidden anymore, reset the state
@@ -758,6 +753,15 @@ function updateOffscreenComponent(
758753
// special to do. Need to push to the stack regardless, though, to avoid
759754
// a push/pop misalignment.
760755
subtreeRenderLanes = renderLanes;
756+
757+
if (enableCache) {
758+
// If the render that spawned this one accessed the cache pool, resume
759+
// using the same cache. Unless the parent changed, since that means
760+
// there was a refresh.
761+
if (current !== null) {
762+
pushSpawnedCachePool(workInProgress, null);
763+
}
764+
}
761765
}
762766
pushRenderLanes(workInProgress, subtreeRenderLanes);
763767
}
@@ -2071,6 +2075,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
20712075

20722076
const nextPrimaryChildren = nextProps.children;
20732077
const nextFallbackChildren = nextProps.fallback;
2078+
20742079
if (showFallback) {
20752080
const fallbackFragment = mountSuspenseFallbackChildren(
20762081
workInProgress,

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,36 +198,26 @@ export function popRootCachePool(root: FiberRoot, renderLanes: Lanes) {
198198
// code organization purposes in case that changes.
199199
}
200200

201-
export function restoreSpawnedCachePool(
201+
export function pushSpawnedCachePool(
202202
offscreenWorkInProgress: Fiber,
203-
prevCachePool: SpawnedCachePool,
204-
): SpawnedCachePool | null {
203+
prevCachePool: SpawnedCachePool | null,
204+
): void {
205205
if (!enableCache) {
206-
return (null: any);
206+
return;
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.
214-
return null;
208+
209+
if (prevCachePool === null) {
210+
push(resumedCache, resumedCache.current, offscreenWorkInProgress);
215211
} 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).
219212
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;
224213
}
225214
}
226215

227216
export function popCachePool(workInProgress: Fiber) {
228217
if (!enableCache) {
229218
return;
230219
}
220+
231221
pop(resumedCache, workInProgress);
232222
}
233223

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,36 +198,26 @@ export function popRootCachePool(root: FiberRoot, renderLanes: Lanes) {
198198
// code organization purposes in case that changes.
199199
}
200200

201-
export function restoreSpawnedCachePool(
201+
export function pushSpawnedCachePool(
202202
offscreenWorkInProgress: Fiber,
203-
prevCachePool: SpawnedCachePool,
204-
): SpawnedCachePool | null {
203+
prevCachePool: SpawnedCachePool | null,
204+
): void {
205205
if (!enableCache) {
206-
return (null: any);
206+
return;
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.
214-
return null;
208+
209+
if (prevCachePool === null) {
210+
push(resumedCache, resumedCache.current, offscreenWorkInProgress);
215211
} 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).
219212
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;
224213
}
225214
}
226215

227216
export function popCachePool(workInProgress: Fiber) {
228217
if (!enableCache) {
229218
return;
230219
}
220+
231221
pop(resumedCache, workInProgress);
232222
}
233223

0 commit comments

Comments
 (0)