Skip to content

Commit c9eb491

Browse files
vikermanvicb
authored andcommittedMay 30, 2018
fix(animations): Fix browser detection logic (#24188)
Element type is being polyfilled on the server now and cannot be used to detect browser environment. PR Close #24188
·
6.0.96.0.4
1 parent a634a5a commit c9eb491

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed
 

‎packages/animations/browser/src/render/shared.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {AUTO_STYLE, AnimationEvent, AnimationPlayer, NoopAnimationPlayer, ɵAnim
1010
import {AnimationStyleNormalizer} from '../../src/dsl/style_normalization/animation_style_normalizer';
1111
import {AnimationDriver} from '../../src/render/animation_driver';
1212

13+
export function isBrowser() {
14+
return (typeof window !== 'undefined' && typeof window.document !== 'undefined');
15+
}
16+
1317
export function optimizeGroupPlayer(players: AnimationPlayer[]): AnimationPlayer {
1418
switch (players.length) {
1519
case 0:
@@ -138,7 +142,7 @@ let _query: (element: any, selector: string, multi: boolean) => any[] =
138142
return [];
139143
};
140144

141-
if (typeof Element != 'undefined') {
145+
if (isBrowser()) {
142146
// this is well supported in all browsers
143147
_contains = (elm1: any, elm2: any) => { return elm1.contains(elm2) as boolean; };
144148

‎packages/animations/browser/src/render/web_animations/web_animations_driver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {AnimationPlayer, ɵStyleData} from '@angular/animations';
1010
import {allowPreviousPlayerStylesMerge, balancePreviousStylesIntoKeyframes, copyStyles} from '../../util';
1111
import {AnimationDriver} from '../animation_driver';
1212
import {CssKeyframesDriver} from '../css_keyframes/css_keyframes_driver';
13-
import {containsElement, invokeQuery, matchesElement, validateStyleProperty} from '../shared';
13+
import {containsElement, invokeQuery, isBrowser, matchesElement, validateStyleProperty} from '../shared';
1414

1515
import {WebAnimationsPlayer} from './web_animations_player';
1616

@@ -75,5 +75,5 @@ export function supportsWebAnimations() {
7575
}
7676

7777
function getElementAnimateFn(): any {
78-
return (typeof Element !== 'undefined' && (<any>Element).prototype['animate']) || {};
78+
return (isBrowser() && (<any>Element).prototype['animate']) || {};
7979
}

0 commit comments

Comments
 (0)
Please sign in to comment.