@@ -1187,19 +1187,28 @@ export function startViewTransition(
1187
1187
rootContainer . nodeType === DOCUMENT_NODE
1188
1188
? rootContainer
1189
1189
: 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.
1192
1210
return false ;
1193
1211
}
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 ;
1203
1212
}
1204
1213
1205
1214
export function clearContainer ( container : Container ) : void {
0 commit comments