From 8d48673e3540869bb1ae989f2a95931624a36cec Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Mon, 6 Jan 2025 13:04:40 -0500 Subject: [PATCH] Only support View Transitions v2 --- .../src/client/ReactFiberConfigDOM.js | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js index dbb552a63f7..f957b527699 100644 --- a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js +++ b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js @@ -1187,19 +1187,28 @@ export function startViewTransition( rootContainer.nodeType === DOCUMENT_NODE ? rootContainer : rootContainer.ownerDocument; - // $FlowFixMe[prop-missing] - if (typeof ownerDocument.startViewTransition !== 'function') { + try { + // $FlowFixMe[prop-missing] + const transition = ownerDocument.startViewTransition({ + update() { + mutationCallback(); + // TODO: Wait for fonts. + afterMutationCallback(); + }, + types: null, // TODO: Provide types. + }); + transition.ready.then(layoutCallback, layoutCallback); + transition.finished.then(passiveCallback); + return true; + } catch (x) { + // We use the error as feature detection. + // The only thing that should throw is if startViewTransition is missing + // or if it doesn't accept the object form. Other errors are async. + // I.e. it's before the View Transitions v2 spec. We only support View + // Transitions v2 otherwise we fallback to not animating to ensure that + // we're not animating with the wrong animation mapped. return false; } - // $FlowFixMe[incompatible-use] - const transition = ownerDocument.startViewTransition(() => { - mutationCallback(); - // TODO: Wait for fonts. - afterMutationCallback(); - }); - transition.ready.then(layoutCallback, layoutCallback); - transition.finished.then(passiveCallback); - return true; } export function clearContainer(container: Container): void {