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-03-11
目录

completeWork方法解析

# 源码解析

# bubbleProperties方法

bubbleProperties方法用于将子节点的属性冒泡到父节点。属性包括childLanes、subtreeFlags、flags。

function bubbleProperties(completedWork) {
  // 计算 bailout 状态:
  // 如果当前节点的 alternate 存在,且 alternate 的子节点与当前节点的子节点相同,
  // 则说明当前节点的子树没有发生变化,直接返回 true,后续React可以跳过对子节点的重新协调
  var didBailout =
      null !== completedWork.alternate &&
      completedWork.alternate.child === completedWork.child,
      // 用于累加子节点的 lanes
    newChildLanes = 0,
    // 用于累加子节点的 subtreeFlags 和 flags
    subtreeFlags = 0;
 
 // didBailout 为 true或false时,遍历的逻辑都是一样,区别在于didBailout为true时,subtreeFlags 只累加子节点的 subtreeFlags 和 flags 的低16位,标记子树没有更新

  if (didBailout)
    for (var child$107 = completedWork.child; null !== child$107; )
      (newChildLanes |= child$107.lanes | child$107.childLanes),
        (subtreeFlags |= child$107.subtreeFlags & 65011712),
        (subtreeFlags |= child$107.flags & 65011712),
        (child$107.return = completedWork),
        (child$107 = child$107.sibling);
  else
    for (child$107 = completedWork.child; null !== child$107; )
      (newChildLanes |= child$107.lanes | child$107.childLanes),
        (subtreeFlags |= child$107.subtreeFlags),
        (subtreeFlags |= child$107.flags),
        (child$107.return = completedWork),
        (child$107 = child$107.sibling);
  // 更新父节点属性      
  completedWork.subtreeFlags |= subtreeFlags;
  completedWork.childLanes = newChildLanes;

  // 返回didBailout值
  return didBailout;
}
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
编辑 (opens new window)
上次更新: 2026/03/13, 10:06:03
最近更新
01
completeUnitOfWork方法解析
02-12
02
beginWork方法解析
02-06
03
Scheduler任务调度执行
02-02
更多文章>
Theme by Vdoing | Copyright © 2024-2026 东流 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式