Jinuss's blog Jinuss's blog
首页
  • 源码合集

    • Leaflet源码分析
    • Openlayers源码合集
    • vue3源码
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • 学习
  • 实用技巧
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

东流

Web、WebGIS技术博客
首页
  • 源码合集

    • Leaflet源码分析
    • Openlayers源码合集
    • vue3源码
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • 学习
  • 实用技巧
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 《React源码》笔记
  • React-reconciler
东流
2026-02-06
目录

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
编辑 (opens new window)
上次更新: 2026/02/13, 09:33:29
最近更新
01
completeUnitOfWork方法解析
02-12
02
Scheduler任务调度执行
02-02
03
Scheduler的任务优先级
01-28
更多文章>
Theme by Vdoing | Copyright © 2024-2026 东流 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式