beginWork方法解析
# 概览
beginWork
function beginWork(current, workInProgress, renderLanes) {
if (current != null) {
// 有旧Fiber,说明是更新操作,对比是否需要更新
// 对比新旧props
if (current.memoizedProps !== workInProgress.pendingProps) {
didReceiveUpdate = true;// 表示需要更新
} else {
// 若Props不同,则检查是否有计划的更新或context变化
const hasScheduledUpdateOrContext = checkScheduledUpdateOrContext(
current,
renderLanes,
);
if (
!hasScheduledUpdateOrContext &&
(workInProgress.flags & DidCapture) === NoFlags
) {
// 没有更新且没有捕获错误,尝试提前退出
didReceiveUpdate = false;
return attemptEarlyBailoutIfNoScheduledUpdate(
current,
workInProgress,
renderLanes,
);
}
// 检查是否有强制更新 用于Legacy Suspense
if ((current.flags & ForceUpdateForLegacySuspense) !== NoFlags) {
didReceiveUpdate = true;
} else {
didReceiveUpdate = false;
}
}
} else {
// 没有旧Fiber,是首次渲染
didReceiveUpdate = false;
// 处理Hydration相关逻辑
if (getIsHydrating() && isForkedChild(workInProgress)) {
const slotIndex = workInProgress.index;
const numberOfForks = getForksAtLevel(workInProgress);
pushTreeId(workInProgress, numberOfForks, slotIndex);
}
}
// 重置工作 Fiber 的 lanes
workInProgress.lanes = NoLanes;
switch (workInProgress.tag) {
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
编辑 (opens new window)
上次更新: 2026/02/13, 09:33:29