@@ -31,10 +31,8 @@ import {NoFlags} from './ReactFiberFlags';
31
31
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber' ;
32
32
import { resolveClassComponentProps } from './ReactFiberClassComponent' ;
33
33
import {
34
- recordLayoutEffectDuration ,
35
- startLayoutEffectTimer ,
36
- recordPassiveEffectDuration ,
37
- startPassiveEffectTimer ,
34
+ recordEffectDuration ,
35
+ startEffectTimer ,
38
36
isCurrentUpdateNested ,
39
37
} from './ReactProfilerTimer' ;
40
38
import { NoMode , ProfileMode } from './ReactTypeOfMode' ;
@@ -91,14 +89,41 @@ export function commitHookLayoutEffects(
91
89
// e.g. a destroy function in one component should never override a ref set
92
90
// by a create function in another component during the same commit.
93
91
if ( shouldProfile ( finishedWork ) ) {
94
- startLayoutEffectTimer ( ) ;
92
+ startEffectTimer ( ) ;
95
93
commitHookEffectListMount ( hookFlags , finishedWork ) ;
96
- recordLayoutEffectDuration ( finishedWork ) ;
94
+ recordEffectDuration ( finishedWork ) ;
97
95
} else {
98
96
commitHookEffectListMount ( hookFlags , finishedWork ) ;
99
97
}
100
98
}
101
99
100
+ export function commitHookLayoutUnmountEffects (
101
+ finishedWork : Fiber ,
102
+ nearestMountedAncestor : null | Fiber ,
103
+ hookFlags : HookFlags ,
104
+ ) {
105
+ // Layout effects are destroyed during the mutation phase so that all
106
+ // destroy functions for all fibers are called before any create functions.
107
+ // This prevents sibling component effects from interfering with each other,
108
+ // e.g. a destroy function in one component should never override a ref set
109
+ // by a create function in another component during the same commit.
110
+ if ( shouldProfile ( finishedWork ) ) {
111
+ startEffectTimer ( ) ;
112
+ commitHookEffectListUnmount (
113
+ hookFlags ,
114
+ finishedWork ,
115
+ nearestMountedAncestor ,
116
+ ) ;
117
+ recordEffectDuration ( finishedWork ) ;
118
+ } else {
119
+ commitHookEffectListUnmount (
120
+ hookFlags ,
121
+ finishedWork ,
122
+ nearestMountedAncestor ,
123
+ ) ;
124
+ }
125
+ }
126
+
102
127
export function commitHookEffectListMount (
103
128
flags : HookFlags ,
104
129
finishedWork : Fiber ,
@@ -265,9 +290,9 @@ export function commitHookPassiveMountEffects(
265
290
hookFlags : HookFlags ,
266
291
) {
267
292
if ( shouldProfile ( finishedWork ) ) {
268
- startPassiveEffectTimer ( ) ;
293
+ startEffectTimer ( ) ;
269
294
commitHookEffectListMount ( hookFlags , finishedWork ) ;
270
- recordPassiveEffectDuration ( finishedWork ) ;
295
+ recordEffectDuration ( finishedWork ) ;
271
296
} else {
272
297
commitHookEffectListMount ( hookFlags , finishedWork ) ;
273
298
}
@@ -279,13 +304,13 @@ export function commitHookPassiveUnmountEffects(
279
304
hookFlags : HookFlags ,
280
305
) {
281
306
if ( shouldProfile ( finishedWork ) ) {
282
- startPassiveEffectTimer ( ) ;
307
+ startEffectTimer ( ) ;
283
308
commitHookEffectListUnmount (
284
309
hookFlags ,
285
310
finishedWork ,
286
311
nearestMountedAncestor ,
287
312
) ;
288
- recordPassiveEffectDuration ( finishedWork ) ;
313
+ recordEffectDuration ( finishedWork ) ;
289
314
} else {
290
315
commitHookEffectListUnmount (
291
316
hookFlags ,
@@ -333,7 +358,7 @@ export function commitClassLayoutLifecycles(
333
358
}
334
359
}
335
360
if ( shouldProfile ( finishedWork ) ) {
336
- startLayoutEffectTimer ( ) ;
361
+ startEffectTimer ( ) ;
337
362
if ( __DEV__ ) {
338
363
runWithFiberInDEV (
339
364
finishedWork ,
@@ -348,7 +373,7 @@ export function commitClassLayoutLifecycles(
348
373
captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
349
374
}
350
375
}
351
- recordLayoutEffectDuration ( finishedWork ) ;
376
+ recordEffectDuration ( finishedWork ) ;
352
377
} else {
353
378
if ( __DEV__ ) {
354
379
runWithFiberInDEV (
@@ -404,7 +429,7 @@ export function commitClassLayoutLifecycles(
404
429
}
405
430
}
406
431
if ( shouldProfile ( finishedWork ) ) {
407
- startLayoutEffectTimer ( ) ;
432
+ startEffectTimer ( ) ;
408
433
if ( __DEV__ ) {
409
434
runWithFiberInDEV (
410
435
finishedWork ,
@@ -426,7 +451,7 @@ export function commitClassLayoutLifecycles(
426
451
captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
427
452
}
428
453
}
429
- recordLayoutEffectDuration ( finishedWork ) ;
454
+ recordEffectDuration ( finishedWork ) ;
430
455
} else {
431
456
if ( __DEV__ ) {
432
457
runWithFiberInDEV (
@@ -679,7 +704,7 @@ export function safelyCallComponentWillUnmount(
679
704
) ;
680
705
instance . state = current . memoizedState ;
681
706
if ( shouldProfile ( current ) ) {
682
- startLayoutEffectTimer ( ) ;
707
+ startEffectTimer ( ) ;
683
708
if ( __DEV__ ) {
684
709
runWithFiberInDEV (
685
710
current ,
@@ -695,7 +720,7 @@ export function safelyCallComponentWillUnmount(
695
720
captureCommitPhaseError ( current , nearestMountedAncestor , error ) ;
696
721
}
697
722
}
698
- recordLayoutEffectDuration ( current ) ;
723
+ recordEffectDuration ( current ) ;
699
724
} else {
700
725
if ( __DEV__ ) {
701
726
runWithFiberInDEV (
@@ -736,10 +761,10 @@ function commitAttachRef(finishedWork: Fiber) {
736
761
if (typeof ref === 'function') {
737
762
if ( shouldProfile ( finishedWork ) ) {
738
763
try {
739
- startLayoutEffectTimer ( ) ;
764
+ startEffectTimer ( ) ;
740
765
finishedWork . refCleanup = ref ( instanceToUse ) ;
741
766
} finally {
742
- recordLayoutEffectDuration ( finishedWork ) ;
767
+ recordEffectDuration ( finishedWork ) ;
743
768
}
744
769
} else {
745
770
finishedWork . refCleanup = ref ( instanceToUse ) ;
@@ -793,14 +818,14 @@ export function safelyDetachRef(
793
818
try {
794
819
if ( shouldProfile ( current ) ) {
795
820
try {
796
- startLayoutEffectTimer ( ) ;
821
+ startEffectTimer ( ) ;
797
822
if ( __DEV__ ) {
798
823
runWithFiberInDEV ( current , refCleanup ) ;
799
824
} else {
800
825
refCleanup ( ) ;
801
826
}
802
827
} finally {
803
- recordLayoutEffectDuration ( current ) ;
828
+ recordEffectDuration ( current ) ;
804
829
}
805
830
} else {
806
831
if ( __DEV__ ) {
@@ -823,14 +848,14 @@ export function safelyDetachRef(
823
848
try {
824
849
if ( shouldProfile ( current ) ) {
825
850
try {
826
- startLayoutEffectTimer ( ) ;
851
+ startEffectTimer ( ) ;
827
852
if ( __DEV__ ) {
828
853
( runWithFiberInDEV ( current , ref, null ) : void ) ;
829
854
} else {
830
855
ref ( null ) ;
831
856
}
832
857
} finally {
833
- recordLayoutEffectDuration ( current ) ;
858
+ recordEffectDuration ( current ) ;
834
859
}
835
860
} else {
836
861
if ( __DEV__ ) {
@@ -849,7 +874,7 @@ export function safelyDetachRef(
849
874
}
850
875
}
851
876
852
- export function safelyCallDestroy (
877
+ function safelyCallDestroy (
853
878
current : Fiber ,
854
879
nearestMountedAncestor : Fiber | null ,
855
880
destroy : ( ) = > void ,
0 commit comments