File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -3026,6 +3026,12 @@ function updateDeferredValueImpl<T>(
30263026 }
30273027}
30283028
3029+ function releaseAsyncTransition ( ) {
3030+ if ( __DEV__ ) {
3031+ ReactSharedInternals . asyncTransitions -- ;
3032+ }
3033+ }
3034+
30293035function startTransition < S > (
30303036 fiber : Fiber ,
30313037 queue : UpdateQueue < S | Thenable < S > , BasicStateAction < S | Thenable < S >>> ,
@@ -3083,6 +3089,11 @@ function startTransition<S>(
30833089 typeof returnValue . then === 'function'
30843090 ) {
30853091 const thenable = ( ( returnValue : any ) : Thenable < mixed > ) ;
3092+ if ( __DEV__ ) {
3093+ // Keep track of the number of async transitions still running so we can warn.
3094+ ReactSharedInternals. asyncTransitions ++ ;
3095+ thenable . then ( releaseAsyncTransition , releaseAsyncTransition ) ;
3096+ }
30863097 // Create a thenable that resolves to `finishedState` once the async
30873098 // action has completed.
30883099 const thenableForFinishedState = chainThenableValue (
Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ export type SharedStateClient = {
3939 // ReactCurrentActQueue
4040 actQueue : null | Array < RendererTask > ,
4141
42+ // When zero this means we're outside an async startTransition.
43+ asyncTransitions : number ,
44+
4245 // Used to reproduce behavior of `batchedUpdates` in legacy mode.
4346 isBatchingLegacy : boolean ,
4447 didScheduleLegacyUpdate : boolean ,
@@ -75,6 +78,7 @@ if (enableViewTransition) {
7578
7679if ( __DEV__ ) {
7780 ReactSharedInternals . actQueue = null ;
81+ ReactSharedInternals . asyncTransitions = 0 ;
7882 ReactSharedInternals . isBatchingLegacy = false ;
7983 ReactSharedInternals . didScheduleLegacyUpdate = false ;
8084 ReactSharedInternals . didUsePromise = false ;
Original file line number Diff line number Diff line change @@ -37,6 +37,12 @@ export type Transition = {
3737 ...
3838} ;
3939
40+ function releaseAsyncTransition ( ) {
41+ if ( __DEV__ ) {
42+ ReactSharedInternals . asyncTransitions -- ;
43+ }
44+ }
45+
4046export function startTransition (
4147 scope : ( ) = > void ,
4248 options ?: StartTransitionOptions ,
@@ -67,6 +73,11 @@ export function startTransition(
6773 returnValue !== null &&
6874 typeof returnValue . then === 'function'
6975 ) {
76+ if ( __DEV__ ) {
77+ // Keep track of the number of async transitions still running so we can warn.
78+ ReactSharedInternals . asyncTransitions ++ ;
79+ returnValue . then ( releaseAsyncTransition , releaseAsyncTransition ) ;
80+ }
7081 returnValue . then ( noop , reportGlobalError ) ;
7182 }
7283 } catch ( error ) {
Original file line number Diff line number Diff line change @@ -45,6 +45,25 @@ export function addTransitionType(type: string): void {
4545 pendingTransitionTypes = pendingGestureTransitionTypes = [ ] ;
4646 }
4747 } else {
48+ if ( __DEV__ ) {
49+ if (
50+ ReactSharedInternals . T === null &&
51+ ReactSharedInternals . asyncTransitions === 0
52+ ) {
53+ if ( enableGestureTransition ) {
54+ console . error (
55+ 'addTransitionType can only be called inside a `startTransition()` ' +
56+ 'or `startGestureTransition()` callback. ' +
57+ 'It must be associated with a specific Transition.' ,
58+ ) ;
59+ } else {
60+ console . error (
61+ 'addTransitionType can only be called inside a `startTransition()` ' +
62+ 'callback. It must be associated with a specific Transition.' ,
63+ ) ;
64+ }
65+ }
66+ }
4867 // Otherwise we're either inside a synchronous startTransition
4968 // or in the async gap of one, which we track globally.
5069 pendingTransitionTypes = ReactSharedInternals . V ;
You can’t perform that action at this time.
0 commit comments