@@ -28,32 +28,42 @@ function useAnimateAtomsInSupportedEnvironment() {
2828 const atoms = Array . isArray ( value ) ? value : [ value ] ;
2929 const { isReducedMotion } = options ;
3030
31- const animations = atoms . map ( motion => {
32- // Grab the custom reduced motion definition if it exists, or fall back to the default reduced motion.
33- const { keyframes : motionKeyframes , reducedMotion = DEFAULT_REDUCED_MOTION_ATOM , ...params } = motion ;
34- // Grab the reduced motion keyframes if they exist, or fall back to the regular keyframes.
35- const { keyframes : reducedMotionKeyframes = motionKeyframes , ...reducedMotionParams } = reducedMotion ;
36-
37- const animationKeyframes : Keyframe [ ] = isReducedMotion ? reducedMotionKeyframes : motionKeyframes ;
38- const animationParams : KeyframeEffectOptions = {
39- ...DEFAULT_ANIMATION_OPTIONS ,
40- ...params ,
41-
42- // Use reduced motion overrides (e.g. duration, easing) when reduced motion is enabled
43- ...( isReducedMotion && reducedMotionParams ) ,
44- } ;
45-
46- const animation = element . animate ( animationKeyframes , animationParams ) ;
47-
48- if ( SUPPORTS_PERSIST ) {
49- animation . persist ( ) ;
50- } else {
51- const resultKeyframe = animationKeyframes [ animationKeyframes . length - 1 ] ;
52- Object . assign ( element . style ?? { } , resultKeyframe ) ;
53- }
54-
55- return animation ;
56- } ) ;
31+ const animations = atoms
32+ . map ( motion => {
33+ // Grab the custom reduced motion definition if it exists, or fall back to the default reduced motion.
34+ const { keyframes : motionKeyframes , reducedMotion = DEFAULT_REDUCED_MOTION_ATOM , ...params } = motion ;
35+ // Grab the reduced motion keyframes if they exist, or fall back to the regular keyframes.
36+ const { keyframes : reducedMotionKeyframes = motionKeyframes , ...reducedMotionParams } = reducedMotion ;
37+
38+ const animationKeyframes : Keyframe [ ] = isReducedMotion ? reducedMotionKeyframes : motionKeyframes ;
39+ const animationParams : KeyframeEffectOptions = {
40+ ...DEFAULT_ANIMATION_OPTIONS ,
41+ ...params ,
42+
43+ // Use reduced motion overrides (e.g. duration, easing) when reduced motion is enabled
44+ ...( isReducedMotion && reducedMotionParams ) ,
45+ } ;
46+
47+ try {
48+ // Firefox can throw an error when calling `element.animate()`.
49+ // See: https://github.com/microsoft/fluentui/issues/33902
50+ const animation = element . animate ( animationKeyframes , animationParams ) ;
51+
52+ if ( SUPPORTS_PERSIST ) {
53+ // Chromium browsers can return null when calling `element.animate()`.
54+ // See: https://github.com/microsoft/fluentui/issues/33902
55+ animation ?. persist ( ) ;
56+ } else {
57+ const resultKeyframe = animationKeyframes [ animationKeyframes . length - 1 ] ;
58+ Object . assign ( element . style ?? { } , resultKeyframe ) ;
59+ }
60+
61+ return animation ;
62+ } catch ( e ) {
63+ return null ;
64+ }
65+ } )
66+ . filter ( animation => ! ! animation ) as Animation [ ] ;
5767
5868 return {
5969 set playbackRate ( rate : number ) {
0 commit comments