( root: FiberRoot, returnFiber: Fiber, deletedFiber: Fiber, )
| 1323 | let hostParentIsContainer: boolean = false; |
| 1324 | |
| 1325 | function commitDeletionEffects( |
| 1326 | root: FiberRoot, |
| 1327 | returnFiber: Fiber, |
| 1328 | deletedFiber: Fiber, |
| 1329 | ) { |
| 1330 | const prevEffectStart = pushComponentEffectStart(); |
| 1331 | |
| 1332 | if (supportsMutation) { |
| 1333 | // We only have the top Fiber that was deleted but we need to recurse down its |
| 1334 | // children to find all the terminal nodes. |
| 1335 | |
| 1336 | // Recursively delete all host nodes from the parent, detach refs, clean |
| 1337 | // up mounted layout effects, and call componentWillUnmount. |
| 1338 | |
| 1339 | // We only need to remove the topmost host child in each branch. But then we |
| 1340 | // still need to keep traversing to unmount effects, refs, and cWU. TODO: We |
| 1341 | // could split this into two separate traversals functions, where the second |
| 1342 | // one doesn't include any removeChild logic. This is maybe the same |
| 1343 | // function as "disappearLayoutEffects" (or whatever that turns into after |
| 1344 | // the layout phase is refactored to use recursion). |
| 1345 | |
| 1346 | // Before starting, find the nearest host parent on the stack so we know |
| 1347 | // which instance/container to remove the children from. |
| 1348 | // TODO: Instead of searching up the fiber return path on every deletion, we |
| 1349 | // can track the nearest host component on the JS stack as we traverse the |
| 1350 | // tree during the commit phase. This would make insertions faster, too. |
| 1351 | let parent: null | Fiber = returnFiber; |
| 1352 | findParent: while (parent !== null) { |
| 1353 | switch (parent.tag) { |
| 1354 | case HostSingleton: { |
| 1355 | if (supportsSingletons) { |
| 1356 | if (isSingletonScope(parent.type)) { |
| 1357 | hostParent = parent.stateNode; |
| 1358 | hostParentIsContainer = false; |
| 1359 | break findParent; |
| 1360 | } |
| 1361 | break; |
| 1362 | } |
| 1363 | // Expected fallthrough when supportsSingletons is false |
| 1364 | } |
| 1365 | case HostComponent: { |
| 1366 | hostParent = parent.stateNode; |
| 1367 | hostParentIsContainer = false; |
| 1368 | break findParent; |
| 1369 | } |
| 1370 | case HostRoot: |
| 1371 | case HostPortal: { |
| 1372 | hostParent = parent.stateNode.containerInfo; |
| 1373 | hostParentIsContainer = true; |
| 1374 | break findParent; |
| 1375 | } |
| 1376 | } |
| 1377 | parent = parent.return; |
| 1378 | } |
| 1379 | if (hostParent === null) { |
| 1380 | throw new Error( |
| 1381 | 'Expected to find a host parent. This error is likely caused by ' + |
| 1382 | 'a bug in React. Please file an issue.', |
no test coverage detected