Skip to content

Commit

Permalink
fix(getPrefix): ensure documentElement.style actually exists
Browse files Browse the repository at this point in the history
Fixes #574, #575
  • Loading branch information
STRML committed Jun 3, 2021
1 parent 72a7660 commit 22b0615
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/utils/getPrefix.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// @flow
const prefixes = ['Moz', 'Webkit', 'O', 'ms'];
export function getPrefix(prop: string='transform'): string {
// Checking specifically for 'window.document' is for pseudo-browser server-side
// environments that define 'window' as the global context.
// E.g. React-rails (see https://github.com/reactjs/react-rails/pull/84)
if (typeof window === 'undefined' || typeof window.document === 'undefined') return '';

const style = window.document.documentElement.style;
// Ensure we're running in an environment where there is actually a global
// `window` obj
if (typeof window === 'undefined') return '';

// If we're in a pseudo-browser server-side environment, this access
// path may not exist, so bail out if it doesn't.
const style = window.document?.documentElement?.style;
if (!style) return '';

if (prop in style) return '';

Expand Down

0 comments on commit 22b0615

Please sign in to comment.