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 (facebook#32002)

Stacked on facebook#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](facebook@98418e8)
  • Loading branch information
pull[bot] committed Jan 8, 2025
1 parent b47223f commit d745718
Show file tree
Hide file tree
Showing 43 changed files with 13,828 additions and 13,658 deletions.
2 changes: 2 additions & 0 deletions compiled/facebook-www/JSXDEVRuntime-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ __DEV__ &&
return "Suspense";
case REACT_SUSPENSE_LIST_TYPE:
return "SuspenseList";
case REACT_VIEW_TRANSITION_TYPE:
case REACT_TRACING_MARKER_TYPE:
if (enableTransitionTracing) return "TracingMarker";
}
Expand Down Expand Up @@ -724,6 +725,7 @@ __DEV__ &&
REACT_OFFSCREEN_TYPE = Symbol.for("react.offscreen"),
REACT_LEGACY_HIDDEN_TYPE = Symbol.for("react.legacy_hidden"),
REACT_TRACING_MARKER_TYPE = Symbol.for("react.tracing_marker"),
REACT_VIEW_TRANSITION_TYPE = Symbol.for("react.view_transition"),
MAYBE_ITERATOR_SYMBOL = Symbol.iterator,
warningWWW = require("warning"),
REACT_CLIENT_REFERENCE$2 = Symbol.for("react.client.reference"),
Expand Down
2 changes: 2 additions & 0 deletions compiled/facebook-www/JSXDEVRuntime-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ __DEV__ &&
return "Suspense";
case REACT_SUSPENSE_LIST_TYPE:
return "SuspenseList";
case REACT_VIEW_TRANSITION_TYPE:
case REACT_TRACING_MARKER_TYPE:
if (enableTransitionTracing) return "TracingMarker";
}
Expand Down Expand Up @@ -724,6 +725,7 @@ __DEV__ &&
REACT_OFFSCREEN_TYPE = Symbol.for("react.offscreen"),
REACT_LEGACY_HIDDEN_TYPE = Symbol.for("react.legacy_hidden"),
REACT_TRACING_MARKER_TYPE = Symbol.for("react.tracing_marker"),
REACT_VIEW_TRANSITION_TYPE = Symbol.for("react.view_transition"),
MAYBE_ITERATOR_SYMBOL = Symbol.iterator,
warningWWW = require("warning"),
REACT_CLIENT_REFERENCE$2 = Symbol.for("react.client.reference"),
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
defffdbba43f89b95d9f67a4fb0fa146c1211734
98418e8902d6045e5138a2e765e026ce2e4de82d
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
defffdbba43f89b95d9f67a4fb0fa146c1211734
98418e8902d6045e5138a2e765e026ce2e4de82d
4 changes: 3 additions & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ __DEV__ &&
return "Suspense";
case REACT_SUSPENSE_LIST_TYPE:
return "SuspenseList";
case REACT_VIEW_TRANSITION_TYPE:
case REACT_TRACING_MARKER_TYPE:
if (enableTransitionTracing) return "TracingMarker";
}
Expand Down Expand Up @@ -1136,6 +1137,7 @@ __DEV__ &&
REACT_OFFSCREEN_TYPE = Symbol.for("react.offscreen"),
REACT_LEGACY_HIDDEN_TYPE = Symbol.for("react.legacy_hidden"),
REACT_TRACING_MARKER_TYPE = Symbol.for("react.tracing_marker"),
REACT_VIEW_TRANSITION_TYPE = Symbol.for("react.view_transition"),
MAYBE_ITERATOR_SYMBOL = Symbol.iterator,
warningWWW = require("warning"),
didWarnStateUpdateForUnmountedComponent = {},
Expand Down Expand Up @@ -1942,7 +1944,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.1.0-www-classic-defffdbb-20250106";
exports.version = "19.1.0-www-classic-98418e89-20250108";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
4 changes: 3 additions & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ __DEV__ &&
return "Suspense";
case REACT_SUSPENSE_LIST_TYPE:
return "SuspenseList";
case REACT_VIEW_TRANSITION_TYPE:
case REACT_TRACING_MARKER_TYPE:
if (enableTransitionTracing) return "TracingMarker";
}
Expand Down Expand Up @@ -1136,6 +1137,7 @@ __DEV__ &&
REACT_OFFSCREEN_TYPE = Symbol.for("react.offscreen"),
REACT_LEGACY_HIDDEN_TYPE = Symbol.for("react.legacy_hidden"),
REACT_TRACING_MARKER_TYPE = Symbol.for("react.tracing_marker"),
REACT_VIEW_TRANSITION_TYPE = Symbol.for("react.view_transition"),
MAYBE_ITERATOR_SYMBOL = Symbol.iterator,
warningWWW = require("warning"),
didWarnStateUpdateForUnmountedComponent = {},
Expand Down Expand Up @@ -1942,7 +1944,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.1.0-www-modern-defffdbb-20250106";
exports.version = "19.1.0-www-modern-98418e89-20250108";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
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 @@ -630,4 +630,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-classic-defffdbb-20250106";
exports.version = "19.1.0-www-classic-98418e89-20250108";
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 @@ -630,4 +630,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-modern-defffdbb-20250106";
exports.version = "19.1.0-www-modern-98418e89-20250108";
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 @@ -634,7 +634,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-classic-defffdbb-20250106";
exports.version = "19.1.0-www-classic-98418e89-20250108";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
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 @@ -634,7 +634,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-modern-defffdbb-20250106";
exports.version = "19.1.0-www-modern-98418e89-20250108";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Loading

0 comments on commit d745718

Please sign in to comment.