Skip to content

Commit

Permalink
[Fiber] Suspend the commit while we wait for the previous View Transi…
Browse files Browse the repository at this point in the history
…tion to finish (#32002)

Stacked on #31975.

View Transitions cannot handle interruptions in that if you start a new
one before the previous one has finished, it just stops and then
restarts. It doesn't seamlessly transition into the new transition.

This is generally considered a bad thing but I actually think it's quite
good for fire-and-forget animations (gestures is another story). There
are too many examples of bad animations in fast interactions because the
scenario wasn't predicted. Like overlapping toasts or stacked layers
that look bad. The only case interrupts tend to work well is when you do
a strict reversal of an animation like returning to the page you just
left or exiting a modal just being opened. However, we're limited by the
platform even in that regard.

I think one reason interruptions have traditionally been seen as good is
because it's hard if you have a synchronous framework to not interrupt
since your application state has already moved on. We don't have that
limitation since we can suspend commits. We can do all the work to
prepare for the next commit by rendering while the animation is going
but then delay the commit until the previous one finishes.

Another technical limitation earlier animation libraries suffered from
is only have the option to either interrupt or sequence animations since
it's modeling just one change set. Like showing one toast at a time.
That's bad. We don't have that limitation because we can interrupt a
previously suspended commit and start working on a new one instead.
That's what we do for suspended transitions in general. The net effect
is that we batch the commits.

Therefore if you get multiple toasts flying in fast, they can animate as
a batch in together all at once instead of overlapping slightly or being
staggered. Interruptions (often) bad. Staggered animations bad. Batched
animations good.

This PR stashes the currently active View Transition with an expando on
the container that's animating (currently always document). This is
similar to what we do with event handlers etc. We reason we do this with
an expando is that if you have multiple Reacts on the same page they
need to wait for each other. However, one of those might also be the SSR
runtime. So this lets us wait for the SSR runtime's animations to finish
before starting client ones. This could really be a more generic name
since this should ideally be shared across frameworks. It's kind of
strange that this property doesn't already exist in the DOM given that
there can only be one. It would be useful to be able to coordinate this
across libraries.

DiffTrain build for [98418e8](98418e8)
  • Loading branch information
sebmarkbage committed Jan 8, 2025
1 parent ef7a1ae commit 3fcc9f8
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 113 deletions.
2 changes: 1 addition & 1 deletion compiled-rn/VERSION_NATIVE_FB
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.1.0-native-fb-38127b28-20250108
19.1.0-native-fb-98418e89-20250108
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<a5907ac6d8c935a838c49cab076677f9>>
* @generated SignedSource<<08e443744db50b32588656c3382782c0>>
*/

"use strict";
Expand Down Expand Up @@ -420,5 +420,5 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.1.0-native-fb-38127b28-20250108";
exports.version = "19.1.0-native-fb-98418e89-20250108";
})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<24ed921d12020cf625ff914fb35495ee>>
* @generated SignedSource<<b90ba57092a2b533d32f364f4bb9ceab>>
*/

"use strict";
Expand Down Expand Up @@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactSharedInternals.H.useHostTransitionStatus();
};
exports.version = "19.1.0-native-fb-38127b28-20250108";
exports.version = "19.1.0-native-fb-98418e89-20250108";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<24ed921d12020cf625ff914fb35495ee>>
* @generated SignedSource<<b90ba57092a2b533d32f364f4bb9ceab>>
*/

"use strict";
Expand Down Expand Up @@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactSharedInternals.H.useHostTransitionStatus();
};
exports.version = "19.1.0-native-fb-38127b28-20250108";
exports.version = "19.1.0-native-fb-98418e89-20250108";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<1774e836c2a7b70ca4262db777405dbf>>
* @generated SignedSource<<dc25c84a41124ac2a2db509184bef29b>>
*/

/*
Expand Down Expand Up @@ -15448,12 +15448,14 @@ __DEV__ &&
root.timeoutHandle = noTimeout;
suspendedCommitReason = finishedWork.subtreeFlags;
if (
suspendedCommitReason & 8192 ||
16785408 === (suspendedCommitReason & 16785408)
(suspendedCommitReason =
suspendedCommitReason & 8192 ||
16785408 === (suspendedCommitReason & 16785408))
)
if (
((suspendedState = { stylesheets: null, count: 0, unsuspend: noop }),
accumulateSuspenseyCommitOnFiber(finishedWork),
suspendedCommitReason &&
accumulateSuspenseyCommitOnFiber(finishedWork),
(suspendedCommitReason = waitForCommitToBeReady()),
null !== suspendedCommitReason)
) {
Expand Down Expand Up @@ -25918,11 +25920,11 @@ __DEV__ &&
};
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.1.0-native-fb-38127b28-20250108" !== isomorphicReactPackageVersion)
if ("19.1.0-native-fb-98418e89-20250108" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.1.0-native-fb-38127b28-20250108\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.1.0-native-fb-98418e89-20250108\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -25959,10 +25961,10 @@ __DEV__ &&
!(function () {
var internals = {
bundleType: 1,
version: "19.1.0-native-fb-38127b28-20250108",
version: "19.1.0-native-fb-98418e89-20250108",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-native-fb-38127b28-20250108"
reconcilerVersion: "19.1.0-native-fb-98418e89-20250108"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -26108,5 +26110,5 @@ __DEV__ &&
listenToAllSupportedEvents(container);
return new ReactDOMHydrationRoot(initialChildren);
};
exports.version = "19.1.0-native-fb-38127b28-20250108";
exports.version = "19.1.0-native-fb-98418e89-20250108";
})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<0d9c07a289ec2ff1fb4891e7547371e2>>
* @generated SignedSource<<321229d77e42c9400f9fca595c8a186d>>
*/

/*
Expand Down Expand Up @@ -11116,12 +11116,13 @@ function commitRootWhenReady(
root.timeoutHandle = -1;
suspendedCommitReason = finishedWork.subtreeFlags;
if (
suspendedCommitReason & 8192 ||
16785408 === (suspendedCommitReason & 16785408)
(suspendedCommitReason =
suspendedCommitReason & 8192 ||
16785408 === (suspendedCommitReason & 16785408))
)
if (
((suspendedState = { stylesheets: null, count: 0, unsuspend: noop }),
accumulateSuspenseyCommitOnFiber(finishedWork),
suspendedCommitReason && accumulateSuspenseyCommitOnFiber(finishedWork),
(suspendedCommitReason = waitForCommitToBeReady()),
null !== suspendedCommitReason)
) {
Expand Down Expand Up @@ -15944,14 +15945,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
};
var isomorphicReactPackageVersion$jscomp$inline_1771 = React.version;
if (
"19.1.0-native-fb-38127b28-20250108" !==
"19.1.0-native-fb-98418e89-20250108" !==
isomorphicReactPackageVersion$jscomp$inline_1771
)
throw Error(
formatProdErrorMessage(
527,
isomorphicReactPackageVersion$jscomp$inline_1771,
"19.1.0-native-fb-38127b28-20250108"
"19.1.0-native-fb-98418e89-20250108"
)
);
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
Expand All @@ -15973,10 +15974,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
};
var internals$jscomp$inline_2219 = {
bundleType: 0,
version: "19.1.0-native-fb-38127b28-20250108",
version: "19.1.0-native-fb-98418e89-20250108",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-native-fb-38127b28-20250108"
reconcilerVersion: "19.1.0-native-fb-98418e89-20250108"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2220 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -16082,4 +16083,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
listenToAllSupportedEvents(container);
return new ReactDOMHydrationRoot(initialChildren);
};
exports.version = "19.1.0-native-fb-38127b28-20250108";
exports.version = "19.1.0-native-fb-98418e89-20250108";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<947cce3cdb7ca8e14164c121b0b56b9a>>
* @generated SignedSource<<13fbbbc8aa85c15cc504fda0be239fb2>>
*/

/*
Expand Down Expand Up @@ -11623,12 +11623,13 @@ function commitRootWhenReady(
root.timeoutHandle = -1;
suspendedCommitReason = finishedWork.subtreeFlags;
if (
suspendedCommitReason & 8192 ||
16785408 === (suspendedCommitReason & 16785408)
(suspendedCommitReason =
suspendedCommitReason & 8192 ||
16785408 === (suspendedCommitReason & 16785408))
)
if (
((suspendedState = { stylesheets: null, count: 0, unsuspend: noop }),
accumulateSuspenseyCommitOnFiber(finishedWork),
suspendedCommitReason && accumulateSuspenseyCommitOnFiber(finishedWork),
(suspendedCommitReason = waitForCommitToBeReady()),
null !== suspendedCommitReason)
) {
Expand Down Expand Up @@ -16591,14 +16592,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
};
var isomorphicReactPackageVersion$jscomp$inline_1866 = React.version;
if (
"19.1.0-native-fb-38127b28-20250108" !==
"19.1.0-native-fb-98418e89-20250108" !==
isomorphicReactPackageVersion$jscomp$inline_1866
)
throw Error(
formatProdErrorMessage(
527,
isomorphicReactPackageVersion$jscomp$inline_1866,
"19.1.0-native-fb-38127b28-20250108"
"19.1.0-native-fb-98418e89-20250108"
)
);
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
Expand All @@ -16620,10 +16621,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
};
var internals$jscomp$inline_1873 = {
bundleType: 0,
version: "19.1.0-native-fb-38127b28-20250108",
version: "19.1.0-native-fb-98418e89-20250108",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-native-fb-38127b28-20250108",
reconcilerVersion: "19.1.0-native-fb-98418e89-20250108",
getLaneLabelMap: function () {
for (
var map = new Map(), lane = 1, index$293 = 0;
Expand Down Expand Up @@ -16744,4 +16745,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
listenToAllSupportedEvents(container);
return new ReactDOMHydrationRoot(initialChildren);
};
exports.version = "19.1.0-native-fb-38127b28-20250108";
exports.version = "19.1.0-native-fb-98418e89-20250108";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<079dbae19bc30169d8e4ecf8c571d8cd>>
* @generated SignedSource<<dd55e045a1b919c31a3138d21ee216d0>>
*/

/*
Expand Down Expand Up @@ -15456,16 +15456,18 @@ __DEV__ &&
root.timeoutHandle = noTimeout;
suspendedCommitReason = finishedWork.subtreeFlags;
if (
suspendedCommitReason & 8192 ||
16785408 === (suspendedCommitReason & 16785408)
(suspendedCommitReason =
suspendedCommitReason & 8192 ||
16785408 === (suspendedCommitReason & 16785408))
)
if (
((suspendedState = {
stylesheets: null,
count: 0,
unsuspend: noop$1
}),
accumulateSuspenseyCommitOnFiber(finishedWork),
suspendedCommitReason &&
accumulateSuspenseyCommitOnFiber(finishedWork),
(suspendedCommitReason = waitForCommitToBeReady()),
null !== suspendedCommitReason)
) {
Expand Down Expand Up @@ -25979,11 +25981,11 @@ __DEV__ &&
};
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.1.0-native-fb-38127b28-20250108" !== isomorphicReactPackageVersion)
if ("19.1.0-native-fb-98418e89-20250108" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.1.0-native-fb-38127b28-20250108\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.1.0-native-fb-98418e89-20250108\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -26020,10 +26022,10 @@ __DEV__ &&
!(function () {
var internals = {
bundleType: 1,
version: "19.1.0-native-fb-38127b28-20250108",
version: "19.1.0-native-fb-98418e89-20250108",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-native-fb-38127b28-20250108"
reconcilerVersion: "19.1.0-native-fb-98418e89-20250108"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -26485,7 +26487,7 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.1.0-native-fb-38127b28-20250108";
exports.version = "19.1.0-native-fb-98418e89-20250108";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<fe7d64373c07d195c02fdb9ca3c97945>>
* @generated SignedSource<<e9da92054ecc9489885d140d450a1fd2>>
*/

/*
Expand Down Expand Up @@ -11116,12 +11116,13 @@ function commitRootWhenReady(
root.timeoutHandle = -1;
suspendedCommitReason = finishedWork.subtreeFlags;
if (
suspendedCommitReason & 8192 ||
16785408 === (suspendedCommitReason & 16785408)
(suspendedCommitReason =
suspendedCommitReason & 8192 ||
16785408 === (suspendedCommitReason & 16785408))
)
if (
((suspendedState = { stylesheets: null, count: 0, unsuspend: noop$1 }),
accumulateSuspenseyCommitOnFiber(finishedWork),
suspendedCommitReason && accumulateSuspenseyCommitOnFiber(finishedWork),
(suspendedCommitReason = waitForCommitToBeReady()),
null !== suspendedCommitReason)
) {
Expand Down Expand Up @@ -15955,14 +15956,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
};
var isomorphicReactPackageVersion$jscomp$inline_1772 = React.version;
if (
"19.1.0-native-fb-38127b28-20250108" !==
"19.1.0-native-fb-98418e89-20250108" !==
isomorphicReactPackageVersion$jscomp$inline_1772
)
throw Error(
formatProdErrorMessage(
527,
isomorphicReactPackageVersion$jscomp$inline_1772,
"19.1.0-native-fb-38127b28-20250108"
"19.1.0-native-fb-98418e89-20250108"
)
);
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
Expand All @@ -15984,10 +15985,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
};
var internals$jscomp$inline_2222 = {
bundleType: 0,
version: "19.1.0-native-fb-38127b28-20250108",
version: "19.1.0-native-fb-98418e89-20250108",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-native-fb-38127b28-20250108"
reconcilerVersion: "19.1.0-native-fb-98418e89-20250108"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2223 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -16247,4 +16248,4 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactSharedInternals.H.useHostTransitionStatus();
};
exports.version = "19.1.0-native-fb-38127b28-20250108";
exports.version = "19.1.0-native-fb-98418e89-20250108";
Loading

0 comments on commit 3fcc9f8

Please sign in to comment.