Release pooled cache reference in complete/unwind (#22464)
Joseph Savona committed
Sep 29, 2021 at 15:49 UTC
201af81b0168cabea3cc07cd8201378a4fec4aaf
2 files changed
+12
-8
packages/react-reconciler/src/ReactFiberCacheComponent.new.js
+6
-4
@@ -99,14 +99,16 @@ export function popRootCachePool(root: FiberRoot, renderLanes: Lanes) {
99
return;
100
}
101
// The `pooledCache` variable points to the cache that was used for new
102
- // cache boundaries during this render, if any. Stash it on the root so that
103
- // parallel transitions may share the same cache. We will clear this field
104
- // once all the transitions that depend on it (which we track with
105
- // `pooledCacheLanes`) have committed.
102
+ // cache boundaries during this render, if any. Move ownership of the
103
+ // cache to the root so that parallel transitions may share the same
104
+ // cache. We will clear this field once all the transitions that depend
105
+ // on it (which we track with `pooledCacheLanes`) have committed.
106
root.pooledCache = pooledCache;
107
if (pooledCache !== null) {
108
root.pooledCacheLanes |= renderLanes;
109
}
110
+ // set to null, conceptually we are moving ownership to the root
111
+ pooledCache = null;
112
}
113
114
export function restoreSpawnedCachePool(
packages/react-reconciler/src/ReactFiberCacheComponent.old.js
+6
-4
@@ -99,14 +99,16 @@ export function popRootCachePool(root: FiberRoot, renderLanes: Lanes) {
99
return;
100
}
101
// The `pooledCache` variable points to the cache that was used for new
102
- // cache boundaries during this render, if any. Stash it on the root so that
103
- // parallel transitions may share the same cache. We will clear this field
104
- // once all the transitions that depend on it (which we track with
105
- // `pooledCacheLanes`) have committed.
102
+ // cache boundaries during this render, if any. Move ownership of the
103
+ // cache to the root so that parallel transitions may share the same
104
+ // cache. We will clear this field once all the transitions that depend
105
+ // on it (which we track with `pooledCacheLanes`) have committed.
106
root.pooledCache = pooledCache;
107
if (pooledCache !== null) {
108
root.pooledCacheLanes |= renderLanes;
109
}
110
+ // set to null, conceptually we are moving ownership to the root
111
+ pooledCache = null;
112
}
113
114
export function restoreSpawnedCachePool(