@@ -323,7 +323,11 @@ function commitBeforeMutationLifeCycles(
323323) ;
324324}
325325
326- function commitHookEffectListUnmount ( tag : HookEffectTag , finishedWork : Fiber ) {
326+ function commitHookEffectListUnmount (
327+ tag : HookEffectTag ,
328+ finishedWork : Fiber ,
329+ nearestMountedAncestor : Fiber | null ,
330+ ) {
327331const updateQueue : FunctionComponentUpdateQueue | null = ( finishedWork . updateQueue : any ) ;
328332const lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
329333if ( lastEffect !== null ) {
@@ -335,7 +339,7 @@ function commitHookEffectListUnmount(tag: HookEffectTag, finishedWork: Fiber) {
335339const destroy = effect . destroy ;
336340effect . destroy = undefined ;
337341if ( destroy !== undefined ) {
338- safelyCallDestroy ( finishedWork , destroy ) ;
342+ safelyCallDestroy ( finishedWork , nearestMountedAncestor , destroy ) ;
339343}
340344}
341345effect = effect . next ;
@@ -1598,12 +1602,17 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
15981602commitHookEffectListUnmount (
15991603HookLayout | HookHasEffect ,
16001604finishedWork ,
1605+ finishedWork . return ,
16011606) ;
16021607} finally {
16031608recordLayoutEffectDuration ( finishedWork ) ;
16041609}
16051610} else {
1606- commitHookEffectListUnmount ( HookLayout | HookHasEffect , finishedWork ) ;
1611+ commitHookEffectListUnmount (
1612+ HookLayout | HookHasEffect ,
1613+ finishedWork ,
1614+ finishedWork . return ,
1615+ ) ;
16071616}
16081617return ;
16091618}
@@ -1658,12 +1667,20 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
16581667) {
16591668try {
16601669startLayoutEffectTimer ( ) ;
1661- commitHookEffectListUnmount ( HookLayout | HookHasEffect , finishedWork ) ;
1670+ commitHookEffectListUnmount (
1671+ HookLayout | HookHasEffect ,
1672+ finishedWork ,
1673+ finishedWork . return ,
1674+ ) ;
16621675} finally {
16631676recordLayoutEffectDuration ( finishedWork ) ;
16641677}
16651678} else {
1666- commitHookEffectListUnmount ( HookLayout | HookHasEffect , finishedWork ) ;
1679+ commitHookEffectListUnmount (
1680+ HookLayout | HookHasEffect ,
1681+ finishedWork ,
1682+ finishedWork . return ,
1683+ ) ;
16671684}
16681685return ;
16691686}
0 commit comments