@@ -325,32 +325,34 @@ function commitBeforeMutationLifeCycles(
325325 ) ;
326326}
327327
328- function commitHookEffectList (
329- unmountTag : number ,
330- mountTag : number ,
331- finishedWork : Fiber ,
332- ) {
328+ function commitHookEffectListUnmount ( tag : number , finishedWork : Fiber ) {
333329 const updateQueue : FunctionComponentUpdateQueue | null = ( finishedWork . updateQueue : any ) ;
334330 let lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
335331 if ( lastEffect !== null ) {
336332 const firstEffect = lastEffect . next ;
337333 let effect = firstEffect ;
338334 do {
339- if (
340- ( effect . tag & HookHasEffect ) !== NoHookEffect &&
341- ( effect . tag & unmountTag ) !== NoHookEffect
342- ) {
335+ if ( ( effect . tag & tag ) === tag ) {
343336 // Unmount
344337 const destroy = effect . destroy ;
345338 effect . destroy = undefined ;
346339 if ( destroy !== undefined ) {
347340 destroy ( ) ;
348341 }
349342 }
350- if (
351- ( effect . tag & HookHasEffect ) !== NoHookEffect &&
352- ( effect . tag & mountTag ) !== NoHookEffect
353- ) {
343+ effect = effect . next ;
344+ } while ( effect !== firstEffect ) ;
345+ }
346+ }
347+
348+ function commitHookEffectListMount ( tag : number , finishedWork : Fiber ) {
349+ const updateQueue : FunctionComponentUpdateQueue | null = ( finishedWork . updateQueue : any ) ;
350+ let lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
351+ if ( lastEffect !== null ) {
352+ const firstEffect = lastEffect . next ;
353+ let effect = firstEffect ;
354+ do {
355+ if ( ( effect . tag & tag ) === tag ) {
354356 // Mount
355357 const create = effect . create ;
356358 effect . destroy = create ( ) ;
@@ -404,8 +406,8 @@ export function commitPassiveHookEffects(finishedWork: Fiber): void {
404406 // TODO (#17945) We should call all passive destroy functions (for all fibers)
405407 // before calling any create functions. The current approach only serializes
406408 // these for a single fiber.
407- commitHookEffectList ( HookPassive , NoHookEffect , finishedWork ) ;
408- commitHookEffectList ( NoHookEffect , HookPassive , finishedWork ) ;
409+ commitHookEffectListUnmount ( HookPassive | HookHasEffect , finishedWork ) ;
410+ commitHookEffectListMount ( HookPassive | HookHasEffect , finishedWork ) ;
409411 break ;
410412 }
411413 default :
@@ -429,7 +431,7 @@ function commitLifeCycles(
429431 // This is done to prevent sibling component effects from interfering with each other,
430432 // e.g. a destroy function in one component should never override a ref set
431433 // by a create function in another component during the same commit.
432- commitHookEffectList ( NoHookEffect , HookLayout , finishedWork ) ;
434+ commitHookEffectListMount ( HookLayout | HookHasEffect , finishedWork ) ;
433435 return ;
434436 }
435437 case ClassComponent : {
@@ -1315,7 +1317,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
13151317 // This prevents sibling component effects from interfering with each other,
13161318 // e.g. a destroy function in one component should never override a ref set
13171319 // by a create function in another component during the same commit.
1318- commitHookEffectList ( HookLayout , NoHookEffect , finishedWork ) ;
1320+ commitHookEffectListUnmount ( HookLayout | HookHasEffect , finishedWork ) ;
13191321 return ;
13201322 }
13211323 case Profiler : {
@@ -1358,7 +1360,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
13581360 // This prevents sibling component effects from interfering with each other,
13591361 // e.g. a destroy function in one component should never override a ref set
13601362 // by a create function in another component during the same commit.
1361- commitHookEffectList ( HookLayout , NoHookEffect , finishedWork ) ;
1363+ commitHookEffectListUnmount ( HookLayout | HookHasEffect , finishedWork ) ;
13621364 return ;
13631365 }
13641366 case ClassComponent : {
0 commit comments