@@ -39,12 +39,10 @@ import invariant from 'shared/invariant'; |
39 | 39 | import { |
40 | 40 | scheduleCallback, |
41 | 41 | cancelCallback, |
42 | | - getCurrentPriorityLevel, |
43 | 42 | shouldYield, |
44 | 43 | requestPaint, |
45 | 44 | now, |
46 | 45 | ImmediatePriority as ImmediateSchedulerPriority, |
47 | | - UserBlockingPriority as UserBlockingSchedulerPriority, |
48 | 46 | NormalPriority as NormalSchedulerPriority, |
49 | 47 | flushSyncCallbackQueue, |
50 | 48 | scheduleSyncCallback, |
@@ -148,7 +146,6 @@ import { |
148 | 146 | mergeLanes, |
149 | 147 | removeLanes, |
150 | 148 | pickArbitraryLane, |
151 | | - hasDiscreteLanes, |
152 | 149 | includesNonIdleWork, |
153 | 150 | includesOnlyRetries, |
154 | 151 | includesOnlyTransitions, |
@@ -163,10 +160,8 @@ import { |
163 | 160 | markRootSuspended as markRootSuspended_dontCallThisOneDirectly, |
164 | 161 | markRootPinged, |
165 | 162 | markRootExpired, |
166 | | - markDiscreteUpdatesExpired, |
167 | 163 | markRootFinished, |
168 | 164 | lanePriorityToSchedulerPriority, |
169 | | - higherLanePriority, |
170 | 165 | } from './ReactFiberLane.new'; |
171 | 166 | import {requestCurrentTransition, NoTransition} from './ReactFiberTransition'; |
172 | 167 | import {beginWork as originalBeginWork} from './ReactFiberBeginWork.new'; |
@@ -243,14 +238,13 @@ const { |
243 | 238 |
|
244 | 239 | type ExecutionContext = number; |
245 | 240 |
|
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; |
| 241 | +export const NoContext = /* */ 0b000000; |
| 242 | +const BatchedContext = /* */ 0b000001; |
| 243 | +const EventContext = /* */ 0b000010; |
| 244 | +const LegacyUnbatchedContext = /* */ 0b000100; |
| 245 | +const RenderContext = /* */ 0b001000; |
| 246 | +const CommitContext = /* */ 0b010000; |
| 247 | +export const RetryAfterError = /* */ 0b100000; |
254 | 248 |
|
255 | 249 | type RootExitStatus = 0 | 1 | 2 | 3 | 4 | 5; |
256 | 250 | const RootIncomplete = 0; |
@@ -331,8 +325,6 @@ let pendingPassiveEffectsRenderPriority: LanePriority = NoLanePriority; |
331 | 325 | let pendingPassiveEffectsLanes: Lanes = NoLanes; |
332 | 326 | let pendingPassiveProfilerEffects: Array<Fiber> = []; |
333 | 327 |
|
334 | | -let rootsWithPendingDiscreteUpdates: Set<FiberRoot> | null = null; |
335 | | - |
336 | 328 | // Use these to prevent an infinite loop of nested updates |
337 | 329 | const NESTED_UPDATE_LIMIT = 50; |
338 | 330 | let nestedUpdateCount: number = 0; |
@@ -434,29 +426,17 @@ export function requestUpdateLane(fiber: Fiber): Lane { |
434 | 426 | return currentEventTransitionLane; |
435 | 427 | } |
436 | 428 |
|
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); |
| 429 | + // Updates originating inside certain React methods, like flushSync, have |
| 430 | + // their priority set by tracking it with a context variable. |
| 431 | + const updateLanePriority = getCurrentUpdateLanePriority(); |
| 432 | + if (updateLanePriority !== NoLanePriority) { |
| 433 | + return findUpdateLane(updateLanePriority); |
457 | 434 | } |
458 | 435 |
|
459 | | - return lane; |
| 436 | + // This update originated outside React. Ask the host environement for an |
| 437 | + // appropriate priority, based on the type of event. |
| 438 | + const eventLanePriority = getCurrentEventPriority(); |
| 439 | + return findUpdateLane(eventLanePriority); |
460 | 440 | } |
461 | 441 |
|
462 | 442 | function requestRetryLane(fiber: Fiber) { |
@@ -578,23 +558,6 @@ export function scheduleUpdateOnFiber( |
578 | 558 | } |
579 | 559 | } |
580 | 560 | } 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 | | - } |
598 | 561 | // Schedule other updates after in case the callback is sync. |
599 | 562 | ensureRootIsScheduled(root, eventTime); |
600 | 563 | schedulePendingInteractions(root, lane); |
@@ -1096,7 +1059,7 @@ export function flushDiscreteUpdates() { |
1096 | 1059 | // like `el.focus()`. Exit. |
1097 | 1060 | return; |
1098 | 1061 | } |
1099 | | - flushPendingDiscreteUpdates(); |
| 1062 | + flushSyncCallbackQueue(); |
1100 | 1063 | // If the discrete updates scheduled passive effects, flush them now so that |
1101 | 1064 | // they fire before the next serial event. |
1102 | 1065 | flushPassiveEffects(); |
@@ -1112,21 +1075,6 @@ export function deferredUpdates<A>(fn: () => A): A { |
1112 | 1075 | } |
1113 | 1076 | } |
1114 | 1077 |
|
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 | | - |
1130 | 1078 | export function batchedUpdates<A, R>(fn: A => R, a: A): R { |
1131 | 1079 | const prevExecutionContext = executionContext; |
1132 | 1080 | executionContext |= BatchedContext; |
@@ -1164,16 +1112,12 @@ export function discreteUpdates<A, B, C, D, R>( |
1164 | 1112 | c: C, |
1165 | 1113 | d: D, |
1166 | 1114 | ): R { |
1167 | | - const prevExecutionContext = executionContext; |
1168 | | - executionContext |= DiscreteEventContext; |
1169 | | - |
1170 | 1115 | const previousLanePriority = getCurrentUpdateLanePriority(); |
1171 | 1116 | try { |
1172 | 1117 | setCurrentUpdateLanePriority(InputDiscreteLanePriority); |
1173 | 1118 | return fn(a, b, c, d); |
1174 | 1119 | } finally { |
1175 | 1120 | setCurrentUpdateLanePriority(previousLanePriority); |
1176 | | - executionContext = prevExecutionContext; |
1177 | 1121 | if (executionContext === NoContext) { |
1178 | 1122 | // Flush the immediate callbacks that were scheduled during this batch |
1179 | 1123 | resetRenderTimer(); |
@@ -1802,18 +1746,6 @@ function commitRootImpl(root, renderPriorityLevel) { |
1802 | 1746 | let remainingLanes = mergeLanes(finishedWork.lanes, finishedWork.childLanes); |
1803 | 1747 | markRootFinished(root, remainingLanes); |
1804 | 1748 |
|
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 | | - |
1817 | 1749 | if (root === workInProgressRoot) { |
1818 | 1750 | // We can reset these now that they are finished. |
1819 | 1751 | workInProgressRoot = null; |
|