GeezerVison is showing github.com — Add feature flag for setting update lane priority (#19401) · react/react@32ff428
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 +23-7Lines changed: 23 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,7 +38,10 @@ import { | 38 | 38 | import getEventTarget from './getEventTarget'; | 39 | 39 | import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree'; | 40 | 40 |
| 41 | | -import {enableLegacyFBSupport} from 'shared/ReactFeatureFlags'; | | 41 | +import { | | 42 | + enableLegacyFBSupport, | | 43 | + decoupleUpdatePriorityFromScheduler, | | 44 | +} from 'shared/ReactFeatureFlags'; | 42 | 45 | import { | 43 | 46 | UserBlockingEvent, | 44 | 47 | ContinuousEvent, | @@ -147,10 +150,25 @@ function dispatchUserBlockingUpdate( | 147 | 150 | container, | 148 | 151 | nativeEvent, | 149 | 152 | ) { | 150 | | - // TODO: Double wrapping is necessary while we decouple Scheduler priority. | 151 | | - const previousPriority = getCurrentUpdateLanePriority(); | 152 | | - try { | 153 | | - setCurrentUpdateLanePriority(InputContinuousLanePriority); | | 153 | + if (decoupleUpdatePriorityFromScheduler) { | | 154 | + const previousPriority = getCurrentUpdateLanePriority(); | | 155 | + try { | | 156 | + // TODO: Double wrapping is necessary while we decouple Scheduler priority. | | 157 | + setCurrentUpdateLanePriority(InputContinuousLanePriority); | | 158 | + runWithPriority( | | 159 | + UserBlockingPriority, | | 160 | + dispatchEvent.bind( | | 161 | + null, | | 162 | + domEventName, | | 163 | + eventSystemFlags, | | 164 | + container, | | 165 | + nativeEvent, | | 166 | + ), | | 167 | + ); | | 168 | + } finally { | | 169 | + setCurrentUpdateLanePriority(previousPriority); | | 170 | + } | | 171 | + } else { | 154 | 172 | runWithPriority( | 155 | 173 | UserBlockingPriority, | 156 | 174 | dispatchEvent.bind( | @@ -161,8 +179,6 @@ function dispatchUserBlockingUpdate( | 161 | 179 | nativeEvent, | 162 | 180 | ), | 163 | 181 | ); | 164 | | - } finally { | 165 | | - setCurrentUpdateLanePriority(previousPriority); | 166 | 182 | } | 167 | 183 | } | 168 | 184 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHooks.new.js +57-26Lines changed: 57 additions & 26 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,6 +26,7 @@ import { | 26 | 26 | enableDebugTracing, | 27 | 27 | enableSchedulingProfiler, | 28 | 28 | enableNewReconciler, | | 29 | + decoupleUpdatePriorityFromScheduler, | 29 | 30 | } from 'shared/ReactFeatureFlags'; | 30 | 31 |
| 31 | 32 | import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode'; | @@ -1506,34 +1507,64 @@ function rerenderDeferredValue<T>( | 1506 | 1507 |
| 1507 | 1508 | function startTransition(setPending, config, callback) { | 1508 | 1509 | const priorityLevel = getCurrentPriorityLevel(); | 1509 | | - const previousLanePriority = getCurrentUpdateLanePriority(); | 1510 | | - setCurrentUpdateLanePriority( | 1511 | | - higherLanePriority(previousLanePriority, InputContinuousLanePriority), | 1512 | | - ); | 1513 | | - runWithPriority( | 1514 | | - priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, | 1515 | | - () => { | 1516 | | - setPending(true); | 1517 | | - }, | 1518 | | - ); | | 1510 | + if (decoupleUpdatePriorityFromScheduler) { | | 1511 | + const previousLanePriority = getCurrentUpdateLanePriority(); | | 1512 | + setCurrentUpdateLanePriority( | | 1513 | + higherLanePriority(previousLanePriority, InputContinuousLanePriority), | | 1514 | + ); | 1519 | 1515 |
| 1520 | | - // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. | 1521 | | - setCurrentUpdateLanePriority(DefaultLanePriority); | | 1516 | + runWithPriority( | | 1517 | + priorityLevel < UserBlockingPriority | | 1518 | + ? UserBlockingPriority | | 1519 | + : priorityLevel, | | 1520 | + () => { | | 1521 | + setPending(true); | | 1522 | + }, | | 1523 | + ); | 1522 | 1524 |
| 1523 | | - runWithPriority( | 1524 | | - priorityLevel > NormalPriority ? NormalPriority : priorityLevel, | 1525 | | - () => { | 1526 | | - const previousConfig = ReactCurrentBatchConfig.suspense; | 1527 | | - ReactCurrentBatchConfig.suspense = config === undefined ? null : config; | 1528 | | - try { | 1529 | | - setPending(false); | 1530 | | - callback(); | 1531 | | - } finally { | 1532 | | - setCurrentUpdateLanePriority(previousLanePriority); | 1533 | | - ReactCurrentBatchConfig.suspense = previousConfig; | 1534 | | - } | 1535 | | - }, | 1536 | | - ); | | 1525 | + // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. | | 1526 | + setCurrentUpdateLanePriority(DefaultLanePriority); | | 1527 | + | | 1528 | + runWithPriority( | | 1529 | + priorityLevel > NormalPriority ? NormalPriority : priorityLevel, | | 1530 | + () => { | | 1531 | + const previousConfig = ReactCurrentBatchConfig.suspense; | | 1532 | + ReactCurrentBatchConfig.suspense = config === undefined ? null : config; | | 1533 | + try { | | 1534 | + setPending(false); | | 1535 | + callback(); | | 1536 | + } finally { | | 1537 | + if (decoupleUpdatePriorityFromScheduler) { | | 1538 | + setCurrentUpdateLanePriority(previousLanePriority); | | 1539 | + } | | 1540 | + ReactCurrentBatchConfig.suspense = previousConfig; | | 1541 | + } | | 1542 | + }, | | 1543 | + ); | | 1544 | + } else { | | 1545 | + runWithPriority( | | 1546 | + priorityLevel < UserBlockingPriority | | 1547 | + ? UserBlockingPriority | | 1548 | + : priorityLevel, | | 1549 | + () => { | | 1550 | + setPending(true); | | 1551 | + }, | | 1552 | + ); | | 1553 | + | | 1554 | + runWithPriority( | | 1555 | + priorityLevel > NormalPriority ? NormalPriority : priorityLevel, | | 1556 | + () => { | | 1557 | + const previousConfig = ReactCurrentBatchConfig.suspense; | | 1558 | + ReactCurrentBatchConfig.suspense = config === undefined ? null : config; | | 1559 | + try { | | 1560 | + setPending(false); | | 1561 | + callback(); | | 1562 | + } finally { | | 1563 | + ReactCurrentBatchConfig.suspense = previousConfig; | | 1564 | + } | | 1565 | + }, | | 1566 | + ); | | 1567 | + } | 1537 | 1568 | } | 1538 | 1569 |
| 1539 | 1570 | function mountTransition( | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHooks.old.js +57-26Lines changed: 57 additions & 26 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,6 +26,7 @@ import { | 26 | 26 | enableDebugTracing, | 27 | 27 | enableSchedulingProfiler, | 28 | 28 | enableNewReconciler, | | 29 | + decoupleUpdatePriorityFromScheduler, | 29 | 30 | } from 'shared/ReactFeatureFlags'; | 30 | 31 |
| 31 | 32 | import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode'; | @@ -1505,34 +1506,64 @@ function rerenderDeferredValue<T>( | 1505 | 1506 |
| 1506 | 1507 | function startTransition(setPending, config, callback) { | 1507 | 1508 | const priorityLevel = getCurrentPriorityLevel(); | 1508 | | - const previousLanePriority = getCurrentUpdateLanePriority(); | 1509 | | - setCurrentUpdateLanePriority( | 1510 | | - higherLanePriority(previousLanePriority, InputContinuousLanePriority), | 1511 | | - ); | 1512 | | - runWithPriority( | 1513 | | - priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel, | 1514 | | - () => { | 1515 | | - setPending(true); | 1516 | | - }, | 1517 | | - ); | | 1509 | + if (decoupleUpdatePriorityFromScheduler) { | | 1510 | + const previousLanePriority = getCurrentUpdateLanePriority(); | | 1511 | + setCurrentUpdateLanePriority( | | 1512 | + higherLanePriority(previousLanePriority, InputContinuousLanePriority), | | 1513 | + ); | 1518 | 1514 |
| 1519 | | - // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. | 1520 | | - setCurrentUpdateLanePriority(DefaultLanePriority); | | 1515 | + runWithPriority( | | 1516 | + priorityLevel < UserBlockingPriority | | 1517 | + ? UserBlockingPriority | | 1518 | + : priorityLevel, | | 1519 | + () => { | | 1520 | + setPending(true); | | 1521 | + }, | | 1522 | + ); | 1521 | 1523 |
| 1522 | | - runWithPriority( | 1523 | | - priorityLevel > NormalPriority ? NormalPriority : priorityLevel, | 1524 | | - () => { | 1525 | | - const previousConfig = ReactCurrentBatchConfig.suspense; | 1526 | | - ReactCurrentBatchConfig.suspense = config === undefined ? null : config; | 1527 | | - try { | 1528 | | - setPending(false); | 1529 | | - callback(); | 1530 | | - } finally { | 1531 | | - setCurrentUpdateLanePriority(previousLanePriority); | 1532 | | - ReactCurrentBatchConfig.suspense = previousConfig; | 1533 | | - } | 1534 | | - }, | 1535 | | - ); | | 1524 | + // If there's no SuspenseConfig set, we'll use the DefaultLanePriority for this transition. | | 1525 | + setCurrentUpdateLanePriority(DefaultLanePriority); | | 1526 | + | | 1527 | + runWithPriority( | | 1528 | + priorityLevel > NormalPriority ? NormalPriority : priorityLevel, | | 1529 | + () => { | | 1530 | + const previousConfig = ReactCurrentBatchConfig.suspense; | | 1531 | + ReactCurrentBatchConfig.suspense = config === undefined ? null : config; | | 1532 | + try { | | 1533 | + setPending(false); | | 1534 | + callback(); | | 1535 | + } finally { | | 1536 | + if (decoupleUpdatePriorityFromScheduler) { | | 1537 | + setCurrentUpdateLanePriority(previousLanePriority); | | 1538 | + } | | 1539 | + ReactCurrentBatchConfig.suspense = previousConfig; | | 1540 | + } | | 1541 | + }, | | 1542 | + ); | | 1543 | + } else { | | 1544 | + runWithPriority( | | 1545 | + priorityLevel < UserBlockingPriority | | 1546 | + ? UserBlockingPriority | | 1547 | + : priorityLevel, | | 1548 | + () => { | | 1549 | + setPending(true); | | 1550 | + }, | | 1551 | + ); | | 1552 | + | | 1553 | + runWithPriority( | | 1554 | + priorityLevel > NormalPriority ? NormalPriority : priorityLevel, | | 1555 | + () => { | | 1556 | + const previousConfig = ReactCurrentBatchConfig.suspense; | | 1557 | + ReactCurrentBatchConfig.suspense = config === undefined ? null : config; | | 1558 | + try { | | 1559 | + setPending(false); | | 1560 | + callback(); | | 1561 | + } finally { | | 1562 | + ReactCurrentBatchConfig.suspense = previousConfig; | | 1563 | + } | | 1564 | + }, | | 1565 | + ); | | 1566 | + } | 1536 | 1567 | } | 1537 | 1568 |
| 1538 | 1569 | function mountTransition( | |
|