Skip to content

Commit 8d48673

Browse files
committed
Only support View Transitions v2
1 parent a4d122f commit 8d48673

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,19 +1187,28 @@ export function startViewTransition(
11871187
rootContainer.nodeType === DOCUMENT_NODE
11881188
? rootContainer
11891189
: rootContainer.ownerDocument;
1190-
// $FlowFixMe[prop-missing]
1191-
if (typeof ownerDocument.startViewTransition !== 'function') {
1190+
try {
1191+
// $FlowFixMe[prop-missing]
1192+
const transition = ownerDocument.startViewTransition({
1193+
update() {
1194+
mutationCallback();
1195+
// TODO: Wait for fonts.
1196+
afterMutationCallback();
1197+
},
1198+
types: null, // TODO: Provide types.
1199+
});
1200+
transition.ready.then(layoutCallback, layoutCallback);
1201+
transition.finished.then(passiveCallback);
1202+
return true;
1203+
} catch (x) {
1204+
// We use the error as feature detection.
1205+
// The only thing that should throw is if startViewTransition is missing
1206+
// or if it doesn't accept the object form. Other errors are async.
1207+
// I.e. it's before the View Transitions v2 spec. We only support View
1208+
// Transitions v2 otherwise we fallback to not animating to ensure that
1209+
// we're not animating with the wrong animation mapped.
11921210
return false;
11931211
}
1194-
// $FlowFixMe[incompatible-use]
1195-
const transition = ownerDocument.startViewTransition(() => {
1196-
mutationCallback();
1197-
// TODO: Wait for fonts.
1198-
afterMutationCallback();
1199-
});
1200-
transition.ready.then(layoutCallback, layoutCallback);
1201-
transition.finished.then(passiveCallback);
1202-
return true;
12031212
}
12041213

12051214
export function clearContainer(container: Container): void {

0 commit comments

Comments
 (0)