@@ -325,32 +325,34 @@ function commitBeforeMutationLifeCycles(
325
325
) ;
326
326
}
327
327
328
- function commitHookEffectList (
329
- unmountTag : number ,
330
- mountTag : number ,
331
- finishedWork : Fiber ,
332
- ) {
328
+ function commitHookEffectListUnmount ( tag : number , finishedWork : Fiber ) {
333
329
const updateQueue : FunctionComponentUpdateQueue | null = ( finishedWork . updateQueue : any ) ;
334
330
let lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
335
331
if ( lastEffect !== null ) {
336
332
const firstEffect = lastEffect . next ;
337
333
let effect = firstEffect ;
338
334
do {
339
- if (
340
- ( effect . tag & HookHasEffect ) !== NoHookEffect &&
341
- ( effect . tag & unmountTag ) !== NoHookEffect
342
- ) {
335
+ if ( ( effect . tag & tag ) === tag ) {
343
336
// Unmount
344
337
const destroy = effect . destroy ;
345
338
effect . destroy = undefined ;
346
339
if ( destroy !== undefined ) {
347
340
destroy ( ) ;
348
341
}
349
342
}
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 ) {
354
356
// Mount
355
357
const create = effect . create ;
356
358
effect . destroy = create ( ) ;
@@ -404,8 +406,8 @@ export function commitPassiveHookEffects(finishedWork: Fiber): void {
404
406
// TODO (#17945) We should call all passive destroy functions (for all fibers)
405
407
// before calling any create functions. The current approach only serializes
406
408
// 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 ) ;
409
411
break ;
410
412
}
411
413
default :
@@ -429,7 +431,7 @@ function commitLifeCycles(
429
431
// This is done to prevent sibling component effects from interfering with each other,
430
432
// e.g. a destroy function in one component should never override a ref set
431
433
// by a create function in another component during the same commit.
432
- commitHookEffectList ( NoHookEffect , HookLayout , finishedWork ) ;
434
+ commitHookEffectListMount ( HookLayout | HookHasEffect , finishedWork ) ;
433
435
return ;
434
436
}
435
437
case ClassComponent : {
@@ -1315,7 +1317,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
1315
1317
// This prevents sibling component effects from interfering with each other,
1316
1318
// e.g. a destroy function in one component should never override a ref set
1317
1319
// by a create function in another component during the same commit.
1318
- commitHookEffectList ( HookLayout , NoHookEffect , finishedWork ) ;
1320
+ commitHookEffectListUnmount ( HookLayout | HookHasEffect , finishedWork ) ;
1319
1321
return ;
1320
1322
}
1321
1323
case Profiler : {
@@ -1358,7 +1360,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
1358
1360
// This prevents sibling component effects from interfering with each other,
1359
1361
// e.g. a destroy function in one component should never override a ref set
1360
1362
// by a create function in another component during the same commit.
1361
- commitHookEffectList ( HookLayout , NoHookEffect , finishedWork ) ;
1363
+ commitHookEffectListUnmount ( HookLayout | HookHasEffect , finishedWork ) ;
1362
1364
return ;
1363
1365
}
1364
1366
case ClassComponent : {
0 commit comments