@@ -84,6 +84,7 @@ import {
8484 scheduleMicrotask ,
8585 prepareRendererToRender ,
8686 resetRendererAfterRender ,
87+ getIsCurrentEventPopState ,
8788} from './ReactFiberHostConfig' ;
8889
8990import {
@@ -137,7 +138,7 @@ import {
137138 NoTimestamp ,
138139 claimNextTransitionLane ,
139140 claimNextRetryLane ,
140- includesSyncLane ,
141+ includesSyncLaneOrForceSync ,
141142 isSubsetOfLanes ,
142143 mergeLanes ,
143144 removeLanes ,
@@ -147,6 +148,7 @@ import {
147148 includesOnlyTransitions ,
148149 includesBlockingLane ,
149150 includesExpiredLane ,
151+ isTransitionLane ,
150152 getNextLanes ,
151153 markStarvedLanesAsExpired ,
152154 getLanesToRetrySynchronouslyOnError ,
@@ -727,6 +729,7 @@ export function scheduleUpdateOnFiber(
727729 }
728730
729731 // Mark that the root has a pending update.
732+ markRootWithPopState ( root , lane ) ;
730733 markRootUpdated ( root , lane , eventTime ) ;
731734
732735 if (
@@ -914,7 +917,7 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
914917 // TODO: Temporary until we confirm this warning is not fired.
915918 if (
916919 existingCallbackNode == null &&
917- ! includesSyncLane ( existingCallbackPriority )
920+ ! includesSyncLaneOrForceSync ( existingCallbackPriority , root )
918921 ) {
919922 console . error (
920923 'Expected scheduled callback to exist. This error is likely caused by a bug in React. Please file an issue.' ,
@@ -932,7 +935,7 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
932935
933936 // Schedule a new callback.
934937 let newCallbackNode ;
935- if ( includesSyncLane ( newCallbackPriority ) ) {
938+ if ( includesSyncLaneOrForceSync ( newCallbackPriority , root ) ) {
936939 // Special case: Sync React callbacks are scheduled on a special
937940 // internal queue
938941 if ( root . tag === LegacyRoot ) {
@@ -1455,6 +1458,12 @@ function markRootSuspended(root: FiberRoot, suspendedLanes: Lanes) {
14551458 markRootSuspended_dontCallThisOneDirectly ( root , suspendedLanes ) ;
14561459}
14571460
1461+ function markRootWithPopState ( root : FiberRoot , updateLane : Lane ) {
1462+ if ( isTransitionLane ( updateLane ) && getIsCurrentEventPopState ( ) ) {
1463+ root . forceSync = true ;
1464+ }
1465+ }
1466+
14581467// This is the entry point for synchronous tasks that don't go
14591468// through Scheduler
14601469function performSyncWorkOnRoot ( root : FiberRoot ) {
@@ -1469,7 +1478,7 @@ function performSyncWorkOnRoot(root: FiberRoot) {
14691478 flushPassiveEffects ( ) ;
14701479
14711480 let lanes = getNextLanes ( root , NoLanes ) ;
1472- if ( ! includesSyncLane ( lanes ) ) {
1481+ if ( ! includesSyncLaneOrForceSync ( lanes , root ) ) {
14731482 // There's no remaining sync work left.
14741483 ensureRootIsScheduled ( root , now ( ) ) ;
14751484 return null ;
@@ -2920,13 +2929,16 @@ function commitRootImpl(
29202929 // TODO: We can optimize this by not scheduling the callback earlier. Since we
29212930 // currently schedule the callback in multiple places, will wait until those
29222931 // are consolidated.
2923- if ( includesSyncLane ( pendingPassiveEffectsLanes ) && root . tag !== LegacyRoot ) {
2932+ if (
2933+ includesSyncLaneOrForceSync ( pendingPassiveEffectsLanes , root ) &&
2934+ root . tag !== LegacyRoot
2935+ ) {
29242936 flushPassiveEffects ( ) ;
29252937 }
29262938
29272939 // Read this again, since a passive effect might have updated it
29282940 remainingLanes = root . pendingLanes ;
2929- if ( includesSyncLane ( remainingLanes ) ) {
2941+ if ( includesSyncLaneOrForceSync ( remainingLanes , root ) ) {
29302942 if ( enableProfilerTimer && enableProfilerNestedUpdatePhase ) {
29312943 markNestedUpdateScheduled ( ) ;
29322944 }
0 commit comments