MCPcopy Create free account
hub / github.com/BetaSu/big-react / commitDeletion

Function commitDeletion

packages/react-reconciler/src/commitWork.ts:364–398  ·  view source on GitHub ↗
(childToDelete: FiberNode, root: FiberRootNode)

Source from the content-addressed store, hash-verified

362}
363
364function commitDeletion(childToDelete: FiberNode, root: FiberRootNode) {
365 const rootChildrenToDelete: FiberNode[] = [];
366
367 // 递归子树
368 commitNestedComponent(childToDelete, (unmountFiber) => {
369 switch (unmountFiber.tag) {
370 case HostComponent:
371 recordHostChildrenToDelete(rootChildrenToDelete, unmountFiber);
372 safelyDetachRef(unmountFiber);
373 return;
374 case HostText:
375 recordHostChildrenToDelete(rootChildrenToDelete, unmountFiber);
376 return;
377 case FunctionComponent:
378 commitPassiveEffect(unmountFiber, root, 'unmount');
379 return;
380 default:
381 if (__DEV__) {
382 console.warn('未处理的unmount类型', unmountFiber);
383 }
384 }
385 });
386
387 // 移除rootHostComponent的DOM
388 if (rootChildrenToDelete.length) {
389 const hostParent = getHostParent(childToDelete);
390 if (hostParent !== null) {
391 rootChildrenToDelete.forEach((node) => {
392 removeChild(node.stateNode, hostParent);
393 });
394 }
395 }
396 childToDelete.return = null;
397 childToDelete.child = null;
398}
399
400function commitNestedComponent(
401 root: FiberNode,

Callers 1

Calls 6

removeChildFunction · 0.90
commitNestedComponentFunction · 0.85
safelyDetachRefFunction · 0.85
commitPassiveEffectFunction · 0.85
getHostParentFunction · 0.85

Tested by

no test coverage detected