( current: Fiber | null, workInProgress: Fiber, renderLanes: Lanes, )
| 1212 | } |
| 1213 | |
| 1214 | function updateCacheComponent( |
| 1215 | current: Fiber | null, |
| 1216 | workInProgress: Fiber, |
| 1217 | renderLanes: Lanes, |
| 1218 | ) { |
| 1219 | prepareToReadContext(workInProgress, renderLanes); |
| 1220 | const parentCache = readContext(CacheContext); |
| 1221 | |
| 1222 | if (current === null) { |
| 1223 | // Initial mount. Request a fresh cache from the pool. |
| 1224 | const freshCache = requestCacheFromPool(renderLanes); |
| 1225 | const initialState: CacheComponentState = { |
| 1226 | parent: parentCache, |
| 1227 | cache: freshCache, |
| 1228 | }; |
| 1229 | workInProgress.memoizedState = initialState; |
| 1230 | initializeUpdateQueue(workInProgress); |
| 1231 | pushCacheProvider(workInProgress, freshCache); |
| 1232 | } else { |
| 1233 | // Check for updates |
| 1234 | if (includesSomeLane(current.lanes, renderLanes)) { |
| 1235 | cloneUpdateQueue(current, workInProgress); |
| 1236 | processUpdateQueue(workInProgress, null, null, renderLanes); |
| 1237 | suspendIfUpdateReadFromEntangledAsyncAction(); |
| 1238 | } |
| 1239 | const prevState: CacheComponentState = current.memoizedState; |
| 1240 | const nextState: CacheComponentState = workInProgress.memoizedState; |
| 1241 | |
| 1242 | // Compare the new parent cache to the previous to see detect there was |
| 1243 | // a refresh. |
| 1244 | if (prevState.parent !== parentCache) { |
| 1245 | // Refresh in parent. Update the parent. |
| 1246 | const derivedState: CacheComponentState = { |
| 1247 | parent: parentCache, |
| 1248 | cache: parentCache, |
| 1249 | }; |
| 1250 | |
| 1251 | // Copied from getDerivedStateFromProps implementation. Once the update |
| 1252 | // queue is empty, persist the derived state onto the base state. |
| 1253 | workInProgress.memoizedState = derivedState; |
| 1254 | if (workInProgress.lanes === NoLanes) { |
| 1255 | const updateQueue: UpdateQueue<any> = (workInProgress.updateQueue: any); |
| 1256 | workInProgress.memoizedState = updateQueue.baseState = derivedState; |
| 1257 | } |
| 1258 | |
| 1259 | pushCacheProvider(workInProgress, parentCache); |
| 1260 | // No need to propagate a context change because the refreshed parent |
| 1261 | // already did. |
| 1262 | } else { |
| 1263 | // The parent didn't refresh. Now check if this cache did. |
| 1264 | const nextCache = nextState.cache; |
| 1265 | pushCacheProvider(workInProgress, nextCache); |
| 1266 | if (nextCache !== prevState.cache) { |
| 1267 | // This cache refreshed. Propagate a context change. |
| 1268 | propagateContextChange(workInProgress, CacheContext, renderLanes); |
| 1269 | } |
| 1270 | } |
| 1271 | } |
no test coverage detected