Skip to content

Commit a6cbb21

Browse files
committed
tmp
1 parent 179e40e commit a6cbb21

10 files changed

+134
-152
lines changed

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

Lines changed: 31 additions & 22 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';
@@ -640,7 +640,6 @@ function updateOffscreenComponent(
640640
// If this is not null, this is a cache pool that was carried over from the
641641
// previous render. We will push this to the cache pool context so that we can
642642
// resume in-flight requests.
643-
let spawnedCachePool: SpawnedCachePool | null = null;
644643

645644
if (
646645
nextProps.mode === 'hidden' ||
@@ -655,7 +654,15 @@ function updateOffscreenComponent(
655654
};
656655
workInProgress.memoizedState = nextState;
657656
pushRenderLanes(workInProgress, renderLanes);
657+
if (enableCache) {
658+
// push the cache pool even though we're going to bail out
659+
// because otherwise there'd be a context mismatch
660+
if (current !== null) {
661+
pushSpawnedCachePool(workInProgress, null);
662+
}
663+
}
658664
} else if (!includesSomeLane(renderLanes, (OffscreenLane: Lane))) {
665+
let spawnedCachePool: SpawnedCachePool | null = null;
659666
// We're hidden, and we're not rendering at Offscreen. We will bail out
660667
// and resume this tree later.
661668
let nextBaseLanes;
@@ -664,18 +671,20 @@ function updateOffscreenComponent(
664671
nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
665672
if (enableCache) {
666673
// 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-
}
673674
spawnedCachePool = getOffscreenDeferredCachePool();
674675
}
675676
} else {
676677
nextBaseLanes = renderLanes;
677678
}
678679

680+
if (enableCache) {
681+
// push the cache pool even though we're going to bail out
682+
// because otherwise there'd be a context mismatch
683+
if (current !== null) {
684+
pushSpawnedCachePool(workInProgress, null);
685+
}
686+
}
687+
679688
// Schedule this fiber to re-render at offscreen priority. Then bailout.
680689
workInProgress.lanes = workInProgress.childLanes = laneToLanes(
681690
OffscreenLane,
@@ -706,17 +715,12 @@ function updateOffscreenComponent(
706715
// This is the second render. The surrounding visible content has already
707716
// committed. Now we resume rendering the hidden tree.
708717

709-
if (enableCache && prevState !== null) {
718+
if (enableCache && current !== null) {
710719
// If the render that spawned this one accessed the cache pool, resume
711720
// using the same cache. Unless the parent changed, since that means
712721
// there was a refresh.
713-
const prevCachePool = prevState.cachePool;
714-
if (prevCachePool !== null) {
715-
spawnedCachePool = restoreSpawnedCachePool(
716-
workInProgress,
717-
prevCachePool,
718-
);
719-
}
722+
const prevCachePool = prevState !== null ? prevState.cachePool : null;
723+
pushSpawnedCachePool(workInProgress, prevCachePool);
720724
}
721725

722726
// Rendering at offscreen, so we can clear the base lanes.
@@ -743,12 +747,7 @@ function updateOffscreenComponent(
743747
// using the same cache. Unless the parent changed, since that means
744748
// there was a refresh.
745749
const prevCachePool = prevState.cachePool;
746-
if (prevCachePool !== null) {
747-
spawnedCachePool = restoreSpawnedCachePool(
748-
workInProgress,
749-
prevCachePool,
750-
);
751-
}
750+
pushSpawnedCachePool(workInProgress, prevCachePool);
752751
}
753752

754753
// Since we're not hidden anymore, reset the state
@@ -758,6 +757,15 @@ function updateOffscreenComponent(
758757
// special to do. Need to push to the stack regardless, though, to avoid
759758
// a push/pop misalignment.
760759
subtreeRenderLanes = renderLanes;
760+
761+
if (enableCache) {
762+
// If the render that spawned this one accessed the cache pool, resume
763+
// using the same cache. Unless the parent changed, since that means
764+
// there was a refresh.
765+
if (current !== null) {
766+
pushSpawnedCachePool(workInProgress, null);
767+
}
768+
}
761769
}
762770
pushRenderLanes(workInProgress, subtreeRenderLanes);
763771
}
@@ -2071,6 +2079,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
20712079

20722080
const nextPrimaryChildren = nextProps.children;
20732081
const nextFallbackChildren = nextProps.fallback;
2082+
20742083
if (showFallback) {
20752084
const fallbackFragment = mountSuspenseFallbackChildren(
20762085
workInProgress,

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

Lines changed: 31 additions & 22 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';
@@ -640,7 +640,6 @@ function updateOffscreenComponent(
640640
// If this is not null, this is a cache pool that was carried over from the
641641
// previous render. We will push this to the cache pool context so that we can
642642
// resume in-flight requests.
643-
let spawnedCachePool: SpawnedCachePool | null = null;
644643

645644
if (
646645
nextProps.mode === 'hidden' ||
@@ -655,7 +654,15 @@ function updateOffscreenComponent(
655654
};
656655
workInProgress.memoizedState = nextState;
657656
pushRenderLanes(workInProgress, renderLanes);
657+
if (enableCache) {
658+
// push the cache pool even though we're going to bail out
659+
// because otherwise there'd be a context mismatch
660+
if (current !== null) {
661+
pushSpawnedCachePool(workInProgress, null);
662+
}
663+
}
658664
} else if (!includesSomeLane(renderLanes, (OffscreenLane: Lane))) {
665+
let spawnedCachePool: SpawnedCachePool | null = null;
659666
// We're hidden, and we're not rendering at Offscreen. We will bail out
660667
// and resume this tree later.
661668
let nextBaseLanes;
@@ -664,18 +671,20 @@ function updateOffscreenComponent(
664671
nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
665672
if (enableCache) {
666673
// 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-
}
673674
spawnedCachePool = getOffscreenDeferredCachePool();
674675
}
675676
} else {
676677
nextBaseLanes = renderLanes;
677678
}
678679

680+
if (enableCache) {
681+
// push the cache pool even though we're going to bail out
682+
// because otherwise there'd be a context mismatch
683+
if (current !== null) {
684+
pushSpawnedCachePool(workInProgress, null);
685+
}
686+
}
687+
679688
// Schedule this fiber to re-render at offscreen priority. Then bailout.
680689
workInProgress.lanes = workInProgress.childLanes = laneToLanes(
681690
OffscreenLane,
@@ -706,17 +715,12 @@ function updateOffscreenComponent(
706715
// This is the second render. The surrounding visible content has already
707716
// committed. Now we resume rendering the hidden tree.
708717

709-
if (enableCache && prevState !== null) {
718+
if (enableCache && current !== null) {
710719
// If the render that spawned this one accessed the cache pool, resume
711720
// using the same cache. Unless the parent changed, since that means
712721
// there was a refresh.
713-
const prevCachePool = prevState.cachePool;
714-
if (prevCachePool !== null) {
715-
spawnedCachePool = restoreSpawnedCachePool(
716-
workInProgress,
717-
prevCachePool,
718-
);
719-
}
722+
const prevCachePool = prevState !== null ? prevState.cachePool : null;
723+
pushSpawnedCachePool(workInProgress, prevCachePool);
720724
}
721725

722726
// Rendering at offscreen, so we can clear the base lanes.
@@ -743,12 +747,7 @@ function updateOffscreenComponent(
743747
// using the same cache. Unless the parent changed, since that means
744748
// there was a refresh.
745749
const prevCachePool = prevState.cachePool;
746-
if (prevCachePool !== null) {
747-
spawnedCachePool = restoreSpawnedCachePool(
748-
workInProgress,
749-
prevCachePool,
750-
);
751-
}
750+
pushSpawnedCachePool(workInProgress, prevCachePool);
752751
}
753752

754753
// Since we're not hidden anymore, reset the state
@@ -758,6 +757,15 @@ function updateOffscreenComponent(
758757
// special to do. Need to push to the stack regardless, though, to avoid
759758
// a push/pop misalignment.
760759
subtreeRenderLanes = renderLanes;
760+
761+
if (enableCache) {
762+
// If the render that spawned this one accessed the cache pool, resume
763+
// using the same cache. Unless the parent changed, since that means
764+
// there was a refresh.
765+
if (current !== null) {
766+
pushSpawnedCachePool(workInProgress, null);
767+
}
768+
}
761769
}
762770
pushRenderLanes(workInProgress, subtreeRenderLanes);
763771
}
@@ -2071,6 +2079,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
20712079

20722080
const nextPrimaryChildren = nextProps.children;
20732081
const nextFallbackChildren = nextProps.fallback;
2082+
20742083
if (showFallback) {
20752084
const fallbackFragment = mountSuspenseFallbackChildren(
20762085
workInProgress,

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,36 +198,27 @@ 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) {
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+
209+
if (prevCachePool === null) {
210+
push(resumedCache, resumedCache.current, offscreenWorkInProgress);
214211
return null;
215212
} 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).
219213
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;
224214
}
225215
}
226216

227217
export function popCachePool(workInProgress: Fiber) {
228218
if (!enableCache) {
229219
return;
230220
}
221+
231222
pop(resumedCache, workInProgress);
232223
}
233224

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,36 +198,27 @@ 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) {
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+
209+
if (prevCachePool === null) {
210+
push(resumedCache, resumedCache.current, offscreenWorkInProgress);
214211
return null;
215212
} 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).
219213
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;
224214
}
225215
}
226216

227217
export function popCachePool(workInProgress: Fiber) {
228218
if (!enableCache) {
229219
return;
230220
}
221+
231222
pop(resumedCache, workInProgress);
232223
}
233224

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -865,8 +865,8 @@ function completeWork(
865865
popRootCachePool(fiberRoot, renderLanes);
866866

867867
let previousCache: Cache | null = null;
868-
if (workInProgress.alternate !== null) {
869-
previousCache = workInProgress.alternate.memoizedState.cache;
868+
if (current !== null) {
869+
previousCache = current.memoizedState.cache;
870870
}
871871
const cache: Cache = workInProgress.memoizedState.cache;
872872
if (cache !== previousCache) {
@@ -1533,11 +1533,11 @@ function completeWork(
15331533
if (enableCache) {
15341534
let previousCache: Cache | null = null;
15351535
if (
1536-
workInProgress.alternate !== null &&
1537-
workInProgress.alternate.memoizedState !== null &&
1538-
workInProgress.alternate.memoizedState.cachePool !== null
1536+
current !== null &&
1537+
current.memoizedState !== null &&
1538+
current.memoizedState.cachePool !== null
15391539
) {
1540-
previousCache = workInProgress.alternate.memoizedState.cachePool.pool;
1540+
previousCache = current.memoizedState.cachePool.pool;
15411541
}
15421542
let cache: Cache | null = null;
15431543
if (
@@ -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 (current !== null) {
15611554
popCachePool(workInProgress);
15621555
}
15631556
}
@@ -1567,8 +1560,8 @@ function completeWork(
15671560
case CacheComponent: {
15681561
if (enableCache) {
15691562
let previousCache: Cache | null = null;
1570-
if (workInProgress.alternate !== null) {
1571-
previousCache = workInProgress.alternate.memoizedState.cache;
1563+
if (current !== null) {
1564+
previousCache = current.memoizedState.cache;
15721565
}
15731566
const cache: Cache = workInProgress.memoizedState.cache;
15741567
if (cache !== previousCache) {

0 commit comments

Comments
 (0)