@@ -20,10 +20,7 @@ import type {FiberRoot} from './ReactInternalTypes';
2020import type { Lanes } from './ReactFiberLane' ;
2121import type { SuspenseState } from './ReactFiberSuspenseComponent.new' ;
2222import type { UpdateQueue } from './ReactUpdateQueue.new' ;
23- import type {
24- Effect as HookEffect ,
25- FunctionComponentUpdateQueue ,
26- } from './ReactFiberHooks.new' ;
23+ import type { FunctionComponentUpdateQueue } from './ReactFiberHooks.new' ;
2724import type { Wakeable } from 'shared/ReactTypes' ;
2825import type { ReactPriorityLevel } from './ReactInternalTypes' ;
2926import type { OffscreenState } from './ReactFiberOffscreenComponent' ;
@@ -343,42 +340,6 @@ function commitHookEffectListUnmount(
343340 }
344341}
345342
346- // TODO: Remove this duplication.
347- function commitHookEffectListUnmount2 (
348- // Tags to check for when deciding whether to unmount. e.g. to skip over layout effects
349- hookFlags : HookFlags ,
350- fiber : Fiber ,
351- nearestMountedAncestor : Fiber | null ,
352- ) : void {
353- const updateQueue : FunctionComponentUpdateQueue | null = ( fiber . updateQueue : any ) ;
354- const lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
355- if ( lastEffect !== null ) {
356- const firstEffect = lastEffect . next ;
357- let effect = firstEffect ;
358- do {
359- const { next, tag} = effect ;
360- if ( ( tag & hookFlags ) === hookFlags ) {
361- const destroy = effect . destroy ;
362- if ( destroy !== undefined ) {
363- effect . destroy = undefined ;
364- if (
365- enableProfilerTimer &&
366- enableProfilerCommitHooks &&
367- fiber . mode & ProfileMode
368- ) {
369- startPassiveEffectTimer ( ) ;
370- safelyCallDestroy ( fiber , nearestMountedAncestor , destroy ) ;
371- recordPassiveEffectDuration ( fiber ) ;
372- } else {
373- safelyCallDestroy ( fiber , nearestMountedAncestor , destroy ) ;
374- }
375- }
376- }
377- effect = next ;
378- } while ( effect !== firstEffect ) ;
379- }
380- }
381-
382343function commitHookEffectListMount ( tag : HookFlags , finishedWork : Fiber ) {
383344 const updateQueue : FunctionComponentUpdateQueue | null = ( finishedWork . updateQueue : any ) ;
384345 const lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
@@ -429,83 +390,6 @@ function commitHookEffectListMount(tag: HookFlags, finishedWork: Fiber) {
429390 }
430391}
431392
432- function invokePassiveEffectCreate ( effect : HookEffect ) : void {
433- const create = effect . create ;
434- effect . destroy = create ( ) ;
435- }
436-
437- // TODO: Remove this duplication.
438- function commitHookEffectListMount2 ( fiber : Fiber ) : void {
439- const updateQueue : FunctionComponentUpdateQueue | null = ( fiber . updateQueue : any ) ;
440- const lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
441- if ( lastEffect !== null ) {
442- const firstEffect = lastEffect . next ;
443- let effect = firstEffect ;
444- do {
445- const { next, tag} = effect ;
446-
447- if (
448- ( tag & HookPassive ) !== NoHookEffect &&
449- ( tag & HookHasEffect ) !== NoHookEffect
450- ) {
451- if ( __DEV__ ) {
452- if (
453- enableProfilerTimer &&
454- enableProfilerCommitHooks &&
455- fiber . mode & ProfileMode
456- ) {
457- startPassiveEffectTimer ( ) ;
458- invokeGuardedCallback (
459- null ,
460- invokePassiveEffectCreate ,
461- null ,
462- effect ,
463- ) ;
464- recordPassiveEffectDuration ( fiber ) ;
465- } else {
466- invokeGuardedCallback (
467- null ,
468- invokePassiveEffectCreate ,
469- null ,
470- effect ,
471- ) ;
472- }
473- if ( hasCaughtError ( ) ) {
474- invariant ( fiber !== null , 'Should be working on an effect.' ) ;
475- const error = clearCaughtError ( ) ;
476- captureCommitPhaseError ( fiber , fiber . return , error ) ;
477- }
478- } else {
479- try {
480- const create = effect . create ;
481- if (
482- enableProfilerTimer &&
483- enableProfilerCommitHooks &&
484- fiber . mode & ProfileMode
485- ) {
486- try {
487- startPassiveEffectTimer ( ) ;
488- effect . destroy = create ( ) ;
489- } finally {
490- recordPassiveEffectDuration ( fiber ) ;
491- }
492- } else {
493- effect . destroy = create ( ) ;
494- }
495- // TODO: This is missing the warning that exists in commitHookEffectListMount.
496- // The warning refers to useEffect but only applies to useLayoutEffect.
497- } catch ( error ) {
498- invariant ( fiber !== null , 'Should be working on an effect.' ) ;
499- captureCommitPhaseError ( fiber , fiber . return , error ) ;
500- }
501- }
502- }
503-
504- effect = next ;
505- } while ( effect !== firstEffect ) ;
506- }
507- }
508-
509393function commitProfilerPassiveEffect (
510394 finishedRoot : FiberRoot ,
511395 finishedWork : Fiber ,
@@ -1894,17 +1778,31 @@ function commitResetTextContent(current: Fiber): void {
18941778 resetTextContent ( current . stateNode ) ;
18951779}
18961780
1897- function commitPassiveWork ( finishedWork : Fiber ) : void {
1781+ function commitPassiveUnmountInsideDeletedTree ( finishedWork : Fiber ) : void {
18981782 switch ( finishedWork . tag ) {
18991783 case FunctionComponent :
19001784 case ForwardRef :
19011785 case SimpleMemoComponent :
19021786 case Block : {
1903- commitHookEffectListUnmount2 (
1904- HookPassive | HookHasEffect ,
1905- finishedWork ,
1906- finishedWork . return ,
1907- ) ;
1787+ if (
1788+ enableProfilerTimer &&
1789+ enableProfilerCommitHooks &&
1790+ finishedWork . mode & ProfileMode
1791+ ) {
1792+ startPassiveEffectTimer ( ) ;
1793+ commitHookEffectListUnmount (
1794+ HookPassive | HookHasEffect ,
1795+ finishedWork ,
1796+ finishedWork . return ,
1797+ ) ;
1798+ recordPassiveEffectDuration ( finishedWork ) ;
1799+ } else {
1800+ commitHookEffectListUnmount (
1801+ HookPassive | HookHasEffect ,
1802+ finishedWork ,
1803+ finishedWork . return ,
1804+ ) ;
1805+ }
19081806 break ;
19091807 }
19101808 }
@@ -1918,16 +1816,32 @@ function commitPassiveUnmount(
19181816 case FunctionComponent :
19191817 case ForwardRef :
19201818 case SimpleMemoComponent :
1921- case Block :
1922- commitHookEffectListUnmount2 (
1923- HookPassive ,
1924- current ,
1925- nearestMountedAncestor ,
1926- ) ;
1819+ case Block : {
1820+ if (
1821+ enableProfilerTimer &&
1822+ enableProfilerCommitHooks &&
1823+ current . mode & ProfileMode
1824+ ) {
1825+ startPassiveEffectTimer ( ) ;
1826+ commitHookEffectListUnmount (
1827+ HookPassive ,
1828+ current ,
1829+ nearestMountedAncestor ,
1830+ ) ;
1831+ recordPassiveEffectDuration ( current ) ;
1832+ } else {
1833+ commitHookEffectListUnmount (
1834+ HookPassive ,
1835+ current ,
1836+ nearestMountedAncestor ,
1837+ ) ;
1838+ }
1839+ break ;
1840+ }
19271841 }
19281842}
19291843
1930- function commitPassiveLifeCycles (
1844+ function commitPassiveMount (
19311845 finishedRoot : FiberRoot ,
19321846 finishedWork : Fiber ,
19331847) : void {
@@ -1936,7 +1850,20 @@ function commitPassiveLifeCycles(
19361850 case ForwardRef :
19371851 case SimpleMemoComponent :
19381852 case Block : {
1939- commitHookEffectListMount2 ( finishedWork ) ;
1853+ if (
1854+ enableProfilerTimer &&
1855+ enableProfilerCommitHooks &&
1856+ finishedWork . mode & ProfileMode
1857+ ) {
1858+ startPassiveEffectTimer ( ) ;
1859+ try {
1860+ commitHookEffectListMount ( HookPassive | HookHasEffect , finishedWork ) ;
1861+ } finally {
1862+ recordPassiveEffectDuration ( finishedWork ) ;
1863+ }
1864+ } else {
1865+ commitHookEffectListMount ( HookPassive | HookHasEffect , finishedWork ) ;
1866+ }
19401867 break ;
19411868 }
19421869 case Profiler : {
@@ -1956,6 +1883,6 @@ export {
19561883 commitAttachRef ,
19571884 commitDetachRef ,
19581885 commitPassiveUnmount ,
1959- commitPassiveWork ,
1960- commitPassiveLifeCycles ,
1886+ commitPassiveUnmountInsideDeletedTree ,
1887+ commitPassiveMount ,
19611888} ;
0 commit comments