83
logSuspendedCommitPhase,
84
logCommitPhase,
85
logPaintYieldPhase,
86
+ logStartViewTransitionYieldPhase,
87
+ logAnimatingPhase,
88
logPassiveCommitPhase,
89
logYieldTime,
90
logActionYieldTime,
676
const SUSPENDED_COMMIT = 1;
677
const THROTTLED_COMMIT = 2;
678
679
+type DelayedCommitReason = 0 | 1 | 2 | 3;
680
+const ABORTED_VIEW_TRANSITION_COMMIT = 1;
681
+const DELAYED_PASSIVE_COMMIT = 2;
682
+const ANIMATION_STARTED_COMMIT = 3;
683
+
684
const NO_PENDING_EFFECTS = 0;
685
const PENDING_MUTATION_PHASE = 1;
686
const PENDING_LAYOUT_PHASE = 2;
703
let pendingTransitionTypes: null | TransitionTypes = null;
704
let pendingDidIncludeRenderPhaseUpdate: boolean = false;
705
let pendingSuspendedCommitReason: SuspendedCommitReason = IMMEDIATE_COMMIT; // Profiling-only
706
+let pendingDelayedCommitReason: DelayedCommitReason = IMMEDIATE_COMMIT; // Profiling-only
707
708
// Use these to prevent an infinite loop of nested updates
709
const NESTED_UPDATE_LIMIT = 50;
3444
if (enableProfilerTimer) {
3445
pendingEffectsRenderEndTime = completedRenderEndTime;
3446
pendingSuspendedCommitReason = suspendedCommitReason;
3447
+ pendingDelayedCommitReason = IMMEDIATE_COMMIT;
3448
}
3449
3450
if (enableGestureTransition && isGestureRender(lanes)) {
3504
// event when logging events.
3505
trackSchedulerEvent();
3506
}
3498
- flushPassiveEffects(true);
3507
+ if (pendingDelayedCommitReason === IMMEDIATE_COMMIT) {
3508
+ pendingDelayedCommitReason = DELAYED_PASSIVE_COMMIT;
3509
+ }
3510
+ flushPassiveEffects();
3511
// This render triggered passive effects: release the root cache pool
3512
// *after* passive effects fire to avoid freeing a cache pool that may
3513
// be referenced by a node in the tree (HostRoot, Cache boundary etc)
3748
ReactSharedInternals.T = prevTransition;
3749
}
3750
}
3751
+
3752
+ const completedRenderEndTime = pendingEffectsRenderEndTime;
3753
+ const suspendedCommitReason = pendingSuspendedCommitReason;
3754
+
3755
+ if (enableProfilerTimer && enableComponentPerformanceTrack) {
3756
+ recordCommitEndTime();
3757
+ logCommitPhase(
3758
+ suspendedCommitReason === IMMEDIATE_COMMIT
3759
+ ? completedRenderEndTime
3760
+ : commitStartTime,
3761
+ commitEndTime,
3762
+ commitErrors,
3763
+ pendingDelayedCommitReason === ABORTED_VIEW_TRANSITION_COMMIT,
3764
+ workInProgressUpdateTask,
3765
+ );
3766
+ }
3767
+
3768
pendingEffectsStatus = PENDING_AFTER_MUTATION_PHASE;
3769
}
3770
3777
) {
3778
return;
3779
}
3780
+ if (enableProfilerTimer && enableComponentPerformanceTrack) {
3781
+ // If we didn't skip the after mutation phase, when is means we started an animation.
3782
+ const startedAnimation = pendingEffectsStatus === PENDING_SPAWNED_WORK;
3783
+ if (startedAnimation) {
3784
+ const startViewTransitionStartTime = commitEndTime;
3785
+ // Update the new commitEndTime to when we started the animation.
3786
+ recordCommitEndTime();
3787
+ logStartViewTransitionYieldPhase(
3788
+ startViewTransitionStartTime,
3789
+ commitEndTime,
3790
+ pendingDelayedCommitReason === ABORTED_VIEW_TRANSITION_COMMIT,
3791
+ workInProgressUpdateTask, // TODO: Use a ViewTransition Task.
3792
+ );
3793
+ if (pendingDelayedCommitReason !== ABORTED_VIEW_TRANSITION_COMMIT) {
3794
+ pendingDelayedCommitReason = ANIMATION_STARTED_COMMIT;
3795
+ }
3796
+ }
3797
+ }
3798
+
3799
pendingEffectsStatus = NO_PENDING_EFFECTS;
3800
3801
pendingViewTransition = null; // The view transition has now fully started.
3807
const root = pendingEffectsRoot;
3808
const finishedWork = pendingFinishedWork;
3809
const lanes = pendingEffectsLanes;
3762
- const completedRenderEndTime = pendingEffectsRenderEndTime;
3810
const recoverableErrors = pendingRecoverableErrors;
3811
const didIncludeRenderPhaseUpdate = pendingDidIncludeRenderPhaseUpdate;
3765
- const suspendedCommitReason = pendingSuspendedCommitReason;
3766
-
3767
- if (enableProfilerTimer && enableComponentPerformanceTrack) {
3768
- recordCommitEndTime();
3769
- logCommitPhase(
3770
- suspendedCommitReason === IMMEDIATE_COMMIT
3771
- ? completedRenderEndTime
3772
- : commitStartTime,
3773
- commitEndTime,
3774
- commitErrors,
3775
- workInProgressUpdateTask,
3776
- );
3777
- }
3812
3813
const passiveSubtreeMask =
3814
enableViewTransition && includesOnlyViewTransitionEligibleLanes(lanes)
4175
4176
let didWarnAboutInterruptedViewTransitions = false;
4177
4144
-export function flushPendingEffects(wasDelayedCommit?: boolean): boolean {
4178
+export function flushPendingEffectsDelayed(): boolean {
4179
+ if (pendingDelayedCommitReason === IMMEDIATE_COMMIT) {
4180
+ pendingDelayedCommitReason = DELAYED_PASSIVE_COMMIT;
4181
+ }
4182
+ return flushPendingEffects();
4183
+}
4184
+
4185
+export function flushPendingEffects(): boolean {
4186
// Returns whether passive effects were flushed.
4187
if (enableViewTransition && pendingViewTransition !== null) {
4188
// If we forced a flush before the View Transition full started then we skip it.
4200
}
4201
}
4202
pendingViewTransition = null;
4203
+ pendingDelayedCommitReason = ABORTED_VIEW_TRANSITION_COMMIT;
4204
}
4205
flushGestureMutations();
4206
flushGestureAnimations();
4208
flushLayoutEffects();
4209
// Skip flushAfterMutation if we're forcing this early.
4210
flushSpawnedWork();
4169
- return flushPassiveEffects(wasDelayedCommit);
4211
+ return flushPassiveEffects();
4212
}
4213
4172
-function flushPassiveEffects(wasDelayedCommit?: boolean): boolean {
4214
+function flushPassiveEffects(): boolean {
4215
if (pendingEffectsStatus !== PENDING_PASSIVE_PHASE) {
4216
return false;
4217
}
4236
try {
4237
setCurrentUpdatePriority(priority);
4238
ReactSharedInternals.T = null;
4197
- return flushPassiveEffectsImpl(wasDelayedCommit);
4239
+ return flushPassiveEffectsImpl();
4240
} finally {
4241
setCurrentUpdatePriority(previousPriority);
4242
ReactSharedInternals.T = prevTransition;
4248
}
4249
}
4250
4209
-function flushPassiveEffectsImpl(wasDelayedCommit: void | boolean) {
4251
+function flushPassiveEffectsImpl() {
4252
// Cache and clear the transitions flag
4253
const transitions = pendingPassiveTransitions;
4254
pendingPassiveTransitions = null;
4288
if (enableProfilerTimer && enableComponentPerformanceTrack) {
4289
resetCommitErrors();
4290
passiveEffectStartTime = now();
4249
- logPaintYieldPhase(
4250
- commitEndTime,
4251
- passiveEffectStartTime,
4252
- !!wasDelayedCommit,
4253
- workInProgressUpdateTask,
4254
- );
4291
+ if (pendingDelayedCommitReason === ANIMATION_STARTED_COMMIT) {
4292
+ // The animation was started, so we've been animating since that happened.
4293
+ logAnimatingPhase(
4294
+ commitEndTime,
4295
+ passiveEffectStartTime,
4296
+ workInProgressUpdateTask, // TODO: Use a ViewTransition Task
4297
+ );
4298
+ } else {
4299
+ logPaintYieldPhase(
4300
+ commitEndTime,
4301
+ passiveEffectStartTime,
4302
+ pendingDelayedCommitReason === DELAYED_PASSIVE_COMMIT,
4303
+ workInProgressUpdateTask,
4304
+ );
4305
+ }
4306
}
4307
4308
if (enableSchedulingProfiler) {