fix(animation): improve compatibility with ssr (#25992)

resolves #25987
This commit is contained in:
Liam DeBeasi
2022-09-22 13:43:47 -05:00
committed by GitHub
parent f0d04bf873
commit 02234f69e0
2 changed files with 5 additions and 2 deletions

View File

@@ -114,7 +114,8 @@ export const generateKeyframeName = (keyframeRules: string) => {
};
export const getStyleContainer = (element: HTMLElement) => {
const rootNode = element.getRootNode() as any;
// getRootNode is not always available in SSR environments.
const rootNode = element.getRootNode !== undefined ? (element.getRootNode() as any) : element;
return rootNode.head || rootNode;
};

View File

@@ -1,4 +1,5 @@
import { raf } from '../helpers';
import { win } from '../window';
import type {
Animation,
@@ -83,7 +84,8 @@ export const createAnimation = (animationId?: string): Animation => {
const _afterAddWriteFunctions: any[] = [];
const webAnimations: any[] = [];
const supportsAnimationEffect =
typeof (AnimationEffect as any) === 'function' || typeof (window as any).AnimationEffect === 'function';
typeof (AnimationEffect as any) === 'function' ||
(win !== undefined && typeof (win as any).AnimationEffect === 'function');
const supportsWebAnimations =
typeof (Element as any) === 'function' &&
typeof (Element as any).prototype!.animate === 'function' &&