@@ -12,6 +12,7 @@ import type {
12
12
MutableSourceGetSnapshotFn ,
13
13
MutableSourceSubscribeFn ,
14
14
ReactContext ,
15
+ StartTransitionOptions ,
15
16
} from 'shared/ReactTypes' ;
16
17
import type { Fiber , Dispatcher , HookType } from './ReactInternalTypes' ;
17
18
import type { Lanes , Lane } from './ReactFiberLane.new' ;
@@ -31,6 +32,7 @@ import {
31
32
enableLazyContextPropagation ,
32
33
enableSuspenseLayoutEffectSemantics ,
33
34
enableUseMutableSource ,
35
+ enableTransitionTracing ,
34
36
} from 'shared/ReactFeatureFlags' ;
35
37
36
38
import {
@@ -111,6 +113,7 @@ import {
111
113
import { pushInterleavedQueue } from './ReactFiberInterleavedUpdates.new' ;
112
114
import { warnOnSubscriptionInsideStartTransition } from 'shared/ReactFeatureFlags' ;
113
115
import { getTreeId } from './ReactFiberTreeContext.new' ;
116
+ import { getCurrentEventStartTime } from './ReactFiberHostConfig' ;
114
117
115
118
const { ReactCurrentDispatcher, ReactCurrentBatchConfig} = ReactSharedInternals ;
116
119
@@ -1929,10 +1932,21 @@ function mountDeferredValue<T>(value: T): T {
1929
1932
mountEffect ( ( ) => {
1930
1933
const prevTransition = ReactCurrentBatchConfig . transition ;
1931
1934
ReactCurrentBatchConfig . transition = 1 ;
1935
+
1936
+ let prevTransitionInfo = null ;
1937
+ if ( enableTransitionTracing ) {
1938
+ prevTransitionInfo = ReactCurrentBatchConfig . transitionInfo ;
1939
+ ReactCurrentBatchConfig . transitionInfo = null ;
1940
+ }
1941
+
1932
1942
try {
1933
1943
setValue ( value ) ;
1934
1944
} finally {
1935
1945
ReactCurrentBatchConfig . transition = prevTransition ;
1946
+
1947
+ if ( enableTransitionTracing ) {
1948
+ ReactCurrentBatchConfig . transitionInfo = prevTransitionInfo ;
1949
+ }
1936
1950
}
1937
1951
} , [ value ] ) ;
1938
1952
return prevValue ;
@@ -1943,10 +1957,21 @@ function updateDeferredValue<T>(value: T): T {
1943
1957
updateEffect ( ( ) => {
1944
1958
const prevTransition = ReactCurrentBatchConfig . transition ;
1945
1959
ReactCurrentBatchConfig . transition = 1 ;
1960
+
1961
+ let prevTransitionInfo = null ;
1962
+ if ( enableTransitionTracing ) {
1963
+ prevTransitionInfo = ReactCurrentBatchConfig . transitionInfo ;
1964
+ ReactCurrentBatchConfig . transitionInfo = null ;
1965
+ }
1966
+
1946
1967
try {
1947
1968
setValue ( value ) ;
1948
1969
} finally {
1949
1970
ReactCurrentBatchConfig . transition = prevTransition ;
1971
+
1972
+ if ( enableTransitionTracing ) {
1973
+ ReactCurrentBatchConfig . transitionInfo = prevTransitionInfo ;
1974
+ }
1950
1975
}
1951
1976
} , [ value ] ) ;
1952
1977
return prevValue ;
@@ -1957,16 +1982,27 @@ function rerenderDeferredValue<T>(value: T): T {
1957
1982
updateEffect ( ( ) => {
1958
1983
const prevTransition = ReactCurrentBatchConfig . transition ;
1959
1984
ReactCurrentBatchConfig . transition = 1 ;
1985
+
1986
+ let prevTransitionInfo = null ;
1987
+ if ( enableTransitionTracing ) {
1988
+ prevTransitionInfo = ReactCurrentBatchConfig . transitionInfo ;
1989
+ ReactCurrentBatchConfig . transitionInfo = null ;
1990
+ }
1991
+
1960
1992
try {
1961
1993
setValue ( value ) ;
1962
1994
} finally {
1963
1995
ReactCurrentBatchConfig . transition = prevTransition ;
1996
+
1997
+ if ( enableTransitionTracing ) {
1998
+ ReactCurrentBatchConfig . transitionInfo = prevTransitionInfo ;
1999
+ }
1964
2000
}
1965
2001
} , [ value ] ) ;
1966
2002
return prevValue ;
1967
2003
}
1968
2004
1969
- function startTransition(setPending, callback) {
2005
+ function startTransition(setPending, callback, options ) {
1970
2006
const previousPriority = getCurrentUpdatePriority ( ) ;
1971
2007
setCurrentUpdatePriority (
1972
2008
higherEventPriority ( previousPriority , ContinuousEventPriority ) ,
@@ -1976,12 +2012,29 @@ function startTransition(setPending, callback) {
1976
2012
1977
2013
const prevTransition = ReactCurrentBatchConfig . transition ;
1978
2014
ReactCurrentBatchConfig . transition = 1 ;
2015
+
2016
+ let prevTransitionInfo = null ;
2017
+ if ( enableTransitionTracing ) {
2018
+ prevTransitionInfo = ReactCurrentBatchConfig . transitionInfo ;
2019
+ if ( options !== undefined && options . name !== undefined ) {
2020
+ ReactCurrentBatchConfig . transitionInfo = {
2021
+ name : options . name ,
2022
+ startTime : getCurrentEventStartTime ( ) ,
2023
+ } ;
2024
+ }
2025
+ }
2026
+
1979
2027
try {
1980
2028
setPending ( false ) ;
1981
2029
callback ( ) ;
1982
2030
} finally {
1983
2031
setCurrentUpdatePriority ( previousPriority ) ;
1984
2032
ReactCurrentBatchConfig . transition = prevTransition ;
2033
+
2034
+ if ( enableTransitionTracing ) {
2035
+ ReactCurrentBatchConfig . transitionInfo = prevTransitionInfo ;
2036
+ }
2037
+
1985
2038
if (__DEV__) {
1986
2039
if (
1987
2040
prevTransition !== 1 &&
@@ -2002,7 +2055,10 @@ function startTransition(setPending, callback) {
2002
2055
}
2003
2056
}
2004
2057
2005
- function mountTransition ( ) : [ boolean , ( ( ) => void ) => void ] {
2058
+ function mountTransition ( ) : [
2059
+ boolean ,
2060
+ ( callback : ( ) => void , options ?: StartTransitionOptions ) => void ,
2061
+ ] {
2006
2062
const [ isPending , setPending ] = mountState ( false ) ;
2007
2063
// The `start` method never changes.
2008
2064
const start = startTransition . bind ( null , setPending ) ;
@@ -2011,14 +2067,20 @@ function mountTransition(): [boolean, (() => void) => void] {
2011
2067
return [ isPending , start ] ;
2012
2068
}
2013
2069
2014
- function updateTransition ( ) : [ boolean , ( ( ) => void ) => void ] {
2070
+ function updateTransition(): [
2071
+ boolean,
2072
+ (callback: () => void , options ?: StartTransitionOptions ) => void ,
2073
+ ] {
2015
2074
const [ isPending ] = updateState ( false ) ;
2016
2075
const hook = updateWorkInProgressHook ( ) ;
2017
2076
const start = hook . memoizedState ;
2018
2077
return [ isPending , start ] ;
2019
2078
}
2020
2079
2021
- function rerenderTransition ( ) : [ boolean , ( ( ) => void ) => void ] {
2080
+ function rerenderTransition(): [
2081
+ boolean,
2082
+ (callback: () => void , options ?: StartTransitionOptions ) => void ,
2083
+ ] {
2022
2084
const [ isPending ] = rerenderState ( false ) ;
2023
2085
const hook = updateWorkInProgressHook ( ) ;
2024
2086
const start = hook . memoizedState ;
0 commit comments