@@ -27,7 +27,6 @@ import type {OffscreenState} from './ReactFiberOffscreenComponent';
2727
2828import { unstable_wrap as Schedule_tracing_wrap } from 'scheduler/tracing' ;
2929import {
30- deferPassiveEffectCleanupDuringUnmount ,
3130 enableSchedulerTracing ,
3231 enableProfilerTimer ,
3332 enableProfilerCommitHooks ,
@@ -36,7 +35,6 @@ import {
3635 enableFundamentalAPI ,
3736 enableSuspenseCallback ,
3837 enableScopeAPI ,
39- runAllPassiveEffectDestroysBeforeCreates ,
4038 enableCreateEventHandleAPI ,
4139} from 'shared/ReactFeatureFlags' ;
4240import {
@@ -71,7 +69,6 @@ import {
7169 Placement ,
7270 Snapshot ,
7371 Update ,
74- Passive ,
7572} from './ReactSideEffectTags' ;
7673import getComponentName from 'shared/getComponentName' ;
7774import invariant from 'shared/invariant' ;
@@ -81,9 +78,7 @@ import {resolveDefaultProps} from './ReactFiberLazyComponent.new';
8178import {
8279 getCommitTime ,
8380 recordLayoutEffectDuration ,
84- recordPassiveEffectDuration ,
8581 startLayoutEffectTimer ,
86- startPassiveEffectTimer ,
8782} from './ReactProfilerTimer.new' ;
8883import { ProfileMode } from './ReactTypeOfMode' ;
8984import { commitUpdateQueue } from './ReactUpdateQueue.new' ;
@@ -134,10 +129,6 @@ import {
134129 Passive as HookPassive ,
135130} from './ReactHookEffectTags' ;
136131import { didWarnAboutReassigningProps } from './ReactFiberBeginWork.new' ;
137- import {
138- runWithPriority ,
139- NormalPriority ,
140- } from './SchedulerWithReactIntegration.new' ;
141132import {
142133 updateDeprecatedEventListeners ,
143134 unmountDeprecatedResponderListeners ,
@@ -394,67 +385,22 @@ function commitHookEffectListMount(tag: number, finishedWork: Fiber) {
394385}
395386
396387function schedulePassiveEffects ( finishedWork : Fiber ) {
397- if ( runAllPassiveEffectDestroysBeforeCreates ) {
398- const updateQueue : FunctionComponentUpdateQueue | null = ( finishedWork . updateQueue : any ) ;
399- const lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
400- if ( lastEffect !== null ) {
401- const firstEffect = lastEffect . next ;
402- let effect = firstEffect ;
403- do {
404- const { next, tag} = effect ;
405- if (
406- ( tag & HookPassive ) !== NoHookEffect &&
407- ( tag & HookHasEffect ) !== NoHookEffect
408- ) {
409- enqueuePendingPassiveHookEffectUnmount ( finishedWork , effect ) ;
410- enqueuePendingPassiveHookEffectMount ( finishedWork , effect ) ;
411- }
412- effect = next ;
413- } while ( effect !== firstEffect ) ;
414- }
415- }
416- }
417-
418- export function commitPassiveHookEffects ( finishedWork : Fiber ) : void {
419- if ( ( finishedWork . effectTag & Passive ) !== NoEffect ) {
420- switch ( finishedWork . tag ) {
421- case FunctionComponent :
422- case ForwardRef :
423- case SimpleMemoComponent :
424- case Block : {
425- // TODO (#17945) We should call all passive destroy functions (for all fibers)
426- // before calling any create functions. The current approach only serializes
427- // these for a single fiber.
428- if (
429- enableProfilerTimer &&
430- enableProfilerCommitHooks &&
431- finishedWork . mode & ProfileMode
432- ) {
433- try {
434- startPassiveEffectTimer ( ) ;
435- commitHookEffectListUnmount (
436- HookPassive | HookHasEffect ,
437- finishedWork ,
438- ) ;
439- commitHookEffectListMount (
440- HookPassive | HookHasEffect ,
441- finishedWork ,
442- ) ;
443- } finally {
444- recordPassiveEffectDuration ( finishedWork ) ;
445- }
446- } else {
447- commitHookEffectListUnmount (
448- HookPassive | HookHasEffect ,
449- finishedWork ,
450- ) ;
451- commitHookEffectListMount ( HookPassive | HookHasEffect , finishedWork ) ;
452- }
453- break ;
388+ const updateQueue : FunctionComponentUpdateQueue | null = ( finishedWork . updateQueue : any ) ;
389+ const lastEffect = updateQueue !== null ? updateQueue . lastEffect : null ;
390+ if ( lastEffect !== null ) {
391+ const firstEffect = lastEffect . next ;
392+ let effect = firstEffect ;
393+ do {
394+ const { next, tag} = effect ;
395+ if (
396+ ( tag & HookPassive ) !== NoHookEffect &&
397+ ( tag & HookHasEffect ) !== NoHookEffect
398+ ) {
399+ enqueuePendingPassiveHookEffectUnmount ( finishedWork , effect ) ;
400+ enqueuePendingPassiveHookEffectMount ( finishedWork , effect ) ;
454401 }
455- default :
456- break ;
457- }
402+ effect = next ;
403+ } while ( effect !== firstEffect ) ;
458404 }
459405}
460406
@@ -543,9 +489,7 @@ function commitLifeCycles(
543489 commitHookEffectListMount ( HookLayout | HookHasEffect , finishedWork ) ;
544490 }
545491
546- if ( runAllPassiveEffectDestroysBeforeCreates ) {
547- schedulePassiveEffects ( finishedWork ) ;
548- }
492+ schedulePassiveEffects ( finishedWork ) ;
549493 return ;
550494 }
551495 case ClassComponent : {
@@ -946,74 +890,28 @@ function commitUnmount(
946890 if ( lastEffect !== null ) {
947891 const firstEffect = lastEffect . next ;
948892
949- if (
950- deferPassiveEffectCleanupDuringUnmount &&
951- runAllPassiveEffectDestroysBeforeCreates
952- ) {
953- let effect = firstEffect ;
954- do {
955- const { destroy, tag} = effect ;
956- if ( destroy !== undefined ) {
957- if ( ( tag & HookPassive ) !== NoHookEffect ) {
958- enqueuePendingPassiveHookEffectUnmount ( current , effect ) ;
893+ let effect = firstEffect ;
894+ do {
895+ const { destroy, tag} = effect ;
896+ if ( destroy !== undefined ) {
897+ if ( ( tag & HookPassive ) !== NoHookEffect ) {
898+ enqueuePendingPassiveHookEffectUnmount ( current , effect ) ;
899+ } else {
900+ if (
901+ enableProfilerTimer &&
902+ enableProfilerCommitHooks &&
903+ current . mode & ProfileMode
904+ ) {
905+ startLayoutEffectTimer ( ) ;
906+ safelyCallDestroy ( current , destroy ) ;
907+ recordLayoutEffectDuration ( current ) ;
959908 } else {
960- if (
961- enableProfilerTimer &&
962- enableProfilerCommitHooks &&
963- current . mode & ProfileMode
964- ) {
965- startLayoutEffectTimer ( ) ;
966- safelyCallDestroy ( current , destroy ) ;
967- recordLayoutEffectDuration ( current ) ;
968- } else {
969- safelyCallDestroy ( current , destroy ) ;
970- }
909+ safelyCallDestroy ( current , destroy ) ;
971910 }
972911 }
973- effect = effect . next ;
974- } while ( effect !== firstEffect ) ;
975- } else {
976- // When the owner fiber is deleted, the destroy function of a passive
977- // effect hook is called during the synchronous commit phase. This is
978- // a concession to implementation complexity. Calling it in the
979- // passive effect phase (like they usually are, when dependencies
980- // change during an update) would require either traversing the
981- // children of the deleted fiber again, or including unmount effects
982- // as part of the fiber effect list.
983- //
984- // Because this is during the sync commit phase, we need to change
985- // the priority.
986- //
987- // TODO: Reconsider this implementation trade off.
988- const priorityLevel =
989- renderPriorityLevel > NormalPriority
990- ? NormalPriority
991- : renderPriorityLevel ;
992- runWithPriority ( priorityLevel , ( ) => {
993- let effect = firstEffect ;
994- do {
995- const { destroy, tag} = effect ;
996- if ( destroy !== undefined ) {
997- if (
998- enableProfilerTimer &&
999- enableProfilerCommitHooks &&
1000- current . mode & ProfileMode
1001- ) {
1002- if ( ( tag & HookPassive ) !== NoHookEffect ) {
1003- safelyCallDestroy ( current , destroy ) ;
1004- } else {
1005- startLayoutEffectTimer ( ) ;
1006- safelyCallDestroy ( current , destroy ) ;
1007- recordLayoutEffectDuration ( current ) ;
1008- }
1009- } else {
1010- safelyCallDestroy ( current , destroy ) ;
1011- }
1012- }
1013- effect = effect . next ;
1014- } while ( effect !== firstEffect ) ;
1015- } ) ;
1016- }
912+ }
913+ effect = effect . next ;
914+ } while ( effect !== firstEffect ) ;
1017915 }
1018916 }
1019917 return ;
0 commit comments