@samitouri / QOS-React-2 / commits / e89d74ee67

Remove decoupleUpdatePriorityFromScheduler

Rick Hanlon committed Mar 8, 2021 at 09:16 UTC e89d74ee679bafe09213ef66394dd530d2168787
18 files changed +226 -542
packages/react-dom/src/events/ReactDOMEventListener.js
+6 -20
@@ -40,7 +40,6 @@ import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
40
41 import {
42 enableLegacyFBSupport,
43 - decoupleUpdatePriorityFromScheduler,
43 enableNewReconciler,
44 } from 'shared/ReactFeatureFlags';
45 import {dispatchEventForPluginEventSystem} from './DOMPluginEventSystem';
@@ -177,25 +176,10 @@ function dispatchContinuousEvent(
176 container,
177 nativeEvent,
178 ) {
180 - if (decoupleUpdatePriorityFromScheduler) {
181 - const previousPriority = getCurrentUpdateLanePriority();
182 - try {
183 - // TODO: Double wrapping is necessary while we decouple Scheduler priority.
184 - setCurrentUpdateLanePriority(InputContinuousLanePriority);
185 - runWithPriority(
186 - UserBlockingPriority,
187 - dispatchEvent.bind(
188 - null,
189 - domEventName,
190 - eventSystemFlags,
191 - container,
192 - nativeEvent,
193 - ),
194 - );
195 - } finally {
196 - setCurrentUpdateLanePriority(previousPriority);
197 - }
198 - } else {
179 + const previousPriority = getCurrentUpdateLanePriority();
180 + try {
181 + // TODO: Double wrapping is necessary while we decouple Scheduler priority.
182 + setCurrentUpdateLanePriority(InputContinuousLanePriority);
183 runWithPriority(
184 UserBlockingPriority,
185 dispatchEvent.bind(
@@ -206,6 +190,8 @@ function dispatchContinuousEvent(
190 nativeEvent,
191 ),
192 );
193 + } finally {
194 + setCurrentUpdateLanePriority(previousPriority);
195 }
196 }
197
packages/react-reconciler/src/ReactFiberHooks.new.js
+28 -58
@@ -27,7 +27,6 @@ import {
27 enableSchedulingProfiler,
28 enableNewReconciler,
29 enableCache,
30 - decoupleUpdatePriorityFromScheduler,
30 enableUseRefAccessWarning,
31 enableStrictEffects,
32 enableLazyContextPropagation,
@@ -1713,66 +1712,37 @@ function rerenderDeferredValue<T>(value: T): T {
1712
1713 function startTransition(setPending, callback) {
1714 const priorityLevel = getCurrentPriorityLevel();
1716 - if (decoupleUpdatePriorityFromScheduler) {
1717 - const previousLanePriority = getCurrentUpdateLanePriority();
1718 - setCurrentUpdateLanePriority(
1719 - higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1720 - );
1715 + const previousLanePriority = getCurrentUpdateLanePriority();
1716 + setCurrentUpdateLanePriority(
1717 + higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1718 + );
1719
1722 - runWithPriority(
1723 - priorityLevel < UserBlockingPriority
1724 - ? UserBlockingPriority
1725 - : priorityLevel,
1726 - () => {
1727 - setPending(true);
1728 - },
1729 - );
1720 + runWithPriority(
1721 + priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
1722 + () => {
1723 + setPending(true);
1724 + },
1725 + );
1726
1731 - // TODO: Can remove this. Was only necessary because we used to give
1732 - // different behavior to transitions without a config object. Now they are
1733 - // all treated the same.
1734 - setCurrentUpdateLanePriority(DefaultLanePriority);
1727 + // TODO: Can remove this. Was only necessary because we used to give
1728 + // different behavior to transitions without a config object. Now they are
1729 + // all treated the same.
1730 + setCurrentUpdateLanePriority(DefaultLanePriority);
1731
1736 - runWithPriority(
1737 - priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1738 - () => {
1739 - const prevTransition = ReactCurrentBatchConfig.transition;
1740 - ReactCurrentBatchConfig.transition = 1;
1741 - try {
1742 - setPending(false);
1743 - callback();
1744 - } finally {
1745 - if (decoupleUpdatePriorityFromScheduler) {
1746 - setCurrentUpdateLanePriority(previousLanePriority);
1747 - }
1748 - ReactCurrentBatchConfig.transition = prevTransition;
1749 - }
1750 - },
1751 - );
1752 - } else {
1753 - runWithPriority(
1754 - priorityLevel < UserBlockingPriority
1755 - ? UserBlockingPriority
1756 - : priorityLevel,
1757 - () => {
1758 - setPending(true);
1759 - },
1760 - );
1761 -
1762 - runWithPriority(
1763 - priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1764 - () => {
1765 - const prevTransition = ReactCurrentBatchConfig.transition;
1766 - ReactCurrentBatchConfig.transition = 1;
1767 - try {
1768 - setPending(false);
1769 - callback();
1770 - } finally {
1771 - ReactCurrentBatchConfig.transition = prevTransition;
1772 - }
1773 - },
1774 - );
1775 - }
1732 + runWithPriority(
1733 + priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1734 + () => {
1735 + const prevTransition = ReactCurrentBatchConfig.transition;
1736 + ReactCurrentBatchConfig.transition = 1;
1737 + try {
1738 + setPending(false);
1739 + callback();
1740 + } finally {
1741 + setCurrentUpdateLanePriority(previousLanePriority);
1742 + ReactCurrentBatchConfig.transition = prevTransition;
1743 + }
1744 + },
1745 + );
1746 }
1747
1748 function mountTransition(): [(() => void) => void, boolean] {
packages/react-reconciler/src/ReactFiberHooks.old.js
+28 -58
@@ -27,7 +27,6 @@ import {
27 enableSchedulingProfiler,
28 enableNewReconciler,
29 enableCache,
30 - decoupleUpdatePriorityFromScheduler,
30 enableUseRefAccessWarning,
31 enableStrictEffects,
32 enableLazyContextPropagation,
@@ -1713,66 +1712,37 @@ function rerenderDeferredValue<T>(value: T): T {
1712
1713 function startTransition(setPending, callback) {
1714 const priorityLevel = getCurrentPriorityLevel();
1716 - if (decoupleUpdatePriorityFromScheduler) {
1717 - const previousLanePriority = getCurrentUpdateLanePriority();
1718 - setCurrentUpdateLanePriority(
1719 - higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1720 - );
1715 + const previousLanePriority = getCurrentUpdateLanePriority();
1716 + setCurrentUpdateLanePriority(
1717 + higherLanePriority(previousLanePriority, InputContinuousLanePriority),
1718 + );
1719
1722 - runWithPriority(
1723 - priorityLevel < UserBlockingPriority
1724 - ? UserBlockingPriority
1725 - : priorityLevel,
1726 - () => {
1727 - setPending(true);
1728 - },
1729 - );
1720 + runWithPriority(
1721 + priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
1722 + () => {
1723 + setPending(true);
1724 + },
1725 + );
1726
1731 - // TODO: Can remove this. Was only necessary because we used to give
1732 - // different behavior to transitions without a config object. Now they are
1733 - // all treated the same.
1734 - setCurrentUpdateLanePriority(DefaultLanePriority);
1727 + // TODO: Can remove this. Was only necessary because we used to give
1728 + // different behavior to transitions without a config object. Now they are
1729 + // all treated the same.
1730 + setCurrentUpdateLanePriority(DefaultLanePriority);
1731
1736 - runWithPriority(
1737 - priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1738 - () => {
1739 - const prevTransition = ReactCurrentBatchConfig.transition;
1740 - ReactCurrentBatchConfig.transition = 1;
1741 - try {
1742 - setPending(false);
1743 - callback();
1744 - } finally {
1745 - if (decoupleUpdatePriorityFromScheduler) {
1746 - setCurrentUpdateLanePriority(previousLanePriority);
1747 - }
1748 - ReactCurrentBatchConfig.transition = prevTransition;
1749 - }
1750 - },
1751 - );
1752 - } else {
1753 - runWithPriority(
1754 - priorityLevel < UserBlockingPriority
1755 - ? UserBlockingPriority
1756 - : priorityLevel,
1757 - () => {
1758 - setPending(true);
1759 - },
1760 - );
1761 -
1762 - runWithPriority(
1763 - priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1764 - () => {
1765 - const prevTransition = ReactCurrentBatchConfig.transition;
1766 - ReactCurrentBatchConfig.transition = 1;
1767 - try {
1768 - setPending(false);
1769 - callback();
1770 - } finally {
1771 - ReactCurrentBatchConfig.transition = prevTransition;
1772 - }
1773 - },
1774 - );
1775 - }
1732 + runWithPriority(
1733 + priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
1734 + () => {
1735 + const prevTransition = ReactCurrentBatchConfig.transition;
1736 + ReactCurrentBatchConfig.transition = 1;
1737 + try {
1738 + setPending(false);
1739 + callback();
1740 + } finally {
1741 + setCurrentUpdateLanePriority(previousLanePriority);
1742 + ReactCurrentBatchConfig.transition = prevTransition;
1743 + }
1744 + },
1745 + );
1746 }
1747
1748 function mountTransition(): [(() => void) => void, boolean] {
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+56 -140
@@ -28,7 +28,6 @@ import {
28 enableSchedulerTracing,
29 warnAboutUnmockedScheduler,
30 deferRenderPhaseUpdateToNextBatch,
31 - decoupleUpdatePriorityFromScheduler,
31 enableDebugTracing,
32 enableSchedulingProfiler,
33 disableSchedulerTimeoutInWorkLoop,
@@ -455,10 +454,7 @@ export function requestUpdateLane(fiber: Fiber): Lane {
454 schedulerPriority === UserBlockingSchedulerPriority
455 ) {
456 lane = findUpdateLane(InputDiscreteLanePriority);
458 - } else if (
459 - decoupleUpdatePriorityFromScheduler &&
460 - getCurrentUpdateLanePriority() !== NoLanePriority
461 - ) {
457 + } else if (getCurrentUpdateLanePriority() !== NoLanePriority) {
458 const currentLanePriority = getCurrentUpdateLanePriority();
459 lane = findUpdateLane(currentLanePriority);
460 } else {
@@ -567,10 +563,6 @@ export function scheduleUpdateOnFiber(
563 }
564 }
565
570 - // TODO: requestUpdateLanePriority also reads the priority. Pass the
571 - // priority as an argument to that function and this one.
572 - const priorityLevel = getCurrentPriorityLevel();
573 -
566 if (lane === SyncLane) {
567 if (
568 // Check if we're inside unbatchedUpdates
@@ -598,7 +590,7 @@ export function scheduleUpdateOnFiber(
590 flushSyncCallbackQueue();
591 }
592 }
601 - } else if (decoupleUpdatePriorityFromScheduler) {
593 + } else {
594 const updateLanePriority = getCurrentUpdateLanePriority();
595
596 // Schedule a discrete update but only if it's not Sync.
@@ -619,26 +611,6 @@ export function scheduleUpdateOnFiber(
611 // Schedule other updates after in case the callback is sync.
612 ensureRootIsScheduled(root, eventTime);
613 schedulePendingInteractions(root, lane);
622 - } else {
623 - // Schedule a discrete update but only if it's not Sync.
624 - if (
625 - (executionContext & DiscreteEventContext) !== NoContext &&
626 - // Only updates at user-blocking priority or greater are considered
627 - // discrete, even inside a discrete event.
628 - (priorityLevel === UserBlockingSchedulerPriority ||
629 - priorityLevel === ImmediateSchedulerPriority)
630 - ) {
631 - // This is the result of a discrete event. Track the lowest priority
632 - // discrete update per root so we can flush them early, if needed.
633 - if (rootsWithPendingDiscreteUpdates === null) {
634 - rootsWithPendingDiscreteUpdates = new Set([root]);
635 - } else {
636 - rootsWithPendingDiscreteUpdates.add(root);
637 - }
638 - }
639 - // Schedule other updates after in case the callback is sync.
640 - ensureRootIsScheduled(root, eventTime);
641 - schedulePendingInteractions(root, lane);
614 }
615
616 return root;
@@ -1150,16 +1122,12 @@ export function flushDiscreteUpdates() {
1122 }
1123
1124 export function deferredUpdates<A>(fn: () => A): A {
1153 - if (decoupleUpdatePriorityFromScheduler) {
1154 - const previousLanePriority = getCurrentUpdateLanePriority();
1155 - try {
1156 - setCurrentUpdateLanePriority(DefaultLanePriority);
1157 - return runWithPriority(NormalSchedulerPriority, fn);
1158 - } finally {
1159 - setCurrentUpdateLanePriority(previousLanePriority);
1160 - }
1161 - } else {
1125 + const previousLanePriority = getCurrentUpdateLanePriority();
1126 + try {
1127 + setCurrentUpdateLanePriority(DefaultLanePriority);
1128 return runWithPriority(NormalSchedulerPriority, fn);
1129 + } finally {
1130 + setCurrentUpdateLanePriority(previousLanePriority);
1131 }
1132 }
1133
@@ -1218,36 +1186,20 @@ export function discreteUpdates<A, B, C, D, R>(
1186 const prevExecutionContext = executionContext;
1187 executionContext |= DiscreteEventContext;
1188
1221 - if (decoupleUpdatePriorityFromScheduler) {
1222 - const previousLanePriority = getCurrentUpdateLanePriority();
1223 - try {
1224 - setCurrentUpdateLanePriority(InputDiscreteLanePriority);
1225 - return runWithPriority(
1226 - UserBlockingSchedulerPriority,
1227 - fn.bind(null, a, b, c, d),
1228 - );
1229 - } finally {
1230 - setCurrentUpdateLanePriority(previousLanePriority);
1231 - executionContext = prevExecutionContext;
1232 - if (executionContext === NoContext) {
1233 - // Flush the immediate callbacks that were scheduled during this batch
1234 - resetRenderTimer();
1235 - flushSyncCallbackQueue();
1236 - }
1237 - }
1238 - } else {
1239 - try {
1240 - return runWithPriority(
1241 - UserBlockingSchedulerPriority,
1242 - fn.bind(null, a, b, c, d),
1243 - );
1244 - } finally {
1245 - executionContext = prevExecutionContext;
1246 - if (executionContext === NoContext) {
1247 - // Flush the immediate callbacks that were scheduled during this batch
1248 - resetRenderTimer();
1249 - flushSyncCallbackQueue();
1250 - }
1189 + const previousLanePriority = getCurrentUpdateLanePriority();
1190 + try {
1191 + setCurrentUpdateLanePriority(InputDiscreteLanePriority);
1192 + return runWithPriority(
1193 + UserBlockingSchedulerPriority,
1194 + fn.bind(null, a, b, c, d),
1195 + );
1196 + } finally {
1197 + setCurrentUpdateLanePriority(previousLanePriority);
1198 + executionContext = prevExecutionContext;
1199 + if (executionContext === NoContext) {
1200 + // Flush the immediate callbacks that were scheduled during this batch
1201 + resetRenderTimer();
1202 + flushSyncCallbackQueue();
1203 }
1204 }
1205 }
@@ -1282,68 +1234,39 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
1234 }
1235 executionContext |= BatchedContext;
1236
1285 - if (decoupleUpdatePriorityFromScheduler) {
1286 - const previousLanePriority = getCurrentUpdateLanePriority();
1287 - try {
1288 - setCurrentUpdateLanePriority(SyncLanePriority);
1289 - if (fn) {
1290 - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
1291 - } else {
1292 - return (undefined: $FlowFixMe);
1293 - }
1294 - } finally {
1295 - setCurrentUpdateLanePriority(previousLanePriority);
1296 - executionContext = prevExecutionContext;
1297 - // Flush the immediate callbacks that were scheduled during this batch.
1298 - // Note that this will happen even if batchedUpdates is higher up
1299 - // the stack.
1300 - flushSyncCallbackQueue();
1301 - }
1302 - } else {
1303 - try {
1304 - if (fn) {
1305 - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
1306 - } else {
1307 - return (undefined: $FlowFixMe);
1308 - }
1309 - } finally {
1310 - executionContext = prevExecutionContext;
1311 - // Flush the immediate callbacks that were scheduled during this batch.
1312 - // Note that this will happen even if batchedUpdates is higher up
1313 - // the stack.
1314 - flushSyncCallbackQueue();
1237 + const previousLanePriority = getCurrentUpdateLanePriority();
1238 + try {
1239 + setCurrentUpdateLanePriority(SyncLanePriority);
1240 + if (fn) {
1241 + return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
1242 + } else {
1243 + return (undefined: $FlowFixMe);
1244 }
1245 + } finally {
1246 + setCurrentUpdateLanePriority(previousLanePriority);
1247 + executionContext = prevExecutionContext;
1248 + // Flush the immediate callbacks that were scheduled during this batch.
1249 + // Note that this will happen even if batchedUpdates is higher up
1250 + // the stack.
1251 + flushSyncCallbackQueue();
1252 }
1253 }
1254
1255 export function flushControlled(fn: () => mixed): void {
1256 const prevExecutionContext = executionContext;
1257 executionContext |= BatchedContext;
1322 - if (decoupleUpdatePriorityFromScheduler) {
1323 - const previousLanePriority = getCurrentUpdateLanePriority();
1324 - try {
1325 - setCurrentUpdateLanePriority(SyncLanePriority);
1326 - runWithPriority(ImmediateSchedulerPriority, fn);
1327 - } finally {
1328 - setCurrentUpdateLanePriority(previousLanePriority);
1258 + const previousLanePriority = getCurrentUpdateLanePriority();
1259 + try {
1260 + setCurrentUpdateLanePriority(SyncLanePriority);
1261 + runWithPriority(ImmediateSchedulerPriority, fn);
1262 + } finally {
1263 + setCurrentUpdateLanePriority(previousLanePriority);
1264
1330 - executionContext = prevExecutionContext;
1331 - if (executionContext === NoContext) {
1332 - // Flush the immediate callbacks that were scheduled during this batch
1333 - resetRenderTimer();
1334 - flushSyncCallbackQueue();
1335 - }
1336 - }
1337 - } else {
1338 - try {
1339 - runWithPriority(ImmediateSchedulerPriority, fn);
1340 - } finally {
1341 - executionContext = prevExecutionContext;
1342 - if (executionContext === NoContext) {
1343 - // Flush the immediate callbacks that were scheduled during this batch
1344 - resetRenderTimer();
1345 - flushSyncCallbackQueue();
1346 - }
1265 + executionContext = prevExecutionContext;
1266 + if (executionContext === NoContext) {
1267 + // Flush the immediate callbacks that were scheduled during this batch
1268 + resetRenderTimer();
1269 + flushSyncCallbackQueue();
1270 }
1271 }
1272 }
@@ -1954,11 +1877,8 @@ function commitRootImpl(root, renderPriorityLevel) {
1877 NoFlags;
1878
1879 if (subtreeHasEffects || rootHasEffect) {
1957 - let previousLanePriority;
1958 - if (decoupleUpdatePriorityFromScheduler) {
1959 - previousLanePriority = getCurrentUpdateLanePriority();
1960 - setCurrentUpdateLanePriority(SyncLanePriority);
1961 - }
1880 + const previousLanePriority = getCurrentUpdateLanePriority();
1881 + setCurrentUpdateLanePriority(SyncLanePriority);
1882
1883 const prevExecutionContext = executionContext;
1884 executionContext |= CommitContext;
@@ -2040,7 +1960,7 @@ function commitRootImpl(root, renderPriorityLevel) {
1960 }
1961 executionContext = prevExecutionContext;
1962
2043 - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) {
1963 + if (previousLanePriority != null) {
1964 // Reset the priority to the previous non-sync value.
1965 setCurrentUpdateLanePriority(previousLanePriority);
1966 }
@@ -2183,18 +2103,14 @@ export function flushPassiveEffects(): boolean {
2103 ? NormalSchedulerPriority
2104 : pendingPassiveEffectsRenderPriority;
2105 pendingPassiveEffectsRenderPriority = NoSchedulerPriority;
2186 - if (decoupleUpdatePriorityFromScheduler) {
2187 - const previousLanePriority = getCurrentUpdateLanePriority();
2188 - try {
2189 - setCurrentUpdateLanePriority(
2190 - schedulerPriorityToLanePriority(priorityLevel),
2191 - );
2192 - return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
2193 - } finally {
2194 - setCurrentUpdateLanePriority(previousLanePriority);
2195 - }
2196 - } else {
2106 + const previousLanePriority = getCurrentUpdateLanePriority();
2107 + try {
2108 + setCurrentUpdateLanePriority(
2109 + schedulerPriorityToLanePriority(priorityLevel),
2110 + );
2111 return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
2112 + } finally {
2113 + setCurrentUpdateLanePriority(previousLanePriority);
2114 }
2115 }
2116 return false;
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+56 -140
@@ -28,7 +28,6 @@ import {
28 enableSchedulerTracing,
29 warnAboutUnmockedScheduler,
30 deferRenderPhaseUpdateToNextBatch,
31 - decoupleUpdatePriorityFromScheduler,
31 enableDebugTracing,
32 enableSchedulingProfiler,
33 disableSchedulerTimeoutInWorkLoop,
@@ -455,10 +454,7 @@ export function requestUpdateLane(fiber: Fiber): Lane {
454 schedulerPriority === UserBlockingSchedulerPriority
455 ) {
456 lane = findUpdateLane(InputDiscreteLanePriority);
458 - } else if (
459 - decoupleUpdatePriorityFromScheduler &&
460 - getCurrentUpdateLanePriority() !== NoLanePriority
461 - ) {
457 + } else if (getCurrentUpdateLanePriority() !== NoLanePriority) {
458 const currentLanePriority = getCurrentUpdateLanePriority();
459 lane = findUpdateLane(currentLanePriority);
460 } else {
@@ -567,10 +563,6 @@ export function scheduleUpdateOnFiber(
563 }
564 }
565
570 - // TODO: requestUpdateLanePriority also reads the priority. Pass the
571 - // priority as an argument to that function and this one.
572 - const priorityLevel = getCurrentPriorityLevel();
573 -
566 if (lane === SyncLane) {
567 if (
568 // Check if we're inside unbatchedUpdates
@@ -598,7 +590,7 @@ export function scheduleUpdateOnFiber(
590 flushSyncCallbackQueue();
591 }
592 }
601 - } else if (decoupleUpdatePriorityFromScheduler) {
593 + } else {
594 const updateLanePriority = getCurrentUpdateLanePriority();
595
596 // Schedule a discrete update but only if it's not Sync.
@@ -619,26 +611,6 @@ export function scheduleUpdateOnFiber(
611 // Schedule other updates after in case the callback is sync.
612 ensureRootIsScheduled(root, eventTime);
613 schedulePendingInteractions(root, lane);
622 - } else {
623 - // Schedule a discrete update but only if it's not Sync.
624 - if (
625 - (executionContext & DiscreteEventContext) !== NoContext &&
626 - // Only updates at user-blocking priority or greater are considered
627 - // discrete, even inside a discrete event.
628 - (priorityLevel === UserBlockingSchedulerPriority ||
629 - priorityLevel === ImmediateSchedulerPriority)
630 - ) {
631 - // This is the result of a discrete event. Track the lowest priority
632 - // discrete update per root so we can flush them early, if needed.
633 - if (rootsWithPendingDiscreteUpdates === null) {
634 - rootsWithPendingDiscreteUpdates = new Set([root]);
635 - } else {
636 - rootsWithPendingDiscreteUpdates.add(root);
637 - }
638 - }
639 - // Schedule other updates after in case the callback is sync.
640 - ensureRootIsScheduled(root, eventTime);
641 - schedulePendingInteractions(root, lane);
614 }
615
616 return root;
@@ -1150,16 +1122,12 @@ export function flushDiscreteUpdates() {
1122 }
1123
1124 export function deferredUpdates<A>(fn: () => A): A {
1153 - if (decoupleUpdatePriorityFromScheduler) {
1154 - const previousLanePriority = getCurrentUpdateLanePriority();
1155 - try {
1156 - setCurrentUpdateLanePriority(DefaultLanePriority);
1157 - return runWithPriority(NormalSchedulerPriority, fn);
1158 - } finally {
1159 - setCurrentUpdateLanePriority(previousLanePriority);
1160 - }
1161 - } else {
1125 + const previousLanePriority = getCurrentUpdateLanePriority();
1126 + try {
1127 + setCurrentUpdateLanePriority(DefaultLanePriority);
1128 return runWithPriority(NormalSchedulerPriority, fn);
1129 + } finally {
1130 + setCurrentUpdateLanePriority(previousLanePriority);
1131 }
1132 }
1133
@@ -1218,36 +1186,20 @@ export function discreteUpdates<A, B, C, D, R>(
1186 const prevExecutionContext = executionContext;
1187 executionContext |= DiscreteEventContext;
1188
1221 - if (decoupleUpdatePriorityFromScheduler) {
1222 - const previousLanePriority = getCurrentUpdateLanePriority();
1223 - try {
1224 - setCurrentUpdateLanePriority(InputDiscreteLanePriority);
1225 - return runWithPriority(
1226 - UserBlockingSchedulerPriority,
1227 - fn.bind(null, a, b, c, d),
1228 - );
1229 - } finally {
1230 - setCurrentUpdateLanePriority(previousLanePriority);
1231 - executionContext = prevExecutionContext;
1232 - if (executionContext === NoContext) {
1233 - // Flush the immediate callbacks that were scheduled during this batch
1234 - resetRenderTimer();
1235 - flushSyncCallbackQueue();
1236 - }
1237 - }
1238 - } else {
1239 - try {
1240 - return runWithPriority(
1241 - UserBlockingSchedulerPriority,
1242 - fn.bind(null, a, b, c, d),
1243 - );
1244 - } finally {
1245 - executionContext = prevExecutionContext;
1246 - if (executionContext === NoContext) {
1247 - // Flush the immediate callbacks that were scheduled during this batch
1248 - resetRenderTimer();
1249 - flushSyncCallbackQueue();
1250 - }
1189 + const previousLanePriority = getCurrentUpdateLanePriority();
1190 + try {
1191 + setCurrentUpdateLanePriority(InputDiscreteLanePriority);
1192 + return runWithPriority(
1193 + UserBlockingSchedulerPriority,
1194 + fn.bind(null, a, b, c, d),
1195 + );
1196 + } finally {
1197 + setCurrentUpdateLanePriority(previousLanePriority);
1198 + executionContext = prevExecutionContext;
1199 + if (executionContext === NoContext) {
1200 + // Flush the immediate callbacks that were scheduled during this batch
1201 + resetRenderTimer();
1202 + flushSyncCallbackQueue();
1203 }
1204 }
1205 }
@@ -1282,68 +1234,39 @@ export function flushSync<A, R>(fn: A => R, a: A): R {
1234 }
1235 executionContext |= BatchedContext;
1236
1285 - if (decoupleUpdatePriorityFromScheduler) {
1286 - const previousLanePriority = getCurrentUpdateLanePriority();
1287 - try {
1288 - setCurrentUpdateLanePriority(SyncLanePriority);
1289 - if (fn) {
1290 - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
1291 - } else {
1292 - return (undefined: $FlowFixMe);
1293 - }
1294 - } finally {
1295 - setCurrentUpdateLanePriority(previousLanePriority);
1296 - executionContext = prevExecutionContext;
1297 - // Flush the immediate callbacks that were scheduled during this batch.
1298 - // Note that this will happen even if batchedUpdates is higher up
1299 - // the stack.
1300 - flushSyncCallbackQueue();
1301 - }
1302 - } else {
1303 - try {
1304 - if (fn) {
1305 - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
1306 - } else {
1307 - return (undefined: $FlowFixMe);
1308 - }
1309 - } finally {
1310 - executionContext = prevExecutionContext;
1311 - // Flush the immediate callbacks that were scheduled during this batch.
1312 - // Note that this will happen even if batchedUpdates is higher up
1313 - // the stack.
1314 - flushSyncCallbackQueue();
1237 + const previousLanePriority = getCurrentUpdateLanePriority();
1238 + try {
1239 + setCurrentUpdateLanePriority(SyncLanePriority);
1240 + if (fn) {
1241 + return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a));
1242 + } else {
1243 + return (undefined: $FlowFixMe);
1244 }
1245 + } finally {
1246 + setCurrentUpdateLanePriority(previousLanePriority);
1247 + executionContext = prevExecutionContext;
1248 + // Flush the immediate callbacks that were scheduled during this batch.
1249 + // Note that this will happen even if batchedUpdates is higher up
1250 + // the stack.
1251 + flushSyncCallbackQueue();
1252 }
1253 }
1254
1255 export function flushControlled(fn: () => mixed): void {
1256 const prevExecutionContext = executionContext;
1257 executionContext |= BatchedContext;
1322 - if (decoupleUpdatePriorityFromScheduler) {
1323 - const previousLanePriority = getCurrentUpdateLanePriority();
1324 - try {
1325 - setCurrentUpdateLanePriority(SyncLanePriority);
1326 - runWithPriority(ImmediateSchedulerPriority, fn);
1327 - } finally {
1328 - setCurrentUpdateLanePriority(previousLanePriority);
1258 + const previousLanePriority = getCurrentUpdateLanePriority();
1259 + try {
1260 + setCurrentUpdateLanePriority(SyncLanePriority);
1261 + runWithPriority(ImmediateSchedulerPriority, fn);
1262 + } finally {
1263 + setCurrentUpdateLanePriority(previousLanePriority);
1264
1330 - executionContext = prevExecutionContext;
1331 - if (executionContext === NoContext) {
1332 - // Flush the immediate callbacks that were scheduled during this batch
1333 - resetRenderTimer();
1334 - flushSyncCallbackQueue();
1335 - }
1336 - }
1337 - } else {
1338 - try {
1339 - runWithPriority(ImmediateSchedulerPriority, fn);
1340 - } finally {
1341 - executionContext = prevExecutionContext;
1342 - if (executionContext === NoContext) {
1343 - // Flush the immediate callbacks that were scheduled during this batch
1344 - resetRenderTimer();
1345 - flushSyncCallbackQueue();
1346 - }
1265 + executionContext = prevExecutionContext;
1266 + if (executionContext === NoContext) {
1267 + // Flush the immediate callbacks that were scheduled during this batch
1268 + resetRenderTimer();
1269 + flushSyncCallbackQueue();
1270 }
1271 }
1272 }
@@ -1954,11 +1877,8 @@ function commitRootImpl(root, renderPriorityLevel) {
1877 NoFlags;
1878
1879 if (subtreeHasEffects || rootHasEffect) {
1957 - let previousLanePriority;
1958 - if (decoupleUpdatePriorityFromScheduler) {
1959 - previousLanePriority = getCurrentUpdateLanePriority();
1960 - setCurrentUpdateLanePriority(SyncLanePriority);
1961 - }
1880 + const previousLanePriority = getCurrentUpdateLanePriority();
1881 + setCurrentUpdateLanePriority(SyncLanePriority);
1882
1883 const prevExecutionContext = executionContext;
1884 executionContext |= CommitContext;
@@ -2040,7 +1960,7 @@ function commitRootImpl(root, renderPriorityLevel) {
1960 }
1961 executionContext = prevExecutionContext;
1962
2043 - if (decoupleUpdatePriorityFromScheduler && previousLanePriority != null) {
1963 + if (previousLanePriority != null) {
1964 // Reset the priority to the previous non-sync value.
1965 setCurrentUpdateLanePriority(previousLanePriority);
1966 }
@@ -2183,18 +2103,14 @@ export function flushPassiveEffects(): boolean {
2103 ? NormalSchedulerPriority
2104 : pendingPassiveEffectsRenderPriority;
2105 pendingPassiveEffectsRenderPriority = NoSchedulerPriority;
2186 - if (decoupleUpdatePriorityFromScheduler) {
2187 - const previousLanePriority = getCurrentUpdateLanePriority();
2188 - try {
2189 - setCurrentUpdateLanePriority(
2190 - schedulerPriorityToLanePriority(priorityLevel),
2191 - );
2192 - return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
2193 - } finally {
2194 - setCurrentUpdateLanePriority(previousLanePriority);
2195 - }
2196 - } else {
2106 + const previousLanePriority = getCurrentUpdateLanePriority();
2107 + try {
2108 + setCurrentUpdateLanePriority(
2109 + schedulerPriorityToLanePriority(priorityLevel),
2110 + );
2111 return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
2112 + } finally {
2113 + setCurrentUpdateLanePriority(previousLanePriority);
2114 }
2115 }
2116 return false;
packages/react-reconciler/src/SchedulerWithReactIntegration.new.js
+26 -56
@@ -15,7 +15,6 @@ import * as Scheduler from 'scheduler';
15 import {__interactionsRef} from 'scheduler/tracing';
16 import {
17 enableSchedulerTracing,
18 - decoupleUpdatePriorityFromScheduler,
18 enableSyncMicroTasks,
19 } from 'shared/ReactFeatureFlags';
20 import invariant from 'shared/invariant';
@@ -184,63 +183,34 @@ function flushSyncCallbackQueueImpl() {
183 // Prevent re-entrancy.
184 isFlushingSyncQueue = true;
185 let i = 0;
187 - if (decoupleUpdatePriorityFromScheduler) {
188 - const previousLanePriority = getCurrentUpdateLanePriority();
189 - try {
190 - const isSync = true;
191 - const queue = syncQueue;
192 - setCurrentUpdateLanePriority(SyncLanePriority);
193 - runWithPriority(ImmediatePriority, () => {
194 - for (; i < queue.length; i++) {
195 - let callback = queue[i];
196 - do {
197 - callback = callback(isSync);
198 - } while (callback !== null);
199 - }
200 - });
201 - syncQueue = null;
202 - } catch (error) {
203 - // If something throws, leave the remaining callbacks on the queue.
204 - if (syncQueue !== null) {
205 - syncQueue = syncQueue.slice(i + 1);
186 + const previousLanePriority = getCurrentUpdateLanePriority();
187 + try {
188 + const isSync = true;
189 + const queue = syncQueue;
190 + setCurrentUpdateLanePriority(SyncLanePriority);
191 + runWithPriority(ImmediatePriority, () => {
192 + for (; i < queue.length; i++) {
193 + let callback = queue[i];
194 + do {
195 + callback = callback(isSync);
196 + } while (callback !== null);
197 }
207 - // Resume flushing in the next tick
208 - Scheduler_scheduleCallback(
209 - Scheduler_ImmediatePriority,
210 - flushSyncCallbackQueue,
211 - );
212 - throw error;
213 - } finally {
214 - setCurrentUpdateLanePriority(previousLanePriority);
215 - isFlushingSyncQueue = false;
216 - }
217 - } else {
218 - try {
219 - const isSync = true;
220 - const queue = syncQueue;
221 - runWithPriority(ImmediatePriority, () => {
222 - for (; i < queue.length; i++) {
223 - let callback = queue[i];
224 - do {
225 - callback = callback(isSync);
226 - } while (callback !== null);
227 - }
228 - });
229 - syncQueue = null;
230 - } catch (error) {
231 - // If something throws, leave the remaining callbacks on the queue.
232 - if (syncQueue !== null) {
233 - syncQueue = syncQueue.slice(i + 1);
234 - }
235 - // Resume flushing in the next tick
236 - Scheduler_scheduleCallback(
237 - Scheduler_ImmediatePriority,
238 - flushSyncCallbackQueue,
239 - );
240 - throw error;
241 - } finally {
242 - isFlushingSyncQueue = false;
198 + });
199 + syncQueue = null;
200 + } catch (error) {
201 + // If something throws, leave the remaining callbacks on the queue.
202 + if (syncQueue !== null) {
203 + syncQueue = syncQueue.slice(i + 1);
204 }
205 + // Resume flushing in the next tick
206 + Scheduler_scheduleCallback(
207 + Scheduler_ImmediatePriority,
208 + flushSyncCallbackQueue,
209 + );
210 + throw error;
211 + } finally {
212 + setCurrentUpdateLanePriority(previousLanePriority);
213 + isFlushingSyncQueue = false;
214 }
215 }
216 }
packages/react-reconciler/src/SchedulerWithReactIntegration.old.js
+26 -56
@@ -15,7 +15,6 @@ import * as Scheduler from 'scheduler';
15 import {__interactionsRef} from 'scheduler/tracing';
16 import {
17 enableSchedulerTracing,
18 - decoupleUpdatePriorityFromScheduler,
18 enableSyncMicroTasks,
19 } from 'shared/ReactFeatureFlags';
20 import invariant from 'shared/invariant';
@@ -184,63 +183,34 @@ function flushSyncCallbackQueueImpl() {
183 // Prevent re-entrancy.
184 isFlushingSyncQueue = true;
185 let i = 0;
187 - if (decoupleUpdatePriorityFromScheduler) {
188 - const previousLanePriority = getCurrentUpdateLanePriority();
189 - try {
190 - const isSync = true;
191 - const queue = syncQueue;
192 - setCurrentUpdateLanePriority(SyncLanePriority);
193 - runWithPriority(ImmediatePriority, () => {
194 - for (; i < queue.length; i++) {
195 - let callback = queue[i];
196 - do {
197 - callback = callback(isSync);
198 - } while (callback !== null);
199 - }
200 - });
201 - syncQueue = null;
202 - } catch (error) {
203 - // If something throws, leave the remaining callbacks on the queue.
204 - if (syncQueue !== null) {
205 - syncQueue = syncQueue.slice(i + 1);
186 + const previousLanePriority = getCurrentUpdateLanePriority();
187 + try {
188 + const isSync = true;
189 + const queue = syncQueue;
190 + setCurrentUpdateLanePriority(SyncLanePriority);
191 + runWithPriority(ImmediatePriority, () => {
192 + for (; i < queue.length; i++) {
193 + let callback = queue[i];
194 + do {
195 + callback = callback(isSync);
196 + } while (callback !== null);
197 }
207 - // Resume flushing in the next tick
208 - Scheduler_scheduleCallback(
209 - Scheduler_ImmediatePriority,
210 - flushSyncCallbackQueue,
211 - );
212 - throw error;
213 - } finally {
214 - setCurrentUpdateLanePriority(previousLanePriority);
215 - isFlushingSyncQueue = false;
216 - }
217 - } else {
218 - try {
219 - const isSync = true;
220 - const queue = syncQueue;
221 - runWithPriority(ImmediatePriority, () => {
222 - for (; i < queue.length; i++) {
223 - let callback = queue[i];
224 - do {
225 - callback = callback(isSync);
226 - } while (callback !== null);
227 - }
228 - });
229 - syncQueue = null;
230 - } catch (error) {
231 - // If something throws, leave the remaining callbacks on the queue.
232 - if (syncQueue !== null) {
233 - syncQueue = syncQueue.slice(i + 1);
234 - }
235 - // Resume flushing in the next tick
236 - Scheduler_scheduleCallback(
237 - Scheduler_ImmediatePriority,
238 - flushSyncCallbackQueue,
239 - );
240 - throw error;
241 - } finally {
242 - isFlushingSyncQueue = false;
198 + });
199 + syncQueue = null;
200 + } catch (error) {
201 + // If something throws, leave the remaining callbacks on the queue.
202 + if (syncQueue !== null) {
203 + syncQueue = syncQueue.slice(i + 1);
204 }
205 + // Resume flushing in the next tick
206 + Scheduler_scheduleCallback(
207 + Scheduler_ImmediatePriority,
208 + flushSyncCallbackQueue,
209 + );
210 + throw error;
211 + } finally {
212 + setCurrentUpdateLanePriority(previousLanePriority);
213 + isFlushingSyncQueue = false;
214 }
215 }
216 }
packages/react/src/__tests__/ReactDOMTracing-test.internal.js
-2
@@ -428,7 +428,6 @@ describe('ReactDOMTracing', () => {
428 });
429
430 // @gate experimental
431 - // @gate enableNativeEventPriorityInference
431 it('should properly trace interactions when there is work of interleaved priorities', () => {
432 const Child = () => {
433 Scheduler.unstable_yieldValue('Child');
@@ -550,7 +549,6 @@ describe('ReactDOMTracing', () => {
549 });
550
551 // @gate experimental
553 - // @gate enableNativeEventPriorityInference
552 it('should properly trace interactions through a multi-pass SuspenseList render', () => {
553 const SuspenseList = React.SuspenseList;
554 const Suspense = React.Suspense;
packages/shared/ReactFeatureFlags.js
-3
@@ -142,9 +142,6 @@ export const enableLegacyFBSupport = false;
142 // new behavior.
143 export const deferRenderPhaseUpdateToNextBatch = true;
144
145 -// Replacement for runWithPriority in React internals.
146 -export const decoupleUpdatePriorityFromScheduler = false;
147 -
145 export const enableDiscreteEventFlushingChange = false;
146
147 export const enableUseRefAccessWarning = false;
packages/shared/forks/ReactFeatureFlags.native-fb.js
-1
@@ -49,7 +49,6 @@ export const skipUnmountedBoundaries = false;
49
50 export const enableNewReconciler = false;
51 export const deferRenderPhaseUpdateToNextBatch = true;
52 -export const decoupleUpdatePriorityFromScheduler = false;
52 export const enableDiscreteEventFlushingChange = false;
53
54 export const enableStrictEffects = false;
packages/shared/forks/ReactFeatureFlags.native-oss.js
-1
@@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = false;
48
49 export const enableNewReconciler = false;
50 export const deferRenderPhaseUpdateToNextBatch = true;
51 -export const decoupleUpdatePriorityFromScheduler = false;
51 export const enableDiscreteEventFlushingChange = false;
52
53 export const enableStrictEffects = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.js
-1
@@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = false;
48
49 export const enableNewReconciler = false;
50 export const deferRenderPhaseUpdateToNextBatch = true;
51 -export const decoupleUpdatePriorityFromScheduler = false;
51 export const enableDiscreteEventFlushingChange = false;
52
53 export const enableStrictEffects = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.native.js
-1
@@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = false;
48
49 export const enableNewReconciler = false;
50 export const deferRenderPhaseUpdateToNextBatch = true;
51 -export const decoupleUpdatePriorityFromScheduler = false;
51 export const enableDiscreteEventFlushingChange = false;
52
53 export const enableStrictEffects = false;
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
-1
@@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = false;
48
49 export const enableNewReconciler = false;
50 export const deferRenderPhaseUpdateToNextBatch = true;
51 -export const decoupleUpdatePriorityFromScheduler = false;
51 export const enableDiscreteEventFlushingChange = false;
52
53 export const enableStrictEffects = true;
packages/shared/forks/ReactFeatureFlags.testing.js
-1
@@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = false;
48
49 export const enableNewReconciler = false;
50 export const deferRenderPhaseUpdateToNextBatch = true;
51 -export const decoupleUpdatePriorityFromScheduler = false;
51 export const enableDiscreteEventFlushingChange = false;
52
53 export const enableStrictEffects = false;
packages/shared/forks/ReactFeatureFlags.testing.www.js
-1
@@ -48,7 +48,6 @@ export const skipUnmountedBoundaries = true;
48
49 export const enableNewReconciler = false;
50 export const deferRenderPhaseUpdateToNextBatch = true;
51 -export const decoupleUpdatePriorityFromScheduler = false;
51 export const enableDiscreteEventFlushingChange = true;
52
53 export const enableStrictEffects = false;
packages/shared/forks/ReactFeatureFlags.www-dynamic.js
-1
@@ -17,7 +17,6 @@ export const warnAboutSpreadingKeyToJSX = __VARIANT__;
17 export const disableInputAttributeSyncing = __VARIANT__;
18 export const enableFilterEmptyStringAttributesDOM = __VARIANT__;
19 export const enableLegacyFBSupport = __VARIANT__;
20 -export const decoupleUpdatePriorityFromScheduler = __VARIANT__;
20 export const skipUnmountedBoundaries = __VARIANT__;
21
22 // Enable this flag to help with concurrent mode debugging.
packages/shared/forks/ReactFeatureFlags.www.js
-1
@@ -24,7 +24,6 @@ export const {
24 enableFilterEmptyStringAttributesDOM,
25 enableLegacyFBSupport,
26 deferRenderPhaseUpdateToNextBatch,
27 - decoupleUpdatePriorityFromScheduler,
27 enableDebugTracing,
28 skipUnmountedBoundaries,
29 enableStrictEffects,