updateCacheComponent() — react Function Reference
Architecture documentation for the updateCacheComponent() function in ReactFiberBeginWork.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD a1cb248e_a332_2329_3b0e_064edd3c0447["updateCacheComponent()"] 0be70812_cc0c_b210_f84f_8e61dd5f831c["ReactFiberBeginWork.js"] a1cb248e_a332_2329_3b0e_064edd3c0447 -->|defined in| 0be70812_cc0c_b210_f84f_8e61dd5f831c 235e1db1_02a4_912f_7d82_ea6636c850c0["beginWork()"] 235e1db1_02a4_912f_7d82_ea6636c850c0 -->|calls| a1cb248e_a332_2329_3b0e_064edd3c0447 554cee68_4cbf_1f39_7875_14cfa10442ae["pushCacheProvider()"] a1cb248e_a332_2329_3b0e_064edd3c0447 -->|calls| 554cee68_4cbf_1f39_7875_14cfa10442ae cf5641cc_b89e_d6b2_5d40_41ad5bbdd682["reconcileChildren()"] a1cb248e_a332_2329_3b0e_064edd3c0447 -->|calls| cf5641cc_b89e_d6b2_5d40_41ad5bbdd682 style a1cb248e_a332_2329_3b0e_064edd3c0447 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-reconciler/src/ReactFiberBeginWork.js lines 1213–1277
function updateCacheComponent(
current: Fiber | null,
workInProgress: Fiber,
renderLanes: Lanes,
) {
prepareToReadContext(workInProgress, renderLanes);
const parentCache = readContext(CacheContext);
if (current === null) {
// Initial mount. Request a fresh cache from the pool.
const freshCache = requestCacheFromPool(renderLanes);
const initialState: CacheComponentState = {
parent: parentCache,
cache: freshCache,
};
workInProgress.memoizedState = initialState;
initializeUpdateQueue(workInProgress);
pushCacheProvider(workInProgress, freshCache);
} else {
// Check for updates
if (includesSomeLane(current.lanes, renderLanes)) {
cloneUpdateQueue(current, workInProgress);
processUpdateQueue(workInProgress, null, null, renderLanes);
suspendIfUpdateReadFromEntangledAsyncAction();
}
const prevState: CacheComponentState = current.memoizedState;
const nextState: CacheComponentState = workInProgress.memoizedState;
// Compare the new parent cache to the previous to see detect there was
// a refresh.
if (prevState.parent !== parentCache) {
// Refresh in parent. Update the parent.
const derivedState: CacheComponentState = {
parent: parentCache,
cache: parentCache,
};
// Copied from getDerivedStateFromProps implementation. Once the update
// queue is empty, persist the derived state onto the base state.
workInProgress.memoizedState = derivedState;
if (workInProgress.lanes === NoLanes) {
const updateQueue: UpdateQueue<any> = (workInProgress.updateQueue: any);
workInProgress.memoizedState = updateQueue.baseState = derivedState;
}
pushCacheProvider(workInProgress, parentCache);
// No need to propagate a context change because the refreshed parent
// already did.
} else {
// The parent didn't refresh. Now check if this cache did.
const nextCache = nextState.cache;
pushCacheProvider(workInProgress, nextCache);
if (nextCache !== prevState.cache) {
// This cache refreshed. Propagate a context change.
propagateContextChange(workInProgress, CacheContext, renderLanes);
}
}
}
const nextProps: CacheProps = workInProgress.pendingProps;
const nextChildren = nextProps.children;
reconcileChildren(current, workInProgress, nextChildren, renderLanes);
return workInProgress.child;
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does updateCacheComponent() do?
updateCacheComponent() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberBeginWork.js.
Where is updateCacheComponent() defined?
updateCacheComponent() is defined in packages/react-reconciler/src/ReactFiberBeginWork.js at line 1213.
What does updateCacheComponent() call?
updateCacheComponent() calls 2 function(s): pushCacheProvider, reconcileChildren.
What calls updateCacheComponent()?
updateCacheComponent() is called by 1 function(s): beginWork.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free