Skip to content

Commit 9031457

Browse files
committed
Extract commit root cache cleanup into a function, handle error case
1 parent 93020d4 commit 9031457

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ function commitRootImpl(root, renderPriorityLevel) {
20532053
hasUncaughtError = false;
20542054
const error = firstUncaughtError;
20552055
firstUncaughtError = null;
2056-
// TODO: how to handle cache cleanup here?
2056+
releaseRootPooledCache(root);
20572057
throw error;
20582058
}
20592059

@@ -2096,13 +2096,7 @@ function commitRootImpl(root, renderPriorityLevel) {
20962096

20972097
// Now that effects have run - giving Cache boundaries a chance to retain the
20982098
// cache instance - release the root's cache in case since the render is complete
2099-
if (enableCache) {
2100-
const pooledCache = root.pooledCache;
2101-
if (pooledCache != null) {
2102-
releaseCache(pooledCache);
2103-
root.pooledCache = null;
2104-
}
2105-
}
2099+
releaseRootPooledCache(root);
21062100

21072101
if (__DEV__) {
21082102
if (enableDebugTracing) {
@@ -2117,6 +2111,16 @@ function commitRootImpl(root, renderPriorityLevel) {
21172111
return null;
21182112
}
21192113

2114+
function releaseRootPooledCache(root) {
2115+
if (enableCache) {
2116+
const pooledCache = root.pooledCache;
2117+
if (pooledCache != null) {
2118+
releaseCache(pooledCache);
2119+
root.pooledCache = null;
2120+
}
2121+
}
2122+
}
2123+
21202124
export function flushPassiveEffects(): boolean {
21212125
// Returns whether passive effects were flushed.
21222126
// TODO: Combine this check with the one in flushPassiveEFfectsImpl. We should

0 commit comments

Comments
 (0)