@@ -323,7 +323,11 @@ function commitBeforeMutationLifeCycles( |
323 | 323 | ); |
324 | 324 | } |
325 | 325 |
|
326 | | -function commitHookEffectListUnmount(tag: HookEffectTag, finishedWork: Fiber) { |
| 326 | +function commitHookEffectListUnmount( |
| 327 | + tag: HookEffectTag, |
| 328 | + finishedWork: Fiber, |
| 329 | + nearestMountedAncestor: Fiber | null, |
| 330 | +) { |
327 | 331 | const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any); |
328 | 332 | const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null; |
329 | 333 | if (lastEffect !== null) { |
@@ -335,7 +339,7 @@ function commitHookEffectListUnmount(tag: HookEffectTag, finishedWork: Fiber) { |
335 | 339 | const destroy = effect.destroy; |
336 | 340 | effect.destroy = undefined; |
337 | 341 | if (destroy !== undefined) { |
338 | | - safelyCallDestroy(finishedWork, destroy); |
| 342 | + safelyCallDestroy(finishedWork, nearestMountedAncestor, destroy); |
339 | 343 | } |
340 | 344 | } |
341 | 345 | effect = effect.next; |
@@ -1598,12 +1602,17 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void { |
1598 | 1602 | commitHookEffectListUnmount( |
1599 | 1603 | HookLayout | HookHasEffect, |
1600 | 1604 | finishedWork, |
| 1605 | + finishedWork.return, |
1601 | 1606 | ); |
1602 | 1607 | } finally { |
1603 | 1608 | recordLayoutEffectDuration(finishedWork); |
1604 | 1609 | } |
1605 | 1610 | } else { |
1606 | | - commitHookEffectListUnmount(HookLayout | HookHasEffect, finishedWork); |
| 1611 | + commitHookEffectListUnmount( |
| 1612 | + HookLayout | HookHasEffect, |
| 1613 | + finishedWork, |
| 1614 | + finishedWork.return, |
| 1615 | + ); |
1607 | 1616 | } |
1608 | 1617 | return; |
1609 | 1618 | } |
@@ -1658,12 +1667,20 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void { |
1658 | 1667 | ) { |
1659 | 1668 | try { |
1660 | 1669 | startLayoutEffectTimer(); |
1661 | | - commitHookEffectListUnmount(HookLayout | HookHasEffect, finishedWork); |
| 1670 | + commitHookEffectListUnmount( |
| 1671 | + HookLayout | HookHasEffect, |
| 1672 | + finishedWork, |
| 1673 | + finishedWork.return, |
| 1674 | + ); |
1662 | 1675 | } finally { |
1663 | 1676 | recordLayoutEffectDuration(finishedWork); |
1664 | 1677 | } |
1665 | 1678 | } else { |
1666 | | - commitHookEffectListUnmount(HookLayout | HookHasEffect, finishedWork); |
| 1679 | + commitHookEffectListUnmount( |
| 1680 | + HookLayout | HookHasEffect, |
| 1681 | + finishedWork, |
| 1682 | + finishedWork.return, |
| 1683 | + ); |
1667 | 1684 | } |
1668 | 1685 | return; |
1669 | 1686 | } |
|