Skip to content

Commit

Permalink
Batch sync, default and continuous lanes (#25700)
Browse files Browse the repository at this point in the history
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn debug-test --watch TestName`, open
`chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->
This is the other approach for unifying default and sync lane
facebook/react#25524.
The approach in that PR is to merge default and continuous lane into the
sync lane, and use a new field to track the priority. But there are a
couple places that field will be needed, and it is difficult to
correctly reset the field when there is no sync lane.

In this PR we take the other approach that doesn't remove any lane, but
batch them to get the behavior we want.

## How did you test this change?

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->
yarn test

Co-authored-by: Andrew Clark <hi@andrewclark.io>

DiffTrain build for [5379b6123f171bb48cc8a9c435c11ccb9f8ff0e7](facebook/react@5379b61)
[View git log for this commit](https://github.com/facebook/react/commits/5379b6123f171bb48cc8a9c435c11ccb9f8ff0e7)
  • Loading branch information
jerrydev0927 committed Jan 5, 2023
1 parent 33fcfbd commit 1ce241e
Show file tree
Hide file tree
Showing 37 changed files with 838 additions and 673 deletions.
1 change: 1 addition & 0 deletions compiled/facebook-www/JSXDEVRuntime-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ var disableInputAttributeSyncing =
enableLazyContextPropagation =
dynamicFeatureFlags.enableLazyContextPropagation,
enableSyncDefaultUpdates = dynamicFeatureFlags.enableSyncDefaultUpdates,
enableUnifiedSyncLane = dynamicFeatureFlags.enableUnifiedSyncLane,
enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay =
dynamicFeatureFlags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
enableClientRenderFallbackOnTextMismatch =
Expand Down
1 change: 1 addition & 0 deletions compiled/facebook-www/JSXDEVRuntime-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ var disableInputAttributeSyncing =
enableLazyContextPropagation =
dynamicFeatureFlags.enableLazyContextPropagation,
enableSyncDefaultUpdates = dynamicFeatureFlags.enableSyncDefaultUpdates,
enableUnifiedSyncLane = dynamicFeatureFlags.enableUnifiedSyncLane,
enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay =
dynamicFeatureFlags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
enableClientRenderFallbackOnTextMismatch =
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b83baf63f71669ca7bf222afec305b7a6fd782b7
5379b6123f171bb48cc8a9c435c11ccb9f8ff0e7
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b83baf63f71669ca7bf222afec305b7a6fd782b7
5379b6123f171bb48cc8a9c435c11ccb9f8ff0e7
3 changes: 2 additions & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-classic-b83baf63f-20230105";
var ReactVersion = "18.3.0-www-classic-5379b6123-20230105";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -502,6 +502,7 @@ var disableInputAttributeSyncing =
enableLazyContextPropagation =
dynamicFeatureFlags.enableLazyContextPropagation,
enableSyncDefaultUpdates = dynamicFeatureFlags.enableSyncDefaultUpdates,
enableUnifiedSyncLane = dynamicFeatureFlags.enableUnifiedSyncLane,
enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay =
dynamicFeatureFlags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
enableClientRenderFallbackOnTextMismatch =
Expand Down
3 changes: 2 additions & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-modern-b83baf63f-20230105";
var ReactVersion = "18.3.0-www-modern-5379b6123-20230105";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -502,6 +502,7 @@ var disableInputAttributeSyncing =
enableLazyContextPropagation =
dynamicFeatureFlags.enableLazyContextPropagation,
enableSyncDefaultUpdates = dynamicFeatureFlags.enableSyncDefaultUpdates,
enableUnifiedSyncLane = dynamicFeatureFlags.enableUnifiedSyncLane,
enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay =
dynamicFeatureFlags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
enableClientRenderFallbackOnTextMismatch =
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,4 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-classic-b83baf63f-20230105";
exports.version = "18.3.0-www-classic-5379b6123-20230105";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,4 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-modern-b83baf63f-20230105";
exports.version = "18.3.0-www-modern-5379b6123-20230105";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-classic-b83baf63f-20230105";
exports.version = "18.3.0-www-classic-5379b6123-20230105";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-modern-b83baf63f-20230105";
exports.version = "18.3.0-www-modern-5379b6123-20230105";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
98 changes: 57 additions & 41 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-classic-b83baf63f-20230105";
var ReactVersion = "18.3.0-www-classic-5379b6123-20230105";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -191,6 +191,7 @@ var disableInputAttributeSyncing =
enableLazyContextPropagation =
dynamicFeatureFlags.enableLazyContextPropagation,
enableSyncDefaultUpdates = dynamicFeatureFlags.enableSyncDefaultUpdates,
enableUnifiedSyncLane = dynamicFeatureFlags.enableUnifiedSyncLane,
enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay =
dynamicFeatureFlags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
enableClientRenderFallbackOnTextMismatch =
Expand Down Expand Up @@ -1596,6 +1597,9 @@ var DefaultHydrationLane =
var DefaultLane =
/* */
32;
var SyncUpdateLanes =
/* */
42;
var TransitionHydrationLane =
/* */
64;
Expand Down Expand Up @@ -1743,6 +1747,14 @@ var nextTransitionLane = TransitionLane1;
var nextRetryLane = RetryLane1;

function getHighestPriorityLanes(lanes) {
if (enableUnifiedSyncLane) {
var pendingSyncLanes = lanes & SyncUpdateLanes;

if (pendingSyncLanes !== 0) {
return pendingSyncLanes;
}
}

switch (getHighestPriorityLane(lanes)) {
case SyncHydrationLane:
return SyncHydrationLane;
Expand Down Expand Up @@ -2317,51 +2329,55 @@ function getBumpedLaneForHydration(root, renderLanes) {
var renderLane = getHighestPriorityLane(renderLanes);
var lane;

switch (renderLane) {
case SyncLane:
lane = SyncHydrationLane;
break;
if (enableUnifiedSyncLane && (renderLane & SyncUpdateLanes) !== NoLane) {
lane = SyncHydrationLane;
} else {
switch (renderLane) {
case SyncLane:
lane = SyncHydrationLane;
break;

case InputContinuousLane:
lane = InputContinuousHydrationLane;
break;
case InputContinuousLane:
lane = InputContinuousHydrationLane;
break;

case DefaultLane:
lane = DefaultHydrationLane;
break;
case DefaultLane:
lane = DefaultHydrationLane;
break;

case TransitionLane1:
case TransitionLane2:
case TransitionLane3:
case TransitionLane4:
case TransitionLane5:
case TransitionLane6:
case TransitionLane7:
case TransitionLane8:
case TransitionLane9:
case TransitionLane10:
case TransitionLane11:
case TransitionLane12:
case TransitionLane13:
case TransitionLane14:
case TransitionLane15:
case TransitionLane16:
case RetryLane1:
case RetryLane2:
case RetryLane3:
case RetryLane4:
lane = TransitionHydrationLane;
break;
case TransitionLane1:
case TransitionLane2:
case TransitionLane3:
case TransitionLane4:
case TransitionLane5:
case TransitionLane6:
case TransitionLane7:
case TransitionLane8:
case TransitionLane9:
case TransitionLane10:
case TransitionLane11:
case TransitionLane12:
case TransitionLane13:
case TransitionLane14:
case TransitionLane15:
case TransitionLane16:
case RetryLane1:
case RetryLane2:
case RetryLane3:
case RetryLane4:
lane = TransitionHydrationLane;
break;

case IdleLane:
lane = IdleHydrationLane;
break;
case IdleLane:
lane = IdleHydrationLane;
break;

default:
// Everything else is already either a hydration lane, or shouldn't
// be retried at a hydration lane.
lane = NoLane;
break;
default:
// Everything else is already either a hydration lane, or shouldn't
// be retried at a hydration lane.
lane = NoLane;
break;
}
} // Check if the lane we chose is suspended. If so, that indicates that we
// already attempted and failed to hydrate at that level. Also check if we're
// already rendering that lane, which is rare but could happen.
Expand Down
98 changes: 57 additions & 41 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-modern-b83baf63f-20230105";
var ReactVersion = "18.3.0-www-modern-5379b6123-20230105";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -191,6 +191,7 @@ var disableInputAttributeSyncing =
enableLazyContextPropagation =
dynamicFeatureFlags.enableLazyContextPropagation,
enableSyncDefaultUpdates = dynamicFeatureFlags.enableSyncDefaultUpdates,
enableUnifiedSyncLane = dynamicFeatureFlags.enableUnifiedSyncLane,
enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay =
dynamicFeatureFlags.enableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay,
enableClientRenderFallbackOnTextMismatch =
Expand Down Expand Up @@ -1593,6 +1594,9 @@ var DefaultHydrationLane =
var DefaultLane =
/* */
32;
var SyncUpdateLanes =
/* */
42;
var TransitionHydrationLane =
/* */
64;
Expand Down Expand Up @@ -1740,6 +1744,14 @@ var nextTransitionLane = TransitionLane1;
var nextRetryLane = RetryLane1;

function getHighestPriorityLanes(lanes) {
if (enableUnifiedSyncLane) {
var pendingSyncLanes = lanes & SyncUpdateLanes;

if (pendingSyncLanes !== 0) {
return pendingSyncLanes;
}
}

switch (getHighestPriorityLane(lanes)) {
case SyncHydrationLane:
return SyncHydrationLane;
Expand Down Expand Up @@ -2314,51 +2326,55 @@ function getBumpedLaneForHydration(root, renderLanes) {
var renderLane = getHighestPriorityLane(renderLanes);
var lane;

switch (renderLane) {
case SyncLane:
lane = SyncHydrationLane;
break;
if (enableUnifiedSyncLane && (renderLane & SyncUpdateLanes) !== NoLane) {
lane = SyncHydrationLane;
} else {
switch (renderLane) {
case SyncLane:
lane = SyncHydrationLane;
break;

case InputContinuousLane:
lane = InputContinuousHydrationLane;
break;
case InputContinuousLane:
lane = InputContinuousHydrationLane;
break;

case DefaultLane:
lane = DefaultHydrationLane;
break;
case DefaultLane:
lane = DefaultHydrationLane;
break;

case TransitionLane1:
case TransitionLane2:
case TransitionLane3:
case TransitionLane4:
case TransitionLane5:
case TransitionLane6:
case TransitionLane7:
case TransitionLane8:
case TransitionLane9:
case TransitionLane10:
case TransitionLane11:
case TransitionLane12:
case TransitionLane13:
case TransitionLane14:
case TransitionLane15:
case TransitionLane16:
case RetryLane1:
case RetryLane2:
case RetryLane3:
case RetryLane4:
lane = TransitionHydrationLane;
break;
case TransitionLane1:
case TransitionLane2:
case TransitionLane3:
case TransitionLane4:
case TransitionLane5:
case TransitionLane6:
case TransitionLane7:
case TransitionLane8:
case TransitionLane9:
case TransitionLane10:
case TransitionLane11:
case TransitionLane12:
case TransitionLane13:
case TransitionLane14:
case TransitionLane15:
case TransitionLane16:
case RetryLane1:
case RetryLane2:
case RetryLane3:
case RetryLane4:
lane = TransitionHydrationLane;
break;

case IdleLane:
lane = IdleHydrationLane;
break;
case IdleLane:
lane = IdleHydrationLane;
break;

default:
// Everything else is already either a hydration lane, or shouldn't
// be retried at a hydration lane.
lane = NoLane;
break;
default:
// Everything else is already either a hydration lane, or shouldn't
// be retried at a hydration lane.
lane = NoLane;
break;
}
} // Check if the lane we chose is suspended. If so, that indicates that we
// already attempted and failed to hydrate at that level. Also check if we're
// already rendering that lane, which is rare but could happen.
Expand Down
Loading

0 comments on commit 1ce241e

Please sign in to comment.