@@ -20,6 +20,7 @@ import {
2020 enableComponentPerformanceTrack ,
2121 enableYieldingBeforePassive ,
2222 enableGestureTransition ,
23+ enableDefaultTransitionIndicator ,
2324} from 'shared/ReactFeatureFlags' ;
2425import {
2526 NoLane ,
@@ -80,6 +81,9 @@ import {
8081} from './ReactProfilerTimer' ;
8182import { peekEntangledActionLane } from './ReactFiberAsyncAction' ;
8283
84+ import noop from 'shared/noop' ;
85+ import reportGlobalError from 'shared/reportGlobalError' ;
86+
8387// A linked list of all the roots with pending work. In an idiomatic app,
8488// there's only a single root, but we do support multi root apps, hence this
8589// extra complexity. But this module is optimized for the single root case.
@@ -316,8 +320,33 @@ function processRootScheduleInMicrotask() {
316320 flushSyncWorkAcrossRoots_impl ( syncTransitionLanes , false ) ;
317321 }
318322
319- // Reset Event Transition Lane so that we allocate a new one next time.
320- currentEventTransitionLane = NoLane ;
323+ if ( currentEventTransitionLane !== NoLane ) {
324+ // Reset Event Transition Lane so that we allocate a new one next time.
325+ currentEventTransitionLane = NoLane ;
326+ startDefaultTransitionIndicatorIfNeeded ( ) ;
327+ }
328+ }
329+
330+ function startDefaultTransitionIndicatorIfNeeded ( ) {
331+ if ( ! enableDefaultTransitionIndicator ) {
332+ return ;
333+ }
334+ // Check all the roots if there are any new indicators needed.
335+ let root = firstScheduledRoot ;
336+ while ( root !== null ) {
337+ if ( root . indicatorLanes !== NoLanes && root . pendingIndicator === null ) {
338+ // We have new indicator lanes that requires a loading state. Start the
339+ // default transition indicator.
340+ try {
341+ const onDefaultTransitionIndicator = root . onDefaultTransitionIndicator ;
342+ root . pendingIndicator = onDefaultTransitionIndicator ( ) || noop ;
343+ } catch ( x ) {
344+ root . pendingIndicator = noop ;
345+ reportGlobalError ( x ) ;
346+ }
347+ }
348+ root = root . next ;
349+ }
321350}
322351
323352function scheduleTaskForRootDuringMicrotask (
@@ -664,3 +693,12 @@ export function requestTransitionLane(
664693export function didCurrentEventScheduleTransition ( ) : boolean {
665694 return currentEventTransitionLane !== NoLane ;
666695}
696+
697+ export function markIndicatorHandled ( root : FiberRoot ) : void {
698+ if ( enableDefaultTransitionIndicator ) {
699+ // The current transition event rendered a synchronous loading state.
700+ // Clear it from the indicator lanes. We don't need to show a separate
701+ // loading state for this lane.
702+ root . indicatorLanes &= ~ currentEventTransitionLane ;
703+ }
704+ }
0 commit comments