GeezerVison is showing github.com — Apply #20778 to new fork, too (#20782) · react/react@3499c34
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/__tests__/ReactDOMServerSelectiveHydration-test.internal.js +19-6Lines changed: 19 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -92,6 +92,21 @@ function dispatchClickEvent(target) { | 92 | 92 | return target.dispatchEvent(mouseOutEvent); | 93 | 93 | } | 94 | 94 |
| | 95 | +// TODO: There's currently no React DOM API to opt into Idle priority updates, | | 96 | +// and there's no native DOM event that maps to idle priority, so this is a | | 97 | +// temporary workaround. Need something like ReactDOM.unstable_IdleUpdates. | | 98 | +function TODO_scheduleIdleDOMSchedulerTask(fn) { | | 99 | + Scheduler.unstable_runWithPriority(Scheduler.unstable_IdlePriority, () => { | | 100 | + const prevEvent = window.event; | | 101 | + window.event = {type: 'message'}; | | 102 | + try { | | 103 | + fn(); | | 104 | + } finally { | | 105 | + window.event = prevEvent; | | 106 | + } | | 107 | + }); | | 108 | +} | | 109 | + | 95 | 110 | describe('ReactDOMServerSelectiveHydration', () => { | 96 | 111 | beforeEach(() => { | 97 | 112 | jest.resetModuleRegistry(); | @@ -889,12 +904,10 @@ describe('ReactDOMServerSelectiveHydration', () => { | 889 | 904 | expect(Scheduler).toFlushAndYieldThrough(['App', 'Commit']); | 890 | 905 |
| 891 | 906 | // Render an update at Idle priority that needs to update A. | 892 | | - Scheduler.unstable_runWithPriority( | 893 | | - Scheduler.unstable_IdlePriority, | 894 | | - () => { | 895 | | - root.render(<App a="AA" />); | 896 | | - }, | 897 | | - ); | | 907 | + | | 908 | + TODO_scheduleIdleDOMSchedulerTask(() => { | | 909 | + root.render(<App a="AA" />); | | 910 | + }); | 898 | 911 |
| 899 | 912 | // Start rendering. This will force the first boundary to hydrate | 900 | 913 | // by scheduling it at one higher pri than Idle. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-noop-renderer/src/ReactNoop.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,6 +41,7 @@ export const { | 41 | 41 | deferredUpdates, | 42 | 42 | unbatchedUpdates, | 43 | 43 | discreteUpdates, | | 44 | + idleUpdates, | 44 | 45 | flushDiscreteUpdates, | 45 | 46 | flushSync, | 46 | 47 | flushPassiveEffects, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-noop-renderer/src/ReactNoopPersistent.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,6 +41,7 @@ export const { | 41 | 41 | deferredUpdates, | 42 | 42 | unbatchedUpdates, | 43 | 43 | discreteUpdates, | | 44 | + idleUpdates, | 44 | 45 | flushDiscreteUpdates, | 45 | 46 | flushSync, | 46 | 47 | flushPassiveEffects, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-noop-renderer/src/createReactNoop.js +21-1Lines changed: 21 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,6 +27,7 @@ import { | 27 | 27 | LegacyRoot, | 28 | 28 | } from 'react-reconciler/src/ReactRootTags'; | 29 | 29 |
| | 30 | +import {enableNativeEventPriorityInference} from 'shared/ReactFeatureFlags'; | 30 | 31 | import ReactSharedInternals from 'shared/ReactSharedInternals'; | 31 | 32 | import enqueueTask from 'shared/enqueueTask'; | 32 | 33 | const {IsSomeRendererActing} = ReactSharedInternals; | @@ -392,7 +393,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 392 | 393 | resetAfterCommit(): void {}, | 393 | 394 |
| 394 | 395 | getCurrentEventPriority() { | 395 | | - return NoopRenderer.DefaultEventPriority; | | 396 | + return currentEventPriority; | 396 | 397 | }, | 397 | 398 |
| 398 | 399 | now: Scheduler.unstable_now, | @@ -587,6 +588,8 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 587 | 588 | const roots = new Map(); | 588 | 589 | const DEFAULT_ROOT_ID = '<default>'; | 589 | 590 |
| | 591 | + let currentEventPriority = NoopRenderer.DefaultEventPriority; | | 592 | + | 590 | 593 | function childToJSX(child, text) { | 591 | 594 | if (text !== null) { | 592 | 595 | return text; | @@ -925,6 +928,23 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 925 | 928 |
| 926 | 929 | discreteUpdates: NoopRenderer.discreteUpdates, | 927 | 930 |
| | 931 | + idleUpdates<T>(fn: () => T): T { | | 932 | + if (enableNativeEventPriorityInference) { | | 933 | + const prevEventPriority = currentEventPriority; | | 934 | + currentEventPriority = NoopRenderer.IdleEventPriority; | | 935 | + try { | | 936 | + fn(); | | 937 | + } finally { | | 938 | + currentEventPriority = prevEventPriority; | | 939 | + } | | 940 | + } else { | | 941 | + return Scheduler.unstable_runWithPriority( | | 942 | + Scheduler.unstable_IdlePriority, | | 943 | + fn, | | 944 | + ); | | 945 | + } | | 946 | + }, | | 947 | + | 928 | 948 | flushDiscreteUpdates: NoopRenderer.flushDiscreteUpdates, | 929 | 949 |
| 930 | 950 | flushSync(fn: () => mixed) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberLane.new.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -70,7 +70,7 @@ const RetryLanePriority: LanePriority = 5; | 70 | 70 | const SelectiveHydrationLanePriority: LanePriority = 4; | 71 | 71 |
| 72 | 72 | const IdleHydrationLanePriority: LanePriority = 3; | 73 | | -const IdleLanePriority: LanePriority = 2; | | 73 | +export const IdleLanePriority: LanePriority = 2; | 74 | 74 |
| 75 | 75 | const OffscreenLanePriority: LanePriority = 1; | 76 | 76 |
| @@ -275,6 +275,7 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes { | 275 | 275 |
| 276 | 276 | // Check if any work has expired. | 277 | 277 | if (expiredLanes !== NoLanes) { | | 278 | + // TODO: Should entangle with SyncLane | 278 | 279 | nextLanes = expiredLanes; | 279 | 280 | nextLanePriority = return_highestLanePriority = SyncLanePriority; | 280 | 281 | } else { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberLane.old.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -70,7 +70,7 @@ const RetryLanePriority: LanePriority = 5; | 70 | 70 | const SelectiveHydrationLanePriority: LanePriority = 4; | 71 | 71 |
| 72 | 72 | const IdleHydrationLanePriority: LanePriority = 3; | 73 | | -const IdleLanePriority: LanePriority = 2; | | 73 | +export const IdleLanePriority: LanePriority = 2; | 74 | 74 |
| 75 | 75 | const OffscreenLanePriority: LanePriority = 1; | 76 | 76 |
| @@ -275,6 +275,7 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes { | 275 | 275 |
| 276 | 276 | // Check if any work has expired. | 277 | 277 | if (expiredLanes !== NoLanes) { | | 278 | + // TODO: Should entangle with SyncLane | 278 | 279 | nextLanes = expiredLanes; | 279 | 280 | nextLanePriority = return_highestLanePriority = SyncLanePriority; | 280 | 281 | } else { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberReconciler.js +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,6 +55,7 @@ import { | 55 | 55 | DefaultEventPriority as DefaultEventPriority_old, | 56 | 56 | DiscreteEventPriority as DiscreteEventPriority_old, | 57 | 57 | ContinuousEventPriority as ContinuousEventPriority_old, | | 58 | + IdleEventPriority as IdleEventPriority_old, | 58 | 59 | } from './ReactFiberReconciler.old'; | 59 | 60 |
| 60 | 61 | import { | @@ -98,6 +99,7 @@ import { | 98 | 99 | DefaultEventPriority as DefaultEventPriority_new, | 99 | 100 | DiscreteEventPriority as DiscreteEventPriority_new, | 100 | 101 | ContinuousEventPriority as ContinuousEventPriority_new, | | 102 | + IdleEventPriority as IdleEventPriority_new, | 101 | 103 | } from './ReactFiberReconciler.new'; | 102 | 104 |
| 103 | 105 | export const createContainer = enableNewReconciler | @@ -183,6 +185,9 @@ export const DiscreteEventPriority = enableNewReconciler | 183 | 185 | export const ContinuousEventPriority = enableNewReconciler | 184 | 186 | ? ContinuousEventPriority_new | 185 | 187 | : ContinuousEventPriority_old; | | 188 | +export const IdleEventPriority = enableNewReconciler | | 189 | + ? IdleEventPriority_new | | 190 | + : IdleEventPriority_old; | 186 | 191 |
| 187 | 192 | //TODO: "psuedo" is spelled "pseudo" | 188 | 193 | export const createHasPsuedoClassSelector = enableNewReconciler | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberReconciler.new.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -101,6 +101,7 @@ export { | 101 | 101 | InputDiscreteLanePriority as DiscreteEventPriority, | 102 | 102 | InputContinuousLanePriority as ContinuousEventPriority, | 103 | 103 | DefaultLanePriority as DefaultEventPriority, | | 104 | + IdleLanePriority as IdleEventPriority, | 104 | 105 | } from './ReactFiberLane.new'; | 105 | 106 |
| 106 | 107 | export {registerMutableSourceForHydration} from './ReactMutableSource.new'; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberReconciler.old.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -101,6 +101,7 @@ export { | 101 | 101 | InputDiscreteLanePriority as DiscreteEventPriority, | 102 | 102 | InputContinuousLanePriority as ContinuousEventPriority, | 103 | 103 | DefaultLanePriority as DefaultEventPriority, | | 104 | + IdleLanePriority as IdleEventPriority, | 104 | 105 | } from './ReactFiberLane.old'; | 105 | 106 |
| 106 | 107 | export {registerMutableSourceForHydration} from './ReactMutableSource.new'; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.new.js +1-9Lines changed: 1 addition & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -465,15 +465,7 @@ export function requestUpdateLane(fiber: Fiber): Lane { | 465 | 465 | } else { | 466 | 466 | if (enableNativeEventPriorityInference) { | 467 | 467 | const eventLanePriority = getCurrentEventPriority(); | 468 | | - if (eventLanePriority === DefaultLanePriority) { | 469 | | - // TODO: move this case into the ReactDOM host config. | 470 | | - const schedulerLanePriority = schedulerPriorityToLanePriority( | 471 | | - schedulerPriority, | 472 | | - ); | 473 | | - lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes); | 474 | | - } else { | 475 | | - lane = findUpdateLane(eventLanePriority, currentEventWipLanes); | 476 | | - } | | 468 | + lane = findUpdateLane(eventLanePriority, currentEventWipLanes); | 477 | 469 | } else { | 478 | 470 | const schedulerLanePriority = schedulerPriorityToLanePriority( | 479 | 471 | schedulerPriority, | |
|