Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Feb 17, 2022
1 parent 179e40e commit 2f1eab9
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 120 deletions.
55 changes: 35 additions & 20 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,13 @@ function updateOffscreenComponent(
};
workInProgress.memoizedState = nextState;
pushRenderLanes(workInProgress, renderLanes);
if (enableCache) {
// push the cache pool even though we're going to bail out
// because otherwise there'd be a context mismatch
if (current !== null) {
restoreSpawnedCachePool(workInProgress, null);
}
}
} else if (!includesSomeLane(renderLanes, (OffscreenLane: Lane))) {
// We're hidden, and we're not rendering at Offscreen. We will bail out
// and resume this tree later.
Expand All @@ -664,18 +671,20 @@ function updateOffscreenComponent(
nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
if (enableCache) {
// Save the cache pool so we can resume later.
const prevCachePool = prevState.cachePool;
if (prevCachePool !== null) {
// push the cache pool even though we're going to bail out
// because otherwise there'd be a context mismatch
restoreSpawnedCachePool(workInProgress, prevCachePool);
}
spawnedCachePool = getOffscreenDeferredCachePool();
}
} else {
nextBaseLanes = renderLanes;
}

if (enableCache) {
// push the cache pool even though we're going to bail out
// because otherwise there'd be a context mismatch
if (current !== null) {
restoreSpawnedCachePool(workInProgress, null);
}
}

// Schedule this fiber to re-render at offscreen priority. Then bailout.
workInProgress.lanes = workInProgress.childLanes = laneToLanes(
OffscreenLane,
Expand Down Expand Up @@ -706,17 +715,15 @@ function updateOffscreenComponent(
// This is the second render. The surrounding visible content has already
// committed. Now we resume rendering the hidden tree.

if (enableCache && prevState !== null) {
if (enableCache && current !== null) {
// If the render that spawned this one accessed the cache pool, resume
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
const prevCachePool = prevState.cachePool;
if (prevCachePool !== null) {
spawnedCachePool = restoreSpawnedCachePool(
workInProgress,
prevCachePool,
);
}
const prevCachePool = prevState !== null ? prevState.cachePool : null;
spawnedCachePool = restoreSpawnedCachePool(
workInProgress,
prevCachePool,
);
}

// Rendering at offscreen, so we can clear the base lanes.
Expand All @@ -743,12 +750,10 @@ function updateOffscreenComponent(
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
const prevCachePool = prevState.cachePool;
if (prevCachePool !== null) {
spawnedCachePool = restoreSpawnedCachePool(
workInProgress,
prevCachePool,
);
}
spawnedCachePool = restoreSpawnedCachePool(
workInProgress,
prevCachePool,
);
}

// Since we're not hidden anymore, reset the state
Expand All @@ -758,6 +763,15 @@ function updateOffscreenComponent(
// special to do. Need to push to the stack regardless, though, to avoid
// a push/pop misalignment.
subtreeRenderLanes = renderLanes;

if (enableCache) {
// If the render that spawned this one accessed the cache pool, resume
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
if (current !== null) {
restoreSpawnedCachePool(workInProgress, null);
}
}
}
pushRenderLanes(workInProgress, subtreeRenderLanes);
}
Expand Down Expand Up @@ -2071,6 +2085,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {

const nextPrimaryChildren = nextProps.children;
const nextFallbackChildren = nextProps.fallback;

if (showFallback) {
const fallbackFragment = mountSuspenseFallbackChildren(
workInProgress,
Expand Down
55 changes: 35 additions & 20 deletions packages/react-reconciler/src/ReactFiberBeginWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,13 @@ function updateOffscreenComponent(
};
workInProgress.memoizedState = nextState;
pushRenderLanes(workInProgress, renderLanes);
if (enableCache) {
// push the cache pool even though we're going to bail out
// because otherwise there'd be a context mismatch
if (current !== null) {
restoreSpawnedCachePool(workInProgress, null);
}
}
} else if (!includesSomeLane(renderLanes, (OffscreenLane: Lane))) {
// We're hidden, and we're not rendering at Offscreen. We will bail out
// and resume this tree later.
Expand All @@ -664,18 +671,20 @@ function updateOffscreenComponent(
nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
if (enableCache) {
// Save the cache pool so we can resume later.
const prevCachePool = prevState.cachePool;
if (prevCachePool !== null) {
// push the cache pool even though we're going to bail out
// because otherwise there'd be a context mismatch
restoreSpawnedCachePool(workInProgress, prevCachePool);
}
spawnedCachePool = getOffscreenDeferredCachePool();
}
} else {
nextBaseLanes = renderLanes;
}

if (enableCache) {
// push the cache pool even though we're going to bail out
// because otherwise there'd be a context mismatch
if (current !== null) {
restoreSpawnedCachePool(workInProgress, null);
}
}

// Schedule this fiber to re-render at offscreen priority. Then bailout.
workInProgress.lanes = workInProgress.childLanes = laneToLanes(
OffscreenLane,
Expand Down Expand Up @@ -706,17 +715,15 @@ function updateOffscreenComponent(
// This is the second render. The surrounding visible content has already
// committed. Now we resume rendering the hidden tree.

if (enableCache && prevState !== null) {
if (enableCache && current !== null) {
// If the render that spawned this one accessed the cache pool, resume
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
const prevCachePool = prevState.cachePool;
if (prevCachePool !== null) {
spawnedCachePool = restoreSpawnedCachePool(
workInProgress,
prevCachePool,
);
}
const prevCachePool = prevState !== null ? prevState.cachePool : null;
spawnedCachePool = restoreSpawnedCachePool(
workInProgress,
prevCachePool,
);
}

// Rendering at offscreen, so we can clear the base lanes.
Expand All @@ -743,12 +750,10 @@ function updateOffscreenComponent(
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
const prevCachePool = prevState.cachePool;
if (prevCachePool !== null) {
spawnedCachePool = restoreSpawnedCachePool(
workInProgress,
prevCachePool,
);
}
spawnedCachePool = restoreSpawnedCachePool(
workInProgress,
prevCachePool,
);
}

// Since we're not hidden anymore, reset the state
Expand All @@ -758,6 +763,15 @@ function updateOffscreenComponent(
// special to do. Need to push to the stack regardless, though, to avoid
// a push/pop misalignment.
subtreeRenderLanes = renderLanes;

if (enableCache) {
// If the render that spawned this one accessed the cache pool, resume
// using the same cache. Unless the parent changed, since that means
// there was a refresh.
if (current !== null) {
restoreSpawnedCachePool(workInProgress, null);
}
}
}
pushRenderLanes(workInProgress, subtreeRenderLanes);
}
Expand Down Expand Up @@ -2071,6 +2085,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {

const nextPrimaryChildren = nextProps.children;
const nextFallbackChildren = nextProps.fallback;

if (showFallback) {
const fallbackFragment = mountSuspenseFallbackChildren(
workInProgress,
Expand Down
37 changes: 22 additions & 15 deletions packages/react-reconciler/src/ReactFiberCacheComponent.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,34 +200,41 @@ export function popRootCachePool(root: FiberRoot, renderLanes: Lanes) {

export function restoreSpawnedCachePool(
offscreenWorkInProgress: Fiber,
prevCachePool: SpawnedCachePool,
prevCachePool: SpawnedCachePool | null,
): SpawnedCachePool | null {
if (!enableCache) {
return (null: any);
}
const nextParentCache = isPrimaryRenderer
? CacheContext._currentValue
: CacheContext._currentValue2;
if (nextParentCache !== prevCachePool.parent) {
// There was a refresh. Don't bother restoring anything since the refresh
// will override it.

if (prevCachePool === null) {
push(resumedCache, resumedCache.current, offscreenWorkInProgress);
return null;
} else {
// No refresh. Resume with the previous cache. New Cache boundaries in the
// subtree use this one instead of requesting a fresh one (see
// peekCacheFromPool).
push(resumedCache, prevCachePool.pool, offscreenWorkInProgress);

// Return the cache pool to signal that we did in fact push it. We will
// assign this to the field on the fiber so we know to pop the context.
return prevCachePool;
const nextParentCache = isPrimaryRenderer
? CacheContext._currentValue
: CacheContext._currentValue2;
if (nextParentCache !== prevCachePool.parent) {
// There was a refresh. Don't bother restoring anything since the refresh
// will override it.
return null;
} else {
// No refresh. Resume with the previous cache. New Cache boundaries in the
// subtree use this one instead of requesting a fresh one (see
// peekCacheFromPool).
push(resumedCache, prevCachePool.pool, offscreenWorkInProgress);

// Return the cache pool to signal that we did in fact push it. We will
// assign this to the field on the fiber so we know to pop the context.
return prevCachePool;
}
}
}

export function popCachePool(workInProgress: Fiber) {
if (!enableCache) {
return;
}

pop(resumedCache, workInProgress);
}

Expand Down
37 changes: 22 additions & 15 deletions packages/react-reconciler/src/ReactFiberCacheComponent.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,34 +200,41 @@ export function popRootCachePool(root: FiberRoot, renderLanes: Lanes) {

export function restoreSpawnedCachePool(
offscreenWorkInProgress: Fiber,
prevCachePool: SpawnedCachePool,
prevCachePool: SpawnedCachePool | null,
): SpawnedCachePool | null {
if (!enableCache) {
return (null: any);
}
const nextParentCache = isPrimaryRenderer
? CacheContext._currentValue
: CacheContext._currentValue2;
if (nextParentCache !== prevCachePool.parent) {
// There was a refresh. Don't bother restoring anything since the refresh
// will override it.

if (prevCachePool === null) {
push(resumedCache, resumedCache.current, offscreenWorkInProgress);
return null;
} else {
// No refresh. Resume with the previous cache. New Cache boundaries in the
// subtree use this one instead of requesting a fresh one (see
// peekCacheFromPool).
push(resumedCache, prevCachePool.pool, offscreenWorkInProgress);

// Return the cache pool to signal that we did in fact push it. We will
// assign this to the field on the fiber so we know to pop the context.
return prevCachePool;
const nextParentCache = isPrimaryRenderer
? CacheContext._currentValue
: CacheContext._currentValue2;
if (nextParentCache !== prevCachePool.parent) {
// There was a refresh. Don't bother restoring anything since the refresh
// will override it.
return null;
} else {
// No refresh. Resume with the previous cache. New Cache boundaries in the
// subtree use this one instead of requesting a fresh one (see
// peekCacheFromPool).
push(resumedCache, prevCachePool.pool, offscreenWorkInProgress);

// Return the cache pool to signal that we did in fact push it. We will
// assign this to the field on the fiber so we know to pop the context.
return prevCachePool;
}
}
}

export function popCachePool(workInProgress: Fiber) {
if (!enableCache) {
return;
}

pop(resumedCache, workInProgress);
}

Expand Down
9 changes: 1 addition & 8 deletions packages/react-reconciler/src/ReactFiberCompleteWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1550,14 +1550,7 @@ function completeWork(
// Run passive effects to retain/release the cache.
workInProgress.flags |= Passive;
}
let prevState: OffscreenState | null = null;
if (
workInProgress.alternate !== null &&
workInProgress.alternate.memoizedState !== null
) {
prevState = workInProgress.alternate.memoizedState;
}
if (prevState !== null && prevState.cachePool !== null) {
if (workInProgress.alternate !== null) {
popCachePool(workInProgress);
}
}
Expand Down
9 changes: 1 addition & 8 deletions packages/react-reconciler/src/ReactFiberCompleteWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1550,14 +1550,7 @@ function completeWork(
// Run passive effects to retain/release the cache.
workInProgress.flags |= Passive;
}
let prevState: OffscreenState | null = null;
if (
workInProgress.alternate !== null &&
workInProgress.alternate.memoizedState !== null
) {
prevState = workInProgress.alternate.memoizedState;
}
if (prevState !== null && prevState.cachePool !== null) {
if (workInProgress.alternate !== null) {
popCachePool(workInProgress);
}
}
Expand Down
19 changes: 2 additions & 17 deletions packages/react-reconciler/src/ReactFiberUnwindWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {Lanes} from './ReactFiberLane.new';
import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
import type {Cache} from './ReactFiberCacheComponent.new';
import type {OffscreenState} from './ReactFiberOffscreenComponent';

import {resetWorkInProgressVersions as resetMutableSourceWorkInProgressVersions} from './ReactMutableSource.new';
import {
Expand Down Expand Up @@ -153,15 +152,8 @@ function unwindWork(workInProgress: Fiber, renderLanes: Lanes) {
case OffscreenComponent:
case LegacyHiddenComponent:
popRenderLanes(workInProgress);
let prevState: OffscreenState | null = null;
if (enableCache) {
if (
workInProgress.alternate !== null &&
workInProgress.alternate.memoizedState !== null
) {
prevState = workInProgress.alternate.memoizedState;
}
if (prevState !== null && prevState.cachePool !== null) {
if (workInProgress.alternate !== null) {
popCachePool(workInProgress);
}
}
Expand Down Expand Up @@ -225,14 +217,7 @@ function unwindInterruptedWork(interruptedWork: Fiber, renderLanes: Lanes) {
case LegacyHiddenComponent:
popRenderLanes(interruptedWork);
if (enableCache) {
let prevState: OffscreenState | null = null;
if (
interruptedWork.alternate !== null &&
interruptedWork.alternate.memoizedState !== null
) {
prevState = interruptedWork.alternate.memoizedState;
}
if (prevState !== null && prevState.cachePool !== null) {
if (interruptedWork.alternate !== null) {
popCachePool(interruptedWork);
}
}
Expand Down
Loading

0 comments on commit 2f1eab9

Please sign in to comment.