@@ -148,7 +148,6 @@ import {
148148 mergeLanes ,
149149 removeLanes ,
150150 pickArbitraryLane ,
151- hasDiscreteLanes ,
152151 includesNonIdleWork ,
153152 includesOnlyRetries ,
154153 includesOnlyTransitions ,
@@ -163,10 +162,8 @@ import {
163162 markRootSuspended as markRootSuspended_dontCallThisOneDirectly ,
164163 markRootPinged ,
165164 markRootExpired ,
166- markDiscreteUpdatesExpired ,
167165 markRootFinished ,
168166 lanePriorityToSchedulerPriority ,
169- higherLanePriority ,
170167} from './ReactFiberLane.new' ;
171168import { requestCurrentTransition , NoTransition } from './ReactFiberTransition' ;
172169import { beginWork as originalBeginWork } from './ReactFiberBeginWork.new' ;
@@ -243,14 +240,13 @@ const {
243240
244241type ExecutionContext = number ;
245242
246- export const NoContext = /* */ 0b0000000 ;
247- const BatchedContext = /* */ 0b0000001 ;
248- const EventContext = /* */ 0b0000010 ;
249- const DiscreteEventContext = /* */ 0b0000100 ;
250- const LegacyUnbatchedContext = /* */ 0b0001000 ;
251- const RenderContext = /* */ 0b0010000 ;
252- const CommitContext = /* */ 0b0100000 ;
253- export const RetryAfterError = /* */ 0b1000000 ;
243+ export const NoContext = /* */ 0b000000 ;
244+ const BatchedContext = /* */ 0b000001 ;
245+ const EventContext = /* */ 0b000010 ;
246+ const LegacyUnbatchedContext = /* */ 0b000100 ;
247+ const RenderContext = /* */ 0b001000 ;
248+ const CommitContext = /* */ 0b010000 ;
249+ export const RetryAfterError = /* */ 0b100000 ;
254250
255251type RootExitStatus = 0 | 1 | 2 | 3 | 4 | 5 ;
256252const RootIncomplete = 0 ;
@@ -331,8 +327,6 @@ let pendingPassiveEffectsRenderPriority: LanePriority = NoLanePriority;
331327let pendingPassiveEffectsLanes: Lanes = NoLanes;
332328let pendingPassiveProfilerEffects: Array< Fiber > = [];
333329
334- let rootsWithPendingDiscreteUpdates: Set< FiberRoot > | null = null;
335-
336330// Use these to prevent an infinite loop of nested updates
337331const NESTED_UPDATE_LIMIT = 50;
338332let nestedUpdateCount: number = 0;
@@ -434,29 +428,17 @@ export function requestUpdateLane(fiber: Fiber): Lane {
434428 return currentEventTransitionLane;
435429 }
436430
437- // TODO: Remove this dependency on the Scheduler priority.
438- // To do that, we're replacing it with an update lane priority.
439- const schedulerPriority = getCurrentPriorityLevel ( ) ;
440-
441- // Find the correct lane based on priorities. Ideally, this would just be
442- // the update lane priority, but for now we're also checking for discrete
443- // updates and falling back to the scheduler priority.
444- let lane ;
445- if (
446- // TODO: Temporary. We're removing the concept of discrete updates.
447- ( executionContext & DiscreteEventContext ) !== NoContext &&
448- schedulerPriority === UserBlockingSchedulerPriority
449- ) {
450- lane = findUpdateLane ( InputDiscreteLanePriority ) ;
451- } else if (getCurrentUpdateLanePriority() !== NoLanePriority) {
452- const currentLanePriority = getCurrentUpdateLanePriority ( ) ;
453- lane = findUpdateLane ( currentLanePriority ) ;
454- } else {
455- const eventLanePriority = getCurrentEventPriority ( ) ;
456- lane = findUpdateLane ( eventLanePriority ) ;
431+ // Updates originating inside certain React methods, like flushSync, have
432+ // their priority set by tracking it with a context variable.
433+ const updateLanePriority = getCurrentUpdateLanePriority ( ) ;
434+ if ( updateLanePriority !== NoLanePriority ) {
435+ return findUpdateLane ( updateLanePriority ) ;
457436 }
458437
459- return lane;
438+ // This update originated outside React. Ask the host environement for an
439+ // appropriate priority, based on the type of event.
440+ const eventLanePriority = getCurrentEventPriority();
441+ return findUpdateLane(eventLanePriority);
460442}
461443
462444function requestRetryLane ( fiber : Fiber ) {
@@ -578,23 +560,6 @@ export function scheduleUpdateOnFiber(
578560 }
579561 }
580562 } else {
581- const updateLanePriority = getCurrentUpdateLanePriority ( ) ;
582-
583- // Schedule a discrete update but only if it's not Sync.
584- if (
585- ( executionContext & DiscreteEventContext ) !== NoContext &&
586- // Only updates greater than default considered discrete, even inside a discrete event.
587- higherLanePriority ( updateLanePriority , DefaultLanePriority ) !==
588- DefaultLanePriority
589- ) {
590- // This is the result of a discrete event. Track the lowest priority
591- // discrete update per root so we can flush them early, if needed.
592- if ( rootsWithPendingDiscreteUpdates === null ) {
593- rootsWithPendingDiscreteUpdates = new Set ( [ root ] ) ;
594- } else {
595- rootsWithPendingDiscreteUpdates . add ( root ) ;
596- }
597- }
598563 // Schedule other updates after in case the callback is sync.
599564 ensureRootIsScheduled ( root , eventTime ) ;
600565 schedulePendingInteractions ( root , lane ) ;
@@ -1096,7 +1061,7 @@ export function flushDiscreteUpdates() {
10961061 // like `el.focus()`. Exit.
10971062 return ;
10981063 }
1099- flushPendingDiscreteUpdates ( ) ;
1064+ flushSyncCallbackQueue ( ) ;
11001065 // If the discrete updates scheduled passive effects, flush them now so that
11011066 // they fire before the next serial event.
11021067 flushPassiveEffects ( ) ;
@@ -1112,21 +1077,6 @@ export function deferredUpdates<A>(fn: () => A): A {
11121077 }
11131078}
11141079
1115- function flushPendingDiscreteUpdates ( ) {
1116- if ( rootsWithPendingDiscreteUpdates !== null ) {
1117- // For each root with pending discrete updates, schedule a callback to
1118- // immediately flush them.
1119- const roots = rootsWithPendingDiscreteUpdates ;
1120- rootsWithPendingDiscreteUpdates = null ;
1121- roots . forEach ( root => {
1122- markDiscreteUpdatesExpired ( root ) ;
1123- ensureRootIsScheduled ( root , now ( ) ) ;
1124- } ) ;
1125- }
1126- // Now flush the immediate queue.
1127- flushSyncCallbackQueue ( ) ;
1128- }
1129-
11301080export function batchedUpdates < A , R > ( fn : A => R , a : A ) : R {
11311081 const prevExecutionContext = executionContext ;
11321082 executionContext |= BatchedContext ;
@@ -1164,16 +1114,12 @@ export function discreteUpdates<A, B, C, D, R>(
11641114 c : C ,
11651115 d : D ,
11661116) : R {
1167- const prevExecutionContext = executionContext ;
1168- executionContext |= DiscreteEventContext ;
1169-
11701117 const previousLanePriority = getCurrentUpdateLanePriority ( ) ;
11711118 try {
11721119 setCurrentUpdateLanePriority ( InputDiscreteLanePriority ) ;
11731120 return fn ( a , b , c , d ) ;
11741121 } finally {
11751122 setCurrentUpdateLanePriority ( previousLanePriority ) ;
1176- executionContext = prevExecutionContext ;
11771123 if ( executionContext === NoContext ) {
11781124 // Flush the immediate callbacks that were scheduled during this batch
11791125 resetRenderTimer ( ) ;
@@ -1802,18 +1748,6 @@ function commitRootImpl(root, renderPriorityLevel) {
18021748 let remainingLanes = mergeLanes ( finishedWork . lanes , finishedWork . childLanes ) ;
18031749 markRootFinished ( root , remainingLanes ) ;
18041750
1805- // Clear already finished discrete updates in case that a later call of
1806- // `flushDiscreteUpdates` starts a useless render pass which may cancels
1807- // a scheduled timeout.
1808- if ( rootsWithPendingDiscreteUpdates !== null ) {
1809- if (
1810- ! hasDiscreteLanes ( remainingLanes ) &&
1811- rootsWithPendingDiscreteUpdates . has ( root )
1812- ) {
1813- rootsWithPendingDiscreteUpdates . delete ( root ) ;
1814- }
1815- }
1816-
18171751 if ( root === workInProgressRoot ) {
18181752 // We can reset these now that they are finished.
18191753 workInProgressRoot = null ;
0 commit comments