@@ -47,6 +47,7 @@ import type {ViewTransitionState} from './ReactFiberViewTransitionComponent';
4747import {
4848 alwaysThrottleRetries ,
4949 enableCreateEventHandleAPI ,
50+ enableEffectEventMutationPhase ,
5051 enableHiddenSubtreeInsertionEffectCleanup ,
5152 enableProfilerTimer ,
5253 enableProfilerCommitHooks ,
@@ -499,7 +500,7 @@ function commitBeforeMutationEffectsOnFiber(
499500 case FunctionComponent :
500501 case ForwardRef :
501502 case SimpleMemoComponent : {
502- if ( ( flags & Update ) !== NoFlags ) {
503+ if ( ! enableEffectEventMutationPhase && ( flags & Update ) !== NoFlags ) {
503504 const updateQueue : FunctionComponentUpdateQueue | null =
504505 ( finishedWork . updateQueue : any ) ;
505506 const eventPayloads = updateQueue !== null ? updateQueue . events : null ;
@@ -2042,6 +2043,24 @@ function commitMutationEffectsOnFiber(
20422043 case ForwardRef :
20432044 case MemoComponent :
20442045 case SimpleMemoComponent : {
2046+ // Mutate event effect callbacks on the way down, before mutation effects.
2047+ // This ensures that parent event effects are mutated before child effects.
2048+ // This isn't a supported use case, so we can re-consider it,
2049+ // but this was the behavior we originally shipped.
2050+ if ( enableEffectEventMutationPhase ) {
2051+ if ( flags & Update ) {
2052+ const updateQueue : FunctionComponentUpdateQueue | null =
2053+ ( finishedWork . updateQueue : any ) ;
2054+ const eventPayloads =
2055+ updateQueue !== null ? updateQueue . events : null ;
2056+ if ( eventPayloads !== null ) {
2057+ for ( let ii = 0 ; ii < eventPayloads . length ; ii ++ ) {
2058+ const { ref, nextImpl} = eventPayloads [ ii ] ;
2059+ ref . impl = nextImpl ;
2060+ }
2061+ }
2062+ }
2063+ }
20452064 recursivelyTraverseMutationEffects ( root , finishedWork , lanes ) ;
20462065 commitReconciliationEffects ( finishedWork , lanes ) ;
20472066
0 commit comments