Skip to content

Commit c1a1e88

Browse files
committed
Add enableSyncDefaultUpdates implementation
1 parent 994bb10 commit c1a1e88

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

packages/react-reconciler/src/ReactFiberLane.new.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ export const NoLane: Lane = /* */ 0b0000000000000000000
4747

4848
export const SyncLane: Lane = /* */ 0b0000000000000000000000000000001;
4949

50-
const InputContinuousHydrationLane: Lane = /* */ 0b0000000000000000000000000000010;
50+
export const InputContinuousHydrationLane: Lane = /* */ 0b0000000000000000000000000000010;
5151
export const InputContinuousLane: Lanes = /* */ 0b0000000000000000000000000000100;
5252

5353
export const DefaultHydrationLane: Lane = /* */ 0b0000000000000000000000000001000;
5454
export const DefaultLane: Lanes = /* */ 0b0000000000000000000000000010000;
5555

5656
const TransitionHydrationLane: Lane = /* */ 0b0000000000000000000000000100000;
5757
const TransitionLanes: Lanes = /* */ 0b0000000001111111111111111000000;
58-
const TransitionLane1: Lane = /* */ 0b0000000000000000000000001000000;
58+
export const TransitionLane1: Lane = /* */ 0b0000000000000000000000001000000;
5959
const TransitionLane2: Lane = /* */ 0b0000000000000000000000010000000;
6060
const TransitionLane3: Lane = /* */ 0b0000000000000000000000100000000;
6161
const TransitionLane4: Lane = /* */ 0b0000000000000000000001000000000;

packages/react-reconciler/src/ReactFiberLane.old.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ export const NoLane: Lane = /* */ 0b0000000000000000000
4747

4848
export const SyncLane: Lane = /* */ 0b0000000000000000000000000000001;
4949

50-
const InputContinuousHydrationLane: Lane = /* */ 0b0000000000000000000000000000010;
50+
export const InputContinuousHydrationLane: Lane = /* */ 0b0000000000000000000000000000010;
5151
export const InputContinuousLane: Lanes = /* */ 0b0000000000000000000000000000100;
5252

5353
export const DefaultHydrationLane: Lane = /* */ 0b0000000000000000000000000001000;
5454
export const DefaultLane: Lanes = /* */ 0b0000000000000000000000000010000;
5555

5656
const TransitionHydrationLane: Lane = /* */ 0b0000000000000000000000000100000;
5757
const TransitionLanes: Lanes = /* */ 0b0000000001111111111111111000000;
58-
const TransitionLane1: Lane = /* */ 0b0000000000000000000000001000000;
58+
export const TransitionLane1: Lane = /* */ 0b0000000000000000000000001000000;
5959
const TransitionLane2: Lane = /* */ 0b0000000000000000000000010000000;
6060
const TransitionLane3: Lane = /* */ 0b0000000000000000000000100000000;
6161
const TransitionLane4: Lane = /* */ 0b0000000000000000000001000000000;

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
disableSchedulerTimeoutInWorkLoop,
3333
enableStrictEffects,
3434
skipUnmountedBoundaries,
35+
enableSyncDefaultUpdates,
3536
} from 'shared/ReactFeatureFlags';
3637
import ReactSharedInternals from 'shared/ReactSharedInternals';
3738
import invariant from 'shared/invariant';
@@ -137,6 +138,8 @@ import {
137138
NoLanes,
138139
NoLane,
139140
SyncLane,
141+
DefaultLane,
142+
DefaultHydrationLane,
140143
NoTimestamp,
141144
claimNextTransitionLane,
142145
claimNextRetryLane,
@@ -159,6 +162,8 @@ import {
159162
markRootFinished,
160163
areLanesExpired,
161164
getHighestPriorityLane,
165+
InputContinuousLane,
166+
InputContinuousHydrationLane,
162167
} from './ReactFiberLane.new';
163168
import {
164169
DiscreteEventPriority,
@@ -426,6 +431,13 @@ export function requestUpdateLane(fiber: Fiber): Lane {
426431
// TODO: Move this type conversion to the event priority module.
427432
const updateLane: Lane = (getCurrentUpdatePriority(): any);
428433
if (updateLane !== NoLane) {
434+
if (
435+
enableSyncDefaultUpdates &&
436+
(updateLane === InputContinuousLane ||
437+
updateLane === InputContinuousHydrationLane)
438+
) {
439+
return DefaultLane;
440+
}
429441
return updateLane;
430442
}
431443

@@ -682,7 +694,16 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
682694

683695
// Schedule a new callback.
684696
let newCallbackNode;
685-
if (newCallbackPriority === SyncLane) {
697+
if (
698+
enableSyncDefaultUpdates &&
699+
(newCallbackPriority === DefaultLane ||
700+
newCallbackPriority === DefaultHydrationLane)
701+
) {
702+
newCallbackNode = scheduleCallback(
703+
ImmediateSchedulerPriority,
704+
performSyncWorkOnRoot.bind(null, root),
705+
);
706+
} else if (newCallbackPriority === SyncLane) {
686707
// Special case: Sync React callbacks are scheduled on a special
687708
// internal queue
688709
scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
@@ -1017,7 +1038,11 @@ function performSyncWorkOnRoot(root) {
10171038
const finishedWork: Fiber = (root.current.alternate: any);
10181039
root.finishedWork = finishedWork;
10191040
root.finishedLanes = lanes;
1020-
commitRoot(root);
1041+
if (enableSyncDefaultUpdates && includesSomeLane(lanes, DefaultLane)) {
1042+
finishConcurrentRender(root, exitStatus, lanes);
1043+
} else {
1044+
commitRoot(root);
1045+
}
10211046

10221047
// Before exiting, make sure there's a callback scheduled for the next
10231048
// pending level.

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
disableSchedulerTimeoutInWorkLoop,
3333
enableStrictEffects,
3434
skipUnmountedBoundaries,
35+
enableSyncDefaultUpdates,
3536
} from 'shared/ReactFeatureFlags';
3637
import ReactSharedInternals from 'shared/ReactSharedInternals';
3738
import invariant from 'shared/invariant';
@@ -137,6 +138,8 @@ import {
137138
NoLanes,
138139
NoLane,
139140
SyncLane,
141+
DefaultLane,
142+
DefaultHydrationLane,
140143
NoTimestamp,
141144
claimNextTransitionLane,
142145
claimNextRetryLane,
@@ -159,6 +162,8 @@ import {
159162
markRootFinished,
160163
areLanesExpired,
161164
getHighestPriorityLane,
165+
InputContinuousLane,
166+
InputContinuousHydrationLane,
162167
} from './ReactFiberLane.old';
163168
import {
164169
DiscreteEventPriority,
@@ -426,6 +431,13 @@ export function requestUpdateLane(fiber: Fiber): Lane {
426431
// TODO: Move this type conversion to the event priority module.
427432
const updateLane: Lane = (getCurrentUpdatePriority(): any);
428433
if (updateLane !== NoLane) {
434+
if (
435+
enableSyncDefaultUpdates &&
436+
(updateLane === InputContinuousLane ||
437+
updateLane === InputContinuousHydrationLane)
438+
) {
439+
return DefaultLane;
440+
}
429441
return updateLane;
430442
}
431443

@@ -682,7 +694,16 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
682694

683695
// Schedule a new callback.
684696
let newCallbackNode;
685-
if (newCallbackPriority === SyncLane) {
697+
if (
698+
enableSyncDefaultUpdates &&
699+
(newCallbackPriority === DefaultLane ||
700+
newCallbackPriority === DefaultHydrationLane)
701+
) {
702+
newCallbackNode = scheduleCallback(
703+
ImmediateSchedulerPriority,
704+
performSyncWorkOnRoot.bind(null, root),
705+
);
706+
} else if (newCallbackPriority === SyncLane) {
686707
// Special case: Sync React callbacks are scheduled on a special
687708
// internal queue
688709
scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
@@ -1017,7 +1038,11 @@ function performSyncWorkOnRoot(root) {
10171038
const finishedWork: Fiber = (root.current.alternate: any);
10181039
root.finishedWork = finishedWork;
10191040
root.finishedLanes = lanes;
1020-
commitRoot(root);
1041+
if (enableSyncDefaultUpdates && includesSomeLane(lanes, DefaultLane)) {
1042+
finishConcurrentRender(root, exitStatus, lanes);
1043+
} else {
1044+
commitRoot(root);
1045+
}
10211046

10221047
// Before exiting, make sure there's a callback scheduled for the next
10231048
// pending level.

0 commit comments

Comments
 (0)