From c8a2074f84ef73096aad7efdbcf9ca2ac33aabd2 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Wed, 20 Oct 2021 15:44:53 -0700 Subject: [PATCH] refactor to avoid optional chaining syntax --- .../src/ReactFiberCommitWork.new.js | 19 ++++++++++++------- .../src/ReactFiberCommitWork.old.js | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.new.js b/packages/react-reconciler/src/ReactFiberCommitWork.new.js index 68dee124adf9b..5c940d092c1e6 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.new.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.new.js @@ -2915,13 +2915,18 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber( case LegacyHiddenComponent: case OffscreenComponent: { if (enableCache) { - const cache: Cache = current.memoizedState?.cachePool?.pool; - // Retain/release the cache used for pending (suspended) nodes. - // Note that this is only reached in the non-suspended/visible case: - // when the content is suspended/hidden, the retain/release occurs - // via the parent Suspense component (see case above). - if (cache != null) { - retainCache(cache); + if ( + current.memoizedState !== null && + current.memoizedState.cachePool !== null + ) { + const cache: Cache = current.memoizedState.cachePool.pool; + // Retain/release the cache used for pending (suspended) nodes. + // Note that this is only reached in the non-suspended/visible case: + // when the content is suspended/hidden, the retain/release occurs + // via the parent Suspense component (see case above). + if (cache != null) { + retainCache(cache); + } } } break; diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.old.js b/packages/react-reconciler/src/ReactFiberCommitWork.old.js index 19959240a742f..86ff34f97dd9f 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.old.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.old.js @@ -2915,13 +2915,18 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber( case LegacyHiddenComponent: case OffscreenComponent: { if (enableCache) { - const cache: Cache = current.memoizedState?.cachePool?.pool; - // Retain/release the cache used for pending (suspended) nodes. - // Note that this is only reached in the non-suspended/visible case: - // when the content is suspended/hidden, the retain/release occurs - // via the parent Suspense component (see case above). - if (cache != null) { - retainCache(cache); + if ( + current.memoizedState !== null && + current.memoizedState.cachePool !== null + ) { + const cache: Cache = current.memoizedState.cachePool.pool; + // Retain/release the cache used for pending (suspended) nodes. + // Note that this is only reached in the non-suspended/visible case: + // when the content is suspended/hidden, the retain/release occurs + // via the parent Suspense component (see case above). + if (cache != null) { + retainCache(cache); + } } } break;