-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle cases when Animation.persist() does not exist #33282
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "fix: handle case when Animation.persist() does not exist", | ||
"packageName": "@fluentui/react-motion", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ import * as React from 'react'; | |
import type { AnimationHandle, AtomMotion } from '../types'; | ||
|
||
function useAnimateAtomsInSupportedEnvironment() { | ||
// eslint-disable-next-line @nx/workspace-no-restricted-globals | ||
const SUPPORTS_PERSIST = typeof window !== 'undefined' && typeof window.Animation?.prototype.persist === 'function'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in love with having this here. Ideally it would live in global scope because I moved it here because I could not find a good way to test it with Jest. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could move this to a function check in another module and mock that moduile in the tests, but I don't mind keeping it like this |
||
|
||
return React.useCallback( | ||
( | ||
element: HTMLElement, | ||
|
@@ -19,10 +22,10 @@ function useAnimateAtomsInSupportedEnvironment() { | |
fill: 'forwards', | ||
|
||
...params, | ||
...(isReducedMotion && { duration: 1 }), | ||
...((isReducedMotion || !SUPPORTS_PERSIST) && { duration: 1 }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need to go through the reduced motion path? the animation will still work without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't strictly need to. My thinking is twofold:
Open to changing this but as-is seems best to me. |
||
}); | ||
|
||
animation.persist(); | ||
SUPPORTS_PERSIST && animation.persist(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about we just create a polyfill for https://developer.mozilla.org/en-US/docs/Web/API/Animation/commitStyles? if (SUPPORTS_PERSIST) {
animation.persist();
} else {
const resultKeyframe = keyframes[keyframes.length - 1];
Object.assign(element.style, resultKeyframe);
} This would ensure that we don't have weirdness when multiple animations are composed https://stackblitz.com/edit/typescript-hqxwu6?file=index.ts |
||
|
||
return animation; | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕵🏾♀️ visual regressions to review in the fluentuiv9 Visual Regression Report
Avatar Converged 2 screenshots
Drawer 2 screenshots