MCPcopy
hub / github.com/facebook/react / beginWork

Function beginWork

packages/react-reconciler/src/ReactFiberBeginWork.js:4091–4373  ·  view source on GitHub ↗
(
  current: Fiber | null,
  workInProgress: Fiber,
  renderLanes: Lanes,
)

Source from the content-addressed store, hash-verified

4089}
4090
4091function beginWork(
4092 current: Fiber | null,
4093 workInProgress: Fiber,
4094 renderLanes: Lanes,
4095): Fiber | null {
4096 if (__DEV__) {
4097 if (workInProgress._debugNeedsRemount && current !== null) {
4098 // This will restart the begin phase with a new fiber.
4099 const copiedFiber = createFiberFromTypeAndProps(
4100 workInProgress.type,
4101 workInProgress.key,
4102 workInProgress.pendingProps,
4103 workInProgress._debugOwner || null,
4104 workInProgress.mode,
4105 workInProgress.lanes,
4106 );
4107 copiedFiber._debugStack = workInProgress._debugStack;
4108 copiedFiber._debugTask = workInProgress._debugTask;
4109 return remountFiber(current, workInProgress, copiedFiber);
4110 }
4111 }
4112
4113 if (current !== null) {
4114 const oldProps = current.memoizedProps;
4115 const newProps = workInProgress.pendingProps;
4116
4117 if (
4118 oldProps !== newProps ||
4119 hasLegacyContextChanged() ||
4120 // Force a re-render if the implementation changed due to hot reload:
4121 (__DEV__ ? workInProgress.type !== current.type : false)
4122 ) {
4123 // If props or context changed, mark the fiber as having performed work.
4124 // This may be unset if the props are determined to be equal later (memo).
4125 didReceiveUpdate = true;
4126 } else {
4127 // Neither props nor legacy context changes. Check if there's a pending
4128 // update or context change.
4129 const hasScheduledUpdateOrContext = checkScheduledUpdateOrContext(
4130 current,
4131 renderLanes,
4132 );
4133 if (
4134 !hasScheduledUpdateOrContext &&
4135 // If this is the second pass of an error or suspense boundary, there
4136 // may not be work scheduled on `current`, so we check for this flag.
4137 (workInProgress.flags & DidCapture) === NoFlags
4138 ) {
4139 // No pending updates or context. Bail out now.
4140 didReceiveUpdate = false;
4141 return attemptEarlyBailoutIfNoScheduledUpdate(
4142 current,
4143 workInProgress,
4144 renderLanes,
4145 );
4146 }
4147 if ((current.flags & ForceUpdateForLegacySuspense) !== NoFlags) {
4148 // This is a special case that only exists for legacy mode.

Callers 2

performUnitOfWorkFunction · 0.90
replayBeginWorkFunction · 0.90

Calls 15

getIsHydratingFunction · 0.90
isForkedChildFunction · 0.90
getForksAtLevelFunction · 0.90
pushTreeIdFunction · 0.90
remountFiberFunction · 0.85
mountLazyComponentFunction · 0.85
updateFunctionComponentFunction · 0.85
updateClassComponentFunction · 0.85

Tested by

no test coverage detected