| 398 | } |
| 399 | |
| 400 | function commitNestedComponent( |
| 401 | root: FiberNode, |
| 402 | onCommitUnmount: (fiber: FiberNode) => void |
| 403 | ) { |
| 404 | let node = root; |
| 405 | while (true) { |
| 406 | onCommitUnmount(node); |
| 407 | |
| 408 | if (node.child !== null) { |
| 409 | // 向下遍历 |
| 410 | node.child.return = node; |
| 411 | node = node.child; |
| 412 | continue; |
| 413 | } |
| 414 | if (node === root) { |
| 415 | // 终止条件 |
| 416 | return; |
| 417 | } |
| 418 | while (node.sibling === null) { |
| 419 | if (node.return === null || node.return === root) { |
| 420 | return; |
| 421 | } |
| 422 | // 向上归 |
| 423 | node = node.return; |
| 424 | } |
| 425 | node.sibling.return = node.return; |
| 426 | node = node.sibling; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | const commitPlacement = (finishedWork: FiberNode) => { |
| 431 | if (__DEV__) { |