From 330b720b91a739972b22c605645c6a257558e0cf Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 17 Feb 2022 18:36:28 -0500 Subject: [PATCH] tmp --- .../src/ReactFiberBeginWork.new.js | 55 ++++++++++++------- .../src/ReactFiberBeginWork.old.js | 55 ++++++++++++------- .../src/ReactFiberCacheComponent.new.js | 37 ++++++++----- .../src/ReactFiberCacheComponent.old.js | 37 ++++++++----- .../src/ReactFiberCompleteWork.new.js | 25 +++------ .../src/ReactFiberCompleteWork.old.js | 25 +++------ .../src/ReactFiberUnwindWork.new.js | 19 +------ .../src/ReactFiberUnwindWork.old.js | 19 +------ 8 files changed, 136 insertions(+), 136 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.new.js b/packages/react-reconciler/src/ReactFiberBeginWork.new.js index ca59103b6eb3b..4ca247d302169 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.new.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.new.js @@ -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. @@ -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, @@ -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. @@ -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 @@ -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); } @@ -2071,6 +2085,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) { const nextPrimaryChildren = nextProps.children; const nextFallbackChildren = nextProps.fallback; + if (showFallback) { const fallbackFragment = mountSuspenseFallbackChildren( workInProgress, diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.old.js b/packages/react-reconciler/src/ReactFiberBeginWork.old.js index fedb04074e27e..4d40cc533219e 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.old.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.old.js @@ -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. @@ -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, @@ -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. @@ -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 @@ -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); } @@ -2071,6 +2085,7 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) { const nextPrimaryChildren = nextProps.children; const nextFallbackChildren = nextProps.fallback; + if (showFallback) { const fallbackFragment = mountSuspenseFallbackChildren( workInProgress, diff --git a/packages/react-reconciler/src/ReactFiberCacheComponent.new.js b/packages/react-reconciler/src/ReactFiberCacheComponent.new.js index cf851af6e3de3..4dab356caf3fe 100644 --- a/packages/react-reconciler/src/ReactFiberCacheComponent.new.js +++ b/packages/react-reconciler/src/ReactFiberCacheComponent.new.js @@ -200,27 +200,33 @@ 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; + } } } @@ -228,6 +234,7 @@ export function popCachePool(workInProgress: Fiber) { if (!enableCache) { return; } + pop(resumedCache, workInProgress); } diff --git a/packages/react-reconciler/src/ReactFiberCacheComponent.old.js b/packages/react-reconciler/src/ReactFiberCacheComponent.old.js index 692dba781302e..0c95a2cc7edfd 100644 --- a/packages/react-reconciler/src/ReactFiberCacheComponent.old.js +++ b/packages/react-reconciler/src/ReactFiberCacheComponent.old.js @@ -200,27 +200,33 @@ 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; + } } } @@ -228,6 +234,7 @@ export function popCachePool(workInProgress: Fiber) { if (!enableCache) { return; } + pop(resumedCache, workInProgress); } diff --git a/packages/react-reconciler/src/ReactFiberCompleteWork.new.js b/packages/react-reconciler/src/ReactFiberCompleteWork.new.js index 54b291157b526..bb01e2b8a2a26 100644 --- a/packages/react-reconciler/src/ReactFiberCompleteWork.new.js +++ b/packages/react-reconciler/src/ReactFiberCompleteWork.new.js @@ -865,8 +865,8 @@ function completeWork( popRootCachePool(fiberRoot, renderLanes); let previousCache: Cache | null = null; - if (workInProgress.alternate !== null) { - previousCache = workInProgress.alternate.memoizedState.cache; + if (current !== null) { + previousCache = current.memoizedState.cache; } const cache: Cache = workInProgress.memoizedState.cache; if (cache !== previousCache) { @@ -1533,11 +1533,11 @@ function completeWork( if (enableCache) { let previousCache: Cache | null = null; if ( - workInProgress.alternate !== null && - workInProgress.alternate.memoizedState !== null && - workInProgress.alternate.memoizedState.cachePool !== null + current !== null && + current.memoizedState !== null && + current.memoizedState.cachePool !== null ) { - previousCache = workInProgress.alternate.memoizedState.cachePool.pool; + previousCache = current.memoizedState.cachePool.pool; } let cache: Cache | null = null; if ( @@ -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 (current !== null) { popCachePool(workInProgress); } } @@ -1567,8 +1560,8 @@ function completeWork( case CacheComponent: { if (enableCache) { let previousCache: Cache | null = null; - if (workInProgress.alternate !== null) { - previousCache = workInProgress.alternate.memoizedState.cache; + if (current !== null) { + previousCache = current.memoizedState.cache; } const cache: Cache = workInProgress.memoizedState.cache; if (cache !== previousCache) { diff --git a/packages/react-reconciler/src/ReactFiberCompleteWork.old.js b/packages/react-reconciler/src/ReactFiberCompleteWork.old.js index 134c610ef5c6f..0d9de679a0f43 100644 --- a/packages/react-reconciler/src/ReactFiberCompleteWork.old.js +++ b/packages/react-reconciler/src/ReactFiberCompleteWork.old.js @@ -865,8 +865,8 @@ function completeWork( popRootCachePool(fiberRoot, renderLanes); let previousCache: Cache | null = null; - if (workInProgress.alternate !== null) { - previousCache = workInProgress.alternate.memoizedState.cache; + if (current !== null) { + previousCache = current.memoizedState.cache; } const cache: Cache = workInProgress.memoizedState.cache; if (cache !== previousCache) { @@ -1533,11 +1533,11 @@ function completeWork( if (enableCache) { let previousCache: Cache | null = null; if ( - workInProgress.alternate !== null && - workInProgress.alternate.memoizedState !== null && - workInProgress.alternate.memoizedState.cachePool !== null + current !== null && + current.memoizedState !== null && + current.memoizedState.cachePool !== null ) { - previousCache = workInProgress.alternate.memoizedState.cachePool.pool; + previousCache = current.memoizedState.cachePool.pool; } let cache: Cache | null = null; if ( @@ -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 (current !== null) { popCachePool(workInProgress); } } @@ -1567,8 +1560,8 @@ function completeWork( case CacheComponent: { if (enableCache) { let previousCache: Cache | null = null; - if (workInProgress.alternate !== null) { - previousCache = workInProgress.alternate.memoizedState.cache; + if (current !== null) { + previousCache = current.memoizedState.cache; } const cache: Cache = workInProgress.memoizedState.cache; if (cache !== previousCache) { diff --git a/packages/react-reconciler/src/ReactFiberUnwindWork.new.js b/packages/react-reconciler/src/ReactFiberUnwindWork.new.js index 808c6de80464d..7fbd85968021a 100644 --- a/packages/react-reconciler/src/ReactFiberUnwindWork.new.js +++ b/packages/react-reconciler/src/ReactFiberUnwindWork.new.js @@ -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 { @@ -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); } } @@ -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); } } diff --git a/packages/react-reconciler/src/ReactFiberUnwindWork.old.js b/packages/react-reconciler/src/ReactFiberUnwindWork.old.js index f318751f06ee5..09e62db79e811 100644 --- a/packages/react-reconciler/src/ReactFiberUnwindWork.old.js +++ b/packages/react-reconciler/src/ReactFiberUnwindWork.old.js @@ -12,7 +12,6 @@ import type {Fiber, FiberRoot} from './ReactInternalTypes'; import type {Lanes} from './ReactFiberLane.old'; import type {SuspenseState} from './ReactFiberSuspenseComponent.old'; import type {Cache} from './ReactFiberCacheComponent.old'; -import type {OffscreenState} from './ReactFiberOffscreenComponent'; import {resetWorkInProgressVersions as resetMutableSourceWorkInProgressVersions} from './ReactMutableSource.old'; import { @@ -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); } } @@ -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); } }