|
8 | 8 | */ |
9 | 9 |
|
10 | 10 | import type {ReactContext} from 'shared/ReactTypes'; |
11 | | -import type {FiberRoot} from './ReactInternalTypes'; |
12 | | -import type {Lanes} from './ReactFiberLane.old'; |
13 | | -import type {StackCursor} from './ReactFiberStack.old'; |
14 | 11 |
|
15 | 12 | import {enableCache} from 'shared/ReactFeatureFlags'; |
16 | 13 | import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols'; |
17 | 14 |
|
18 | | -import {isPrimaryRenderer} from './ReactFiberHostConfig'; |
19 | | -import {createCursor, push, pop} from './ReactFiberStack.old'; |
20 | 15 | import {pushProvider, popProvider} from './ReactFiberNewContext.old'; |
21 | 16 | import * as Scheduler from 'scheduler'; |
22 | | -import {getWorkInProgressRoot} from './ReactFiberWorkLoop.old'; |
23 | 17 |
|
24 | 18 | export type Cache = {| |
25 | 19 | controller: AbortController, |
@@ -62,10 +56,6 @@ if (__DEV__ && enableCache) { |
62 | 56 | CacheContext._currentRenderer2 = null; |
63 | 57 | } |
64 | 58 |
|
65 | | -// When retrying a Suspense/Offscreen boundary, we restore the cache that was |
66 | | -// used during the previous render by placing it here, on the stack. |
67 | | -const resumedCache: StackCursor<Cache | null> = createCursor(null); |
68 | | - |
69 | 59 | // Creates a new empty Cache instance with a ref-count of 0. The caller is responsible |
70 | 60 | // for retaining the cache once it is in use (retainCache), and releasing the cache |
71 | 61 | // once it is no longer needed (releaseCache). |
@@ -131,135 +121,3 @@ export function popCacheProvider(workInProgress: Fiber, cache: Cache) { |
131 | 121 | } |
132 | 122 | popProvider(CacheContext, workInProgress); |
133 | 123 | } |
134 | | - |
135 | | -function peekCacheFromPool(): Cache | null { |
136 | | - if (!enableCache) { |
137 | | - return (null: any); |
138 | | - } |
139 | | - |
140 | | - // Check if the cache pool already has a cache we can use. |
141 | | - |
142 | | - // If we're rendering inside a Suspense boundary that is currently hidden, |
143 | | - // we should use the same cache that we used during the previous render, if |
144 | | - // one exists. |
145 | | - const cacheResumedFromPreviousRender = resumedCache.current; |
146 | | - if (cacheResumedFromPreviousRender !== null) { |
147 | | - return cacheResumedFromPreviousRender; |
148 | | - } |
149 | | - |
150 | | - // Otherwise, check the root's cache pool. |
151 | | - const root = (getWorkInProgressRoot(): any); |
152 | | - const cacheFromRootCachePool = root.pooledCache; |
153 | | - |
154 | | - return cacheFromRootCachePool; |
155 | | -} |
156 | | - |
157 | | -export function requestCacheFromPool(renderLanes: Lanes): Cache { |
158 | | - // Similar to previous function, except if there's not already a cache in the |
159 | | - // pool, we allocate a new one. |
160 | | - const cacheFromPool = peekCacheFromPool(); |
161 | | - if (cacheFromPool !== null) { |
162 | | - return cacheFromPool; |
163 | | - } |
164 | | - |
165 | | - // Create a fresh cache and add it to the root cache pool. A cache can have |
166 | | - // multiple owners: |
167 | | - // - A cache pool that lives on the FiberRoot. This is where all fresh caches |
168 | | - // are originally created (TODO: except during refreshes, until we implement |
169 | | - // this correctly). The root takes ownership immediately when the cache is |
170 | | - // created. Conceptually, root.pooledCache is an Option<Arc<Cache>> (owned), |
171 | | - // and the return value of this function is a &Arc<Cache> (borrowed). |
172 | | - // - One of several fiber types: host root, cache boundary, suspense |
173 | | - // component. These retain and release in the commit phase. |
174 | | - |
175 | | - const root = (getWorkInProgressRoot(): any); |
176 | | - const freshCache = createCache(); |
177 | | - root.pooledCache = freshCache; |
178 | | - retainCache(freshCache); |
179 | | - if (freshCache !== null) { |
180 | | - root.pooledCacheLanes |= renderLanes; |
181 | | - } |
182 | | - return freshCache; |
183 | | -} |
184 | | - |
185 | | -export function pushRootCachePool(root: FiberRoot) { |
186 | | - if (!enableCache) { |
187 | | - return; |
188 | | - } |
189 | | - // Note: This function currently does nothing but I'll leave it here for |
190 | | - // code organization purposes in case that changes. |
191 | | -} |
192 | | - |
193 | | -export function popRootCachePool(root: FiberRoot, renderLanes: Lanes) { |
194 | | - if (!enableCache) { |
195 | | - return; |
196 | | - } |
197 | | - // Note: This function currently does nothing but I'll leave it here for |
198 | | - // code organization purposes in case that changes. |
199 | | -} |
200 | | - |
201 | | -export function pushSpawnedCachePool( |
202 | | - offscreenWorkInProgress: Fiber, |
203 | | - prevCachePool: SpawnedCachePool | null, |
204 | | -): void { |
205 | | - if (!enableCache) { |
206 | | - return; |
207 | | - } |
208 | | - |
209 | | - if (prevCachePool === null) { |
210 | | - push(resumedCache, resumedCache.current, offscreenWorkInProgress); |
211 | | - } else { |
212 | | - push(resumedCache, prevCachePool.pool, offscreenWorkInProgress); |
213 | | - } |
214 | | -} |
215 | | - |
216 | | -export function popCachePool(workInProgress: Fiber) { |
217 | | - if (!enableCache) { |
218 | | - return; |
219 | | - } |
220 | | - |
221 | | - pop(resumedCache, workInProgress); |
222 | | -} |
223 | | - |
224 | | -export function getSuspendedCachePool(): SpawnedCachePool | null { |
225 | | - if (!enableCache) { |
226 | | - return null; |
227 | | - } |
228 | | - // This function is called when a Suspense boundary suspends. It returns the |
229 | | - // cache that would have been used to render fresh data during this render, |
230 | | - // if there was any, so that we can resume rendering with the same cache when |
231 | | - // we receive more data. |
232 | | - const cacheFromPool = peekCacheFromPool(); |
233 | | - if (cacheFromPool === null) { |
234 | | - return null; |
235 | | - } |
236 | | - |
237 | | - return { |
238 | | - // We must also save the parent, so that when we resume we can detect |
239 | | - // a refresh. |
240 | | - parent: isPrimaryRenderer |
241 | | - ? CacheContext._currentValue |
242 | | - : CacheContext._currentValue2, |
243 | | - pool: cacheFromPool, |
244 | | - }; |
245 | | -} |
246 | | - |
247 | | -export function getOffscreenDeferredCachePool(): SpawnedCachePool | null { |
248 | | - if (!enableCache) { |
249 | | - return null; |
250 | | - } |
251 | | - |
252 | | - const cacheFromPool = peekCacheFromPool(); |
253 | | - if (cacheFromPool === null) { |
254 | | - return null; |
255 | | - } |
256 | | - |
257 | | - return { |
258 | | - // We must also store the parent, so that when we resume we can detect |
259 | | - // a refresh. |
260 | | - parent: isPrimaryRenderer |
261 | | - ? CacheContext._currentValue |
262 | | - : CacheContext._currentValue2, |
263 | | - pool: cacheFromPool, |
264 | | - }; |
265 | | -} |
0 commit comments