Skip to content

Commit 3d89d49

Browse files
committed
refactor to avoid optional chaining syntax
1 parent fb49dce commit 3d89d49

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,13 +2915,18 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber(
29152915
case LegacyHiddenComponent:
29162916
case OffscreenComponent: {
29172917
if (enableCache) {
2918-
const cache: Cache = current.memoizedState?.cachePool?.pool;
2919-
// Retain/release the cache used for pending (suspended) nodes.
2920-
// Note that this is only reached in the non-suspended/visible case:
2921-
// when the content is suspended/hidden, the retain/release occurs
2922-
// via the parent Suspense component (see case above).
2923-
if (cache != null) {
2924-
retainCache(cache);
2918+
if (
2919+
current.memoizedState !== null &&
2920+
current.memoizedState.cachePool !== null
2921+
) {
2922+
const cache: Cache = current.memoizedState.cachePool.pool;
2923+
// Retain/release the cache used for pending (suspended) nodes.
2924+
// Note that this is only reached in the non-suspended/visible case:
2925+
// when the content is suspended/hidden, the retain/release occurs
2926+
// via the parent Suspense component (see case above).
2927+
if (cache != null) {
2928+
retainCache(cache);
2929+
}
29252930
}
29262931
}
29272932
break;

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,13 +2915,18 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber(
29152915
case LegacyHiddenComponent:
29162916
case OffscreenComponent: {
29172917
if (enableCache) {
2918-
const cache: Cache = current.memoizedState?.cachePool?.pool;
2919-
// Retain/release the cache used for pending (suspended) nodes.
2920-
// Note that this is only reached in the non-suspended/visible case:
2921-
// when the content is suspended/hidden, the retain/release occurs
2922-
// via the parent Suspense component (see case above).
2923-
if (cache != null) {
2924-
retainCache(cache);
2918+
if (
2919+
current.memoizedState !== null &&
2920+
current.memoizedState.cachePool !== null
2921+
) {
2922+
const cache: Cache = current.memoizedState.cachePool.pool;
2923+
// Retain/release the cache used for pending (suspended) nodes.
2924+
// Note that this is only reached in the non-suspended/visible case:
2925+
// when the content is suspended/hidden, the retain/release occurs
2926+
// via the parent Suspense component (see case above).
2927+
if (cache != null) {
2928+
retainCache(cache);
2929+
}
29252930
}
29262931
}
29272932
break;

0 commit comments

Comments
 (0)