@@ -83,6 +83,7 @@ import {
83
83
supportsMicrotasks ,
84
84
errorHydratingContainer ,
85
85
scheduleMicrotask ,
86
+ requestPostPaintCallback ,
86
87
} from './ReactFiberHostConfig' ;
87
88
88
89
import {
@@ -360,6 +361,7 @@ export function getWorkInProgressTransitions() {
360
361
}
361
362
362
363
let currentPendingTransitionCallbacks : PendingTransitionCallbacks | null = null ;
364
+ let currentEndTime : number | null = null ;
363
365
364
366
export function addTransitionStartCallbackToPendingTransition (
365
367
transition : Transition ,
@@ -2639,6 +2641,26 @@ function commitRootImpl(
2639
2641
markCommitStopped ( ) ;
2640
2642
}
2641
2643
2644
+ // if (enableTransitionTracing) {
2645
+ const prevRootTransitionCallbacks = root . transitionCallbacks ;
2646
+ if ( prevRootTransitionCallbacks !== null ) {
2647
+ requestPostPaintCallback ( endTime => {
2648
+ const prevPendingTransitionCallbacks = currentPendingTransitionCallbacks ;
2649
+ if ( prevPendingTransitionCallbacks !== null ) {
2650
+ scheduleCallback ( IdleSchedulerPriority , ( ) => {
2651
+ processTransitionCallbacks (
2652
+ prevPendingTransitionCallbacks ,
2653
+ endTime ,
2654
+ prevRootTransitionCallbacks ,
2655
+ ) ;
2656
+ } ) ;
2657
+ } else {
2658
+ currentEndTime = endTime ;
2659
+ }
2660
+ } ) ;
2661
+ }
2662
+ // }
2663
+
2642
2664
return null ;
2643
2665
}
2644
2666
@@ -2780,28 +2802,23 @@ function flushPassiveEffectsImpl() {
2780
2802
if ( enableTransitionTracing ) {
2781
2803
const prevPendingTransitionCallbacks = currentPendingTransitionCallbacks ;
2782
2804
const prevRootTransitionCallbacks = root . transitionCallbacks ;
2805
+ const prevEndTime = currentEndTime ;
2783
2806
if (
2784
2807
prevPendingTransitionCallbacks !== null &&
2785
2808
prevRootTransitionCallbacks !== null
2786
2809
) {
2787
- // TODO(luna) Refactor this code into the Host Config
2788
- // TODO(luna) The end time here is not necessarily accurate
2789
- // because passive effects could be called before paint
2790
- // (synchronously) or after paint (normally). We need
2791
- // to come up with a way to get the correct end time for both cases.
2792
- // One solution is in the host config, if the passive effects
2793
- // have not yet been run, make a call to flush the passive effects
2794
- // right after paint.
2795
- const endTime = now ( ) ;
2796
2810
currentPendingTransitionCallbacks = null ;
2797
-
2798
- scheduleCallback ( IdleSchedulerPriority , ( ) =>
2799
- processTransitionCallbacks (
2800
- prevPendingTransitionCallbacks ,
2801
- endTime ,
2802
- prevRootTransitionCallbacks ,
2803
- ) ,
2804
- ) ;
2811
+ currentEndTime = null ;
2812
+
2813
+ if ( prevEndTime !== null ) {
2814
+ scheduleCallback ( IdleSchedulerPriority , ( ) =>
2815
+ processTransitionCallbacks (
2816
+ prevPendingTransitionCallbacks ,
2817
+ prevEndTime ,
2818
+ prevRootTransitionCallbacks ,
2819
+ ) ,
2820
+ ) ;
2821
+ }
2805
2822
}
2806
2823
}
2807
2824
0 commit comments