@@ -12,44 +12,24 @@ import {
12
12
enableViewTransition ,
13
13
enableGestureTransition ,
14
14
} from 'shared/ReactFeatureFlags' ;
15
+ import { startTransition } from './ReactStartTransition' ;
15
16
16
17
export type TransitionTypes = Array < string > ;
17
18
18
- // This one is only available synchronously so we don't need to use ReactSharedInternals
19
- // for this state. Instead, we track it in isomorphic and pass it to the renderer.
20
- export let pendingGestureTransitionTypes : null | TransitionTypes = null ;
21
-
22
- export function pushPendingGestureTransitionTypes ( ) : null | TransitionTypes {
23
- const prev = pendingGestureTransitionTypes ;
24
- pendingGestureTransitionTypes = null ;
25
- return prev ;
26
- }
27
-
28
- export function popPendingGestureTransitionTypes (
29
- prev : null | TransitionTypes ,
30
- ) : void {
31
- pendingGestureTransitionTypes = prev ;
32
- }
33
-
34
19
export function addTransitionType ( type : string ) : void {
35
20
if ( enableViewTransition ) {
36
- let pendingTransitionTypes : null | TransitionTypes ;
37
- if (
38
- enableGestureTransition &&
39
- ReactSharedInternals . T !== null &&
40
- ReactSharedInternals . T . gesture !== null
41
- ) {
42
- // We're inside a startGestureTransition which is always sync.
43
- pendingTransitionTypes = pendingGestureTransitionTypes ;
44
- if ( pendingTransitionTypes === null ) {
45
- pendingTransitionTypes = pendingGestureTransitionTypes = [ ] ;
21
+ const transition = ReactSharedInternals . T ;
22
+ if ( transition !== null ) {
23
+ const transitionTypes = transition . types ;
24
+ if ( transitionTypes === null ) {
25
+ transition . types = [ type ] ;
26
+ } else if ( transitionTypes . indexOf ( type ) === - 1 ) {
27
+ transitionTypes . push ( type ) ;
46
28
}
47
29
} else {
30
+ // We're in the async gap. Simulate an implicit startTransition around it.
48
31
if ( __DEV__ ) {
49
- if (
50
- ReactSharedInternals . T === null &&
51
- ReactSharedInternals . asyncTransitions === 0
52
- ) {
32
+ if ( ReactSharedInternals . asyncTransitions === 0 ) {
53
33
if ( enableGestureTransition ) {
54
34
console . error (
55
35
'addTransitionType can only be called inside a `startTransition()` ' +
@@ -64,15 +44,7 @@ export function addTransitionType(type: string): void {
64
44
}
65
45
}
66
46
}
67
- // Otherwise we're either inside a synchronous startTransition
68
- // or in the async gap of one, which we track globally.
69
- pendingTransitionTypes = ReactSharedInternals . V ;
70
- if ( pendingTransitionTypes === null ) {
71
- pendingTransitionTypes = ReactSharedInternals . V = [ ] ;
72
- }
73
- }
74
- if ( pendingTransitionTypes . indexOf ( type ) === - 1 ) {
75
- pendingTransitionTypes . push ( type ) ;
47
+ startTransition ( addTransitionType . bind ( null , type ) ) ;
76
48
}
77
49
}
78
50
}
0 commit comments