@@ -35,6 +35,7 @@ import {
35
35
enableFundamentalAPI ,
36
36
enableSuspenseCallback ,
37
37
enableScopeAPI ,
38
+ enableDoubleInvokingEffects ,
38
39
} from 'shared/ReactFeatureFlags' ;
39
40
import {
40
41
FunctionComponent ,
@@ -159,7 +160,7 @@ const callComponentWillUnmountWithTimer = function(current, instance) {
159
160
function safelyCallComponentWillUnmount (
160
161
current : Fiber ,
161
162
instance : any ,
162
- nearestMountedAncestor : Fiber ,
163
+ nearestMountedAncestor : Fiber | null ,
163
164
) {
164
165
if ( __DEV__ ) {
165
166
invokeGuardedCallback (
@@ -318,7 +319,7 @@ function commitBeforeMutationLifeCycles(
318
319
}
319
320
320
321
function commitHookEffectListUnmount (
321
- tag : HookFlags ,
322
+ flags : HookFlags ,
322
323
finishedWork : Fiber ,
323
324
nearestMountedAncestor : Fiber | null ,
324
325
) {
@@ -328,7 +329,7 @@ function commitHookEffectListUnmount(
328
329
const firstEffect = lastEffect . next ;
329
330
let effect = firstEffect ;
330
331
do {
331
- if ( ( effect . tag & tag ) === tag ) {
332
+ if ( ( effect . tag & flags ) === flags ) {
332
333
// Unmount
333
334
const destroy = effect . destroy ;
334
335
effect . destroy = undefined ;
@@ -341,14 +342,14 @@ function commitHookEffectListUnmount(
341
342
}
342
343
}
343
344
344
- function commitHookEffectListMount ( tag : HookFlags , finishedWork : Fiber ) {
345
+ function commitHookEffectListMount ( flags : HookFlags , finishedWork : Fiber ) {
345
346
const updateQueue : FunctionComponentUpdateQueue | null = ( finishedWork . updateQueue : any ) ;
346
347
const lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
347
348
if ( lastEffect !== null ) {
348
349
const firstEffect = lastEffect . next ;
349
350
let effect = firstEffect ;
350
351
do {
351
- if ( ( effect . tag & tag ) === tag ) {
352
+ if ( ( effect . tag & flags ) === flags ) {
352
353
// Mount
353
354
const create = effect . create ;
354
355
effect . destroy = create ( ) ;
@@ -1884,6 +1885,131 @@ function commitPassiveMount(
1884
1885
}
1885
1886
}
1886
1887
1888
+ function invokeLayoutEffectMountInDEV ( fiber : Fiber ) : void {
1889
+ if ( __DEV__ && enableDoubleInvokingEffects ) {
1890
+ switch ( fiber . tag ) {
1891
+ case FunctionComponent :
1892
+ case ForwardRef :
1893
+ case SimpleMemoComponent :
1894
+ case Block : {
1895
+ invokeGuardedCallback (
1896
+ null ,
1897
+ commitHookEffectListMount ,
1898
+ null ,
1899
+ HookLayout | HookHasEffect ,
1900
+ fiber ,
1901
+ ) ;
1902
+ if ( hasCaughtError ( ) ) {
1903
+ const mountError = clearCaughtError ( ) ;
1904
+ captureCommitPhaseError ( fiber , fiber . return , mountError ) ;
1905
+ }
1906
+ break ;
1907
+ }
1908
+ case ClassComponent : {
1909
+ const instance = fiber . stateNode ;
1910
+ invokeGuardedCallback ( null , instance . componentDidMount , null ) ;
1911
+ if ( hasCaughtError ( ) ) {
1912
+ const mountError = clearCaughtError ( ) ;
1913
+ captureCommitPhaseError ( fiber , fiber . return , mountError ) ;
1914
+ }
1915
+ break ;
1916
+ }
1917
+ }
1918
+ }
1919
+ }
1920
+
1921
+ function invokePassiveEffectMountInDEV ( fiber : Fiber ) : void {
1922
+ if ( __DEV__ && enableDoubleInvokingEffects ) {
1923
+ switch ( fiber . tag ) {
1924
+ case FunctionComponent :
1925
+ case ForwardRef :
1926
+ case SimpleMemoComponent :
1927
+ case Block : {
1928
+ invokeGuardedCallback (
1929
+ null ,
1930
+ commitHookEffectListMount ,
1931
+ null ,
1932
+ HookPassive | HookHasEffect ,
1933
+ fiber ,
1934
+ ) ;
1935
+ if ( hasCaughtError ( ) ) {
1936
+ const mountError = clearCaughtError ( ) ;
1937
+ captureCommitPhaseError ( fiber , fiber . return , mountError ) ;
1938
+ }
1939
+ break ;
1940
+ }
1941
+ }
1942
+ }
1943
+ }
1944
+
1945
+ function invokeLayoutEffectUnmountInDEV ( fiber : Fiber ) : void {
1946
+ if ( __DEV__ && enableDoubleInvokingEffects ) {
1947
+ switch ( fiber . tag ) {
1948
+ case FunctionComponent :
1949
+ case ForwardRef :
1950
+ case SimpleMemoComponent :
1951
+ case Block : {
1952
+ invokeGuardedCallback (
1953
+ null ,
1954
+ commitHookEffectListUnmount ,
1955
+ null ,
1956
+ HookLayout | HookHasEffect ,
1957
+ fiber ,
1958
+ fiber . return ,
1959
+ ) ;
1960
+ if ( hasCaughtError ( ) ) {
1961
+ const unmountError = clearCaughtError ( ) ;
1962
+ captureCommitPhaseError ( fiber , fiber . return , unmountError ) ;
1963
+ }
1964
+ break ;
1965
+ }
1966
+ case ClassComponent : {
1967
+ const instance = fiber . stateNode ;
1968
+ if ( typeof instance . componentWillUnmount === 'function' ) {
1969
+ invokeGuardedCallback (
1970
+ null ,
1971
+ safelyCallComponentWillUnmount ,
1972
+ null ,
1973
+ fiber ,
1974
+ instance ,
1975
+ fiber . return ,
1976
+ ) ;
1977
+ if ( hasCaughtError ( ) ) {
1978
+ const unmountError = clearCaughtError ( ) ;
1979
+ captureCommitPhaseError ( fiber , fiber . return , unmountError ) ;
1980
+ }
1981
+ }
1982
+ break ;
1983
+ }
1984
+ }
1985
+ }
1986
+ }
1987
+
1988
+ function invokePassiveEffectUnmountInDEV ( fiber : Fiber ) : void {
1989
+ if ( __DEV__ && enableDoubleInvokingEffects ) {
1990
+ switch ( fiber . tag ) {
1991
+ case FunctionComponent :
1992
+ case ForwardRef :
1993
+ case SimpleMemoComponent :
1994
+ case Block : {
1995
+ invokeGuardedCallback (
1996
+ null ,
1997
+ commitHookEffectListUnmount ,
1998
+ null ,
1999
+ HookPassive | HookHasEffect ,
2000
+ fiber ,
2001
+ fiber . return ,
2002
+ ) ;
2003
+ if ( hasCaughtError ( ) ) {
2004
+ const unmountError = clearCaughtError ( ) ;
2005
+ captureCommitPhaseError ( fiber , fiber . return , unmountError ) ;
2006
+ }
2007
+ break ;
2008
+ }
2009
+ }
2010
+ }
2011
+ }
2012
+
1887
2013
export {
1888
2014
commitBeforeMutationLifeCycles ,
1889
2015
commitResetTextContent ,
@@ -1896,4 +2022,8 @@ export {
1896
2022
commitPassiveUnmount ,
1897
2023
commitPassiveUnmountInsideDeletedTree ,
1898
2024
commitPassiveMount ,
2025
+ invokeLayoutEffectMountInDEV ,
2026
+ invokeLayoutEffectUnmountInDEV ,
2027
+ invokePassiveEffectMountInDEV ,
2028
+ invokePassiveEffectUnmountInDEV ,
1899
2029
} ;
0 commit comments