@@ -15,6 +15,7 @@ import type {Interaction} from 'scheduler/src/Tracing';
15
15
import type { SuspenseConfig } from './ReactFiberSuspenseConfig' ;
16
16
import type { SuspenseState } from './ReactFiberSuspenseComponent.new' ;
17
17
import type { Effect as HookEffect } from './ReactFiberHooks.new' ;
18
+ import type { HookEffectTag } from './ReactHookEffectTags' ;
18
19
import type { StackCursor } from './ReactFiberStack.new' ;
19
20
import type { FunctionComponentUpdateQueue } from './ReactFiberHooks.new' ;
20
21
@@ -209,6 +210,7 @@ import {
209
210
commitPassiveEffectDurations ,
210
211
commitResetTextContent ,
211
212
isSuspenseBoundaryBeingHidden ,
213
+ safelyCallDestroy ,
212
214
} from './ReactFiberCommitWork.new' ;
213
215
import { enqueueUpdate } from './ReactUpdateQueue.new' ;
214
216
import { resetContextDependencies } from './ReactFiberNewContext.new' ;
@@ -2702,6 +2704,8 @@ function flushPassiveMountEffects(firstChild: Fiber): void {
2702
2704
}
2703
2705
2704
2706
function flushPassiveMountEffectsImpl ( fiber : Fiber ) : void {
2707
+ setCurrentDebugFiberInDEV ( fiber ) ;
2708
+
2705
2709
const updateQueue : FunctionComponentUpdateQueue | null = ( fiber . updateQueue : any ) ;
2706
2710
const lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
2707
2711
if ( lastEffect !== null ) {
@@ -2715,7 +2719,6 @@ function flushPassiveMountEffectsImpl(fiber: Fiber): void {
2715
2719
( tag & HookHasEffect ) !== NoHookEffect
2716
2720
) {
2717
2721
if ( __DEV__ ) {
2718
- setCurrentDebugFiberInDEV ( fiber ) ;
2719
2722
if (
2720
2723
enableProfilerTimer &&
2721
2724
enableProfilerCommitHooks &&
@@ -2742,7 +2745,6 @@ function flushPassiveMountEffectsImpl(fiber: Fiber): void {
2742
2745
const error = clearCaughtError ( ) ;
2743
2746
captureCommitPhaseError ( fiber , error ) ;
2744
2747
}
2745
- resetCurrentDebugFiberInDEV ( ) ;
2746
2748
} else {
2747
2749
try {
2748
2750
const create = effect . create ;
@@ -2769,6 +2771,8 @@ function flushPassiveMountEffectsImpl(fiber: Fiber): void {
2769
2771
2770
2772
effect = next ;
2771
2773
} while ( effect !== firstEffect ) ;
2774
+
2775
+ resetCurrentDebugFiberInDEV ( ) ;
2772
2776
}
2773
2777
}
2774
2778
@@ -2813,7 +2817,7 @@ function flushPassiveUnmountEffects(firstChild: Fiber): void {
2813
2817
case Block : {
2814
2818
const primaryEffectTag = fiber . effectTag & Passive ;
2815
2819
if ( primaryEffectTag !== NoEffect ) {
2816
- flushPassiveUnmountEffectsImpl ( fiber ) ;
2820
+ flushPassiveUnmountEffectsImpl ( fiber , HookPassive | HookHasEffect ) ;
2817
2821
}
2818
2822
}
2819
2823
}
@@ -2845,7 +2849,7 @@ function flushPassiveUnmountEffectsInsideOfDeletedTree(
2845
2849
case ForwardRef :
2846
2850
case SimpleMemoComponent :
2847
2851
case Block : {
2848
- flushPassiveUnmountEffectsImpl ( fiber ) ;
2852
+ flushPassiveUnmountEffectsImpl ( fiber , HookPassive ) ;
2849
2853
}
2850
2854
}
2851
2855
}
@@ -2854,67 +2858,42 @@ function flushPassiveUnmountEffectsInsideOfDeletedTree(
2854
2858
}
2855
2859
}
2856
2860
2857
- function flushPassiveUnmountEffectsImpl ( fiber : Fiber ) : void {
2861
+ function flushPassiveUnmountEffectsImpl (
2862
+ fiber : Fiber ,
2863
+ // Tags to check for when deciding whether to unmount. e.g. to skip over
2864
+ // layout effects
2865
+ hookEffectTag : HookEffectTag ,
2866
+ ) : void {
2858
2867
const updateQueue : FunctionComponentUpdateQueue | null = ( fiber . updateQueue : any ) ;
2859
2868
const lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
2860
2869
if ( lastEffect !== null ) {
2870
+ setCurrentDebugFiberInDEV ( fiber ) ;
2871
+
2861
2872
const firstEffect = lastEffect . next ;
2862
2873
let effect = firstEffect ;
2863
2874
do {
2864
2875
const { next , tag } = effect ;
2865
- if (
2866
- ( tag & HookPassive ) !== NoHookEffect &&
2867
- ( tag & HookHasEffect ) !== NoHookEffect
2868
- ) {
2876
+ if ( ( tag & hookEffectTag ) === hookEffectTag ) {
2869
2877
const destroy = effect . destroy ;
2870
- effect . destroy = undefined ;
2871
-
2872
- if ( typeof destroy === 'function' ) {
2873
- if ( __DEV__ ) {
2874
- setCurrentDebugFiberInDEV ( fiber ) ;
2875
- if (
2876
- enableProfilerTimer &&
2877
- enableProfilerCommitHooks &&
2878
- fiber . mode & ProfileMode
2879
- ) {
2880
- startPassiveEffectTimer ( ) ;
2881
- invokeGuardedCallback ( null , destroy , null ) ;
2882
- recordPassiveEffectDuration ( fiber ) ;
2883
- } else {
2884
- invokeGuardedCallback ( null , destroy , null ) ;
2885
- }
2886
- if ( hasCaughtError ( ) ) {
2887
- invariant ( fiber !== null , 'Should be working on an effect.' ) ;
2888
- const error = clearCaughtError ( ) ;
2889
- captureCommitPhaseError ( fiber , error ) ;
2890
- }
2891
- resetCurrentDebugFiberInDEV ( ) ;
2878
+ if ( destroy !== undefined ) {
2879
+ effect . destroy = undefined ;
2880
+ if (
2881
+ enableProfilerTimer &&
2882
+ enableProfilerCommitHooks &&
2883
+ fiber . mode & ProfileMode
2884
+ ) {
2885
+ startPassiveEffectTimer ( ) ;
2886
+ safelyCallDestroy ( fiber , destroy ) ;
2887
+ recordPassiveEffectDuration ( fiber ) ;
2892
2888
} else {
2893
- try {
2894
- if (
2895
- enableProfilerTimer &&
2896
- enableProfilerCommitHooks &&
2897
- fiber . mode & ProfileMode
2898
- ) {
2899
- try {
2900
- startPassiveEffectTimer ( ) ;
2901
- destroy ( ) ;
2902
- } finally {
2903
- recordPassiveEffectDuration ( fiber ) ;
2904
- }
2905
- } else {
2906
- destroy ( ) ;
2907
- }
2908
- } catch ( error ) {
2909
- invariant ( fiber !== null , 'Should be working on an effect . ') ;
2910
- captureCommitPhaseError ( fiber , error ) ;
2911
- }
2889
+ safelyCallDestroy ( fiber , destroy ) ;
2912
2890
}
2913
2891
}
2914
2892
}
2915
-
2916
2893
effect = next ;
2917
2894
} while ( effect !== firstEffect ) ;
2895
+
2896
+ resetCurrentDebugFiberInDEV ( ) ;
2918
2897
}
2919
2898
}
2920
2899
0 commit comments