GeezerVison is showing github.com — Remove runWithPriority internally · react/react@41e62e7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/events/ReactDOMEventListener.js +1-20Lines changed: 1 addition & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,10 +12,6 @@ import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes'; | 12 | 12 | import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig'; | 13 | 13 | import type {DOMEventName} from '../events/DOMEventNames'; | 14 | 14 |
| 15 | | -// Intentionally not named imports because Rollup would use dynamic dispatch for | 16 | | -// CommonJS interop named imports. | 17 | | -import * as Scheduler from 'scheduler'; | 18 | | - | 19 | 15 | import { | 20 | 16 | isReplayableDiscreteEvent, | 21 | 17 | queueDiscreteEvent, | @@ -89,11 +85,6 @@ const getCurrentPriorityLevel = enableNewReconciler | 89 | 85 | ? getCurrentPriorityLevel_new | 90 | 86 | : getCurrentPriorityLevel_old; | 91 | 87 |
| 92 | | -const { | 93 | | - unstable_UserBlockingPriority: UserBlockingPriority, | 94 | | - unstable_runWithPriority: runWithPriority, | 95 | | -} = Scheduler; | 96 | | - | 97 | 88 | // TODO: can we stop exporting these? | 98 | 89 | export let _enabled = true; | 99 | 90 |
| @@ -178,18 +169,8 @@ function dispatchContinuousEvent( | 178 | 169 | ) { | 179 | 170 | const previousPriority = getCurrentUpdateLanePriority(); | 180 | 171 | try { | 181 | | - // TODO: Double wrapping is necessary while we decouple Scheduler priority. | 182 | 172 | setCurrentUpdateLanePriority(InputContinuousLanePriority); | 183 | | - runWithPriority( | 184 | | - UserBlockingPriority, | 185 | | - dispatchEvent.bind( | 186 | | - null, | 187 | | - domEventName, | 188 | | - eventSystemFlags, | 189 | | - container, | 190 | | - nativeEvent, | 191 | | - ), | 192 | | - ); | | 173 | + dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent); | 193 | 174 | } finally { | 194 | 175 | setCurrentUpdateLanePriority(previousPriority); | 195 | 176 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHooks.new.js +10-27Lines changed: 10 additions & 27 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -87,12 +87,6 @@ import { | 87 | 87 | markWorkInProgressReceivedUpdate, | 88 | 88 | checkIfWorkInProgressReceivedUpdate, | 89 | 89 | } from './ReactFiberBeginWork.new'; | 90 | | -import { | 91 | | - UserBlockingPriority, | 92 | | - NormalPriority, | 93 | | - runWithPriority, | 94 | | - getCurrentPriorityLevel, | 95 | | -} from './SchedulerWithReactIntegration.new'; | 96 | 90 | import {getIsHydrating} from './ReactFiberHydrationContext.new'; | 97 | 91 | import { | 98 | 92 | makeClientId, | @@ -1711,38 +1705,27 @@ function rerenderDeferredValue<T>(value: T): T { | 1711 | 1705 | } | 1712 | 1706 |
| 1713 | 1707 | function startTransition(setPending, callback) { | 1714 | | - const priorityLevel = getCurrentPriorityLevel(); | 1715 | 1708 | const previousLanePriority = getCurrentUpdateLanePriority(); | 1716 | 1709 | setCurrentUpdateLanePriority( | 1717 | 1710 | higherLanePriority(previousLanePriority, InputContinuousLanePriority), | 1718 | 1711 | ); | 1719 | 1712 |
| 1720 | | - runWithPriority( | 1721 | | - priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, | 1722 | | - () => { | 1723 | | - setPending(true); | 1724 | | - }, | 1725 | | - ); | | 1713 | + setPending(true); | 1726 | 1714 |
| 1727 | 1715 | // TODO: Can remove this. Was only necessary because we used to give | 1728 | 1716 | // different behavior to transitions without a config object. Now they are | 1729 | 1717 | // all treated the same. | 1730 | 1718 | setCurrentUpdateLanePriority(DefaultLanePriority); | 1731 | 1719 |
| 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 | | - ); | | 1720 | + const prevTransition = ReactCurrentBatchConfig.transition; | | 1721 | + ReactCurrentBatchConfig.transition = 1; | | 1722 | + try { | | 1723 | + setPending(false); | | 1724 | + callback(); | | 1725 | + } finally { | | 1726 | + setCurrentUpdateLanePriority(previousLanePriority); | | 1727 | + ReactCurrentBatchConfig.transition = prevTransition; | | 1728 | + } | 1746 | 1729 | } | 1747 | 1730 |
| 1748 | 1731 | function mountTransition(): [(() => void) => void, boolean] { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHooks.old.js +10-27Lines changed: 10 additions & 27 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -87,12 +87,6 @@ import { | 87 | 87 | markWorkInProgressReceivedUpdate, | 88 | 88 | checkIfWorkInProgressReceivedUpdate, | 89 | 89 | } from './ReactFiberBeginWork.old'; | 90 | | -import { | 91 | | - UserBlockingPriority, | 92 | | - NormalPriority, | 93 | | - runWithPriority, | 94 | | - getCurrentPriorityLevel, | 95 | | -} from './SchedulerWithReactIntegration.old'; | 96 | 90 | import {getIsHydrating} from './ReactFiberHydrationContext.old'; | 97 | 91 | import { | 98 | 92 | makeClientId, | @@ -1711,38 +1705,27 @@ function rerenderDeferredValue<T>(value: T): T { | 1711 | 1705 | } | 1712 | 1706 |
| 1713 | 1707 | function startTransition(setPending, callback) { | 1714 | | - const priorityLevel = getCurrentPriorityLevel(); | 1715 | 1708 | const previousLanePriority = getCurrentUpdateLanePriority(); | 1716 | 1709 | setCurrentUpdateLanePriority( | 1717 | 1710 | higherLanePriority(previousLanePriority, InputContinuousLanePriority), | 1718 | 1711 | ); | 1719 | 1712 |
| 1720 | | - runWithPriority( | 1721 | | - priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, | 1722 | | - () => { | 1723 | | - setPending(true); | 1724 | | - }, | 1725 | | - ); | | 1713 | + setPending(true); | 1726 | 1714 |
| 1727 | 1715 | // TODO: Can remove this. Was only necessary because we used to give | 1728 | 1716 | // different behavior to transitions without a config object. Now they are | 1729 | 1717 | // all treated the same. | 1730 | 1718 | setCurrentUpdateLanePriority(DefaultLanePriority); | 1731 | 1719 |
| 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 | | - ); | | 1720 | + const prevTransition = ReactCurrentBatchConfig.transition; | | 1721 | + ReactCurrentBatchConfig.transition = 1; | | 1722 | + try { | | 1723 | + setPending(false); | | 1724 | + callback(); | | 1725 | + } finally { | | 1726 | + setCurrentUpdateLanePriority(previousLanePriority); | | 1727 | + ReactCurrentBatchConfig.transition = prevTransition; | | 1728 | + } | 1746 | 1729 | } | 1747 | 1730 |
| 1748 | 1731 | function mountTransition(): [(() => void) => void, boolean] { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.new.js +6-13Lines changed: 6 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,7 +41,6 @@ import { | 41 | 41 | scheduleCallback, | 42 | 42 | cancelCallback, | 43 | 43 | getCurrentPriorityLevel, | 44 | | - runWithPriority, | 45 | 44 | shouldYield, | 46 | 45 | requestPaint, | 47 | 46 | now, | @@ -1124,7 +1123,7 @@ export function deferredUpdates<A>(fn: () => A): A { | 1124 | 1123 | const previousLanePriority = getCurrentUpdateLanePriority(); | 1125 | 1124 | try { | 1126 | 1125 | setCurrentUpdateLanePriority(DefaultLanePriority); | 1127 | | - return runWithPriority(NormalSchedulerPriority, fn); | | 1126 | + return fn(); | 1128 | 1127 | } finally { | 1129 | 1128 | setCurrentUpdateLanePriority(previousLanePriority); | 1130 | 1129 | } | @@ -1176,7 +1175,7 @@ export function batchedEventUpdates<A, R>(fn: A => R, a: A): R { | 1176 | 1175 | } | 1177 | 1176 |
| 1178 | 1177 | export function discreteUpdates<A, B, C, D, R>( | 1179 | | - fn: (A, B, C) => R, | | 1178 | + fn: (A, B, C, D) => R, | 1180 | 1179 | a: A, | 1181 | 1180 | b: B, | 1182 | 1181 | c: C, | @@ -1188,10 +1187,7 @@ export function discreteUpdates<A, B, C, D, R>( | 1188 | 1187 | const previousLanePriority = getCurrentUpdateLanePriority(); | 1189 | 1188 | try { | 1190 | 1189 | setCurrentUpdateLanePriority(InputDiscreteLanePriority); | 1191 | | - return runWithPriority( | 1192 | | - UserBlockingSchedulerPriority, | 1193 | | - fn.bind(null, a, b, c, d), | 1194 | | - ); | | 1190 | + return fn(a, b, c, d); | 1195 | 1191 | } finally { | 1196 | 1192 | setCurrentUpdateLanePriority(previousLanePriority); | 1197 | 1193 | executionContext = prevExecutionContext; | @@ -1237,7 +1233,7 @@ export function flushSync<A, R>(fn: A => R, a: A): R { | 1237 | 1233 | try { | 1238 | 1234 | setCurrentUpdateLanePriority(SyncLanePriority); | 1239 | 1235 | if (fn) { | 1240 | | - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); | | 1236 | + return fn(a); | 1241 | 1237 | } else { | 1242 | 1238 | return (undefined: $FlowFixMe); | 1243 | 1239 | } | @@ -1257,7 +1253,7 @@ export function flushControlled(fn: () => mixed): void { | 1257 | 1253 | const previousLanePriority = getCurrentUpdateLanePriority(); | 1258 | 1254 | try { | 1259 | 1255 | setCurrentUpdateLanePriority(SyncLanePriority); | 1260 | | - runWithPriority(ImmediateSchedulerPriority, fn); | | 1256 | + fn(); | 1261 | 1257 | } finally { | 1262 | 1258 | setCurrentUpdateLanePriority(previousLanePriority); | 1263 | 1259 |
| @@ -1753,10 +1749,7 @@ function commitRoot(root) { | 1753 | 1749 | const previousUpdateLanePriority = getCurrentUpdateLanePriority(); | 1754 | 1750 | try { | 1755 | 1751 | setCurrentUpdateLanePriority(SyncLanePriority); | 1756 | | - runWithPriority( | 1757 | | - ImmediateSchedulerPriority, | 1758 | | - commitRootImpl.bind(null, root, previousUpdateLanePriority), | 1759 | | - ); | | 1752 | + commitRootImpl(root, previousUpdateLanePriority); | 1760 | 1753 | } finally { | 1761 | 1754 | setCurrentUpdateLanePriority(previousUpdateLanePriority); | 1762 | 1755 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.old.js +6-13Lines changed: 6 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,7 +41,6 @@ import { | 41 | 41 | scheduleCallback, | 42 | 42 | cancelCallback, | 43 | 43 | getCurrentPriorityLevel, | 44 | | - runWithPriority, | 45 | 44 | shouldYield, | 46 | 45 | requestPaint, | 47 | 46 | now, | @@ -1124,7 +1123,7 @@ export function deferredUpdates<A>(fn: () => A): A { | 1124 | 1123 | const previousLanePriority = getCurrentUpdateLanePriority(); | 1125 | 1124 | try { | 1126 | 1125 | setCurrentUpdateLanePriority(DefaultLanePriority); | 1127 | | - return runWithPriority(NormalSchedulerPriority, fn); | | 1126 | + return fn(); | 1128 | 1127 | } finally { | 1129 | 1128 | setCurrentUpdateLanePriority(previousLanePriority); | 1130 | 1129 | } | @@ -1176,7 +1175,7 @@ export function batchedEventUpdates<A, R>(fn: A => R, a: A): R { | 1176 | 1175 | } | 1177 | 1176 |
| 1178 | 1177 | export function discreteUpdates<A, B, C, D, R>( | 1179 | | - fn: (A, B, C) => R, | | 1178 | + fn: (A, B, C, D) => R, | 1180 | 1179 | a: A, | 1181 | 1180 | b: B, | 1182 | 1181 | c: C, | @@ -1188,10 +1187,7 @@ export function discreteUpdates<A, B, C, D, R>( | 1188 | 1187 | const previousLanePriority = getCurrentUpdateLanePriority(); | 1189 | 1188 | try { | 1190 | 1189 | setCurrentUpdateLanePriority(InputDiscreteLanePriority); | 1191 | | - return runWithPriority( | 1192 | | - UserBlockingSchedulerPriority, | 1193 | | - fn.bind(null, a, b, c, d), | 1194 | | - ); | | 1190 | + return fn(a, b, c, d); | 1195 | 1191 | } finally { | 1196 | 1192 | setCurrentUpdateLanePriority(previousLanePriority); | 1197 | 1193 | executionContext = prevExecutionContext; | @@ -1237,7 +1233,7 @@ export function flushSync<A, R>(fn: A => R, a: A): R { | 1237 | 1233 | try { | 1238 | 1234 | setCurrentUpdateLanePriority(SyncLanePriority); | 1239 | 1235 | if (fn) { | 1240 | | - return runWithPriority(ImmediateSchedulerPriority, fn.bind(null, a)); | | 1236 | + return fn(a); | 1241 | 1237 | } else { | 1242 | 1238 | return (undefined: $FlowFixMe); | 1243 | 1239 | } | @@ -1257,7 +1253,7 @@ export function flushControlled(fn: () => mixed): void { | 1257 | 1253 | const previousLanePriority = getCurrentUpdateLanePriority(); | 1258 | 1254 | try { | 1259 | 1255 | setCurrentUpdateLanePriority(SyncLanePriority); | 1260 | | - runWithPriority(ImmediateSchedulerPriority, fn); | | 1256 | + fn(); | 1261 | 1257 | } finally { | 1262 | 1258 | setCurrentUpdateLanePriority(previousLanePriority); | 1263 | 1259 |
| @@ -1753,10 +1749,7 @@ function commitRoot(root) { | 1753 | 1749 | const previousUpdateLanePriority = getCurrentUpdateLanePriority(); | 1754 | 1750 | try { | 1755 | 1751 | setCurrentUpdateLanePriority(SyncLanePriority); | 1756 | | - runWithPriority( | 1757 | | - ImmediateSchedulerPriority, | 1758 | | - commitRootImpl.bind(null, root, previousUpdateLanePriority), | 1759 | | - ); | | 1752 | + commitRootImpl(root, previousUpdateLanePriority); | 1760 | 1753 | } finally { | 1761 | 1754 | setCurrentUpdateLanePriority(previousUpdateLanePriority); | 1762 | 1755 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/SchedulerWithReactIntegration.new.js +6-17Lines changed: 6 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,6 @@ import { | 26 | 26 | import {scheduleMicrotask, supportsMicrotasks} from './ReactFiberHostConfig'; | 27 | 27 |
| 28 | 28 | const { | 29 | | - unstable_runWithPriority: Scheduler_runWithPriority, | 30 | 29 | unstable_scheduleCallback: Scheduler_scheduleCallback, | 31 | 30 | unstable_cancelCallback: Scheduler_cancelCallback, | 32 | 31 | unstable_shouldYield: Scheduler_shouldYield, | @@ -123,14 +122,6 @@ function reactPriorityToSchedulerPriority(reactPriorityLevel) { | 123 | 122 | } | 124 | 123 | } | 125 | 124 |
| 126 | | -export function runWithPriority<T>( | 127 | | - reactPriorityLevel: ReactPriorityLevel, | 128 | | - fn: () => T, | 129 | | -): T { | 130 | | - const priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel); | 131 | | - return Scheduler_runWithPriority(priorityLevel, fn); | 132 | | -} | 133 | | - | 134 | 125 | export function scheduleCallback( | 135 | 126 | reactPriorityLevel: ReactPriorityLevel, | 136 | 127 | callback: SchedulerCallback, | @@ -188,14 +179,12 @@ function flushSyncCallbackQueueImpl() { | 188 | 179 | const isSync = true; | 189 | 180 | const queue = syncQueue; | 190 | 181 | 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 | | - } | 198 | | - }); | | 182 | + for (; i < queue.length; i++) { | | 183 | + let callback = queue[i]; | | 184 | + do { | | 185 | + callback = callback(isSync); | | 186 | + } while (callback !== null); | | 187 | + } | 199 | 188 | syncQueue = null; | 200 | 189 | } catch (error) { | 201 | 190 | // If something throws, leave the remaining callbacks on the queue. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/SchedulerWithReactIntegration.old.js +6-17Lines changed: 6 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,6 @@ import { | 26 | 26 | import {scheduleMicrotask, supportsMicrotasks} from './ReactFiberHostConfig'; | 27 | 27 |
| 28 | 28 | const { | 29 | | - unstable_runWithPriority: Scheduler_runWithPriority, | 30 | 29 | unstable_scheduleCallback: Scheduler_scheduleCallback, | 31 | 30 | unstable_cancelCallback: Scheduler_cancelCallback, | 32 | 31 | unstable_shouldYield: Scheduler_shouldYield, | @@ -123,14 +122,6 @@ function reactPriorityToSchedulerPriority(reactPriorityLevel) { | 123 | 122 | } | 124 | 123 | } | 125 | 124 |
| 126 | | -export function runWithPriority<T>( | 127 | | - reactPriorityLevel: ReactPriorityLevel, | 128 | | - fn: () => T, | 129 | | -): T { | 130 | | - const priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel); | 131 | | - return Scheduler_runWithPriority(priorityLevel, fn); | 132 | | -} | 133 | | - | 134 | 125 | export function scheduleCallback( | 135 | 126 | reactPriorityLevel: ReactPriorityLevel, | 136 | 127 | callback: SchedulerCallback, | @@ -188,14 +179,12 @@ function flushSyncCallbackQueueImpl() { | 188 | 179 | const isSync = true; | 189 | 180 | const queue = syncQueue; | 190 | 181 | 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 | | - } | 198 | | - }); | | 182 | + for (; i < queue.length; i++) { | | 183 | + let callback = queue[i]; | | 184 | + do { | | 185 | + callback = callback(isSync); | | 186 | + } while (callback !== null); | | 187 | + } | 199 | 188 | syncQueue = null; | 200 | 189 | } catch (error) { | 201 | 190 | // If something throws, leave the remaining callbacks on the queue. | |
|