* 难点在于目标fiber的hostSibling可能并不是他的同级sibling * 比如: 其中:function B() {return } 所以A的hostSibling实际是B的child * 实际情况层级可能更深 * 同时:一个fiber被标记Placement,那他就是不稳定的(他对应的DOM在本次commit阶段会移动),也不能作为hostSibling
(fiber: FiberNode)
| 234 | * 同时:一个fiber被标记Placement,那他就是不稳定的(他对应的DOM在本次commit阶段会移动),也不能作为hostSibling |
| 235 | */ |
| 236 | function gethostSibling(fiber: FiberNode) { |
| 237 | let node: FiberNode = fiber; |
| 238 | findSibling: while (true) { |
| 239 | while (node.sibling === null) { |
| 240 | // 如果当前节点没有sibling,则找他父级sibling |
| 241 | const parent = node.return; |
| 242 | if ( |
| 243 | parent === null || |
| 244 | parent.tag === HostComponent || |
| 245 | parent.tag === HostRoot |
| 246 | ) { |
| 247 | // 没找到 |
| 248 | return null; |
| 249 | } |
| 250 | node = parent; |
| 251 | } |
| 252 | node.sibling.return = node.return; |
| 253 | // 向同级sibling寻找 |
| 254 | node = node.sibling; |
| 255 | |
| 256 | while (node.tag !== HostText && node.tag !== HostComponent) { |
| 257 | // 找到一个非Host fiber,向下找,直到找到第一个Host子孙 |
| 258 | if ((node.flags & Placement) !== NoFlags) { |
| 259 | // 这个fiber不稳定,不能用 |
| 260 | continue findSibling; |
| 261 | } |
| 262 | if (node.child === null) { |
| 263 | continue findSibling; |
| 264 | } else { |
| 265 | node.child.return = node; |
| 266 | node = node.child; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | // 找到最有可能的fiber |
| 271 | if ((node.flags & Placement) === NoFlags) { |
| 272 | // 这是稳定的fiber,就他了 |
| 273 | return node.stateNode; |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | function commitPassiveEffect( |
| 279 | fiber: FiberNode, |
nothing calls this directly
no outgoing calls
no test coverage detected