Skip to content

Commit

Permalink
fix(utils): Shim Element in non-DOM environments (#1387)
Browse files Browse the repository at this point in the history
The function `DOMElement` in `utils.js` throws a `ReferenceError` in non-DOM environments such as Node, due to the fact that it references `Element` on the right-hand side  of an `instanceof` check, which is (most probably) undefined in non-DOM environments.

This pull request adds a small shim for the `Element` object in order to prevent `DOMElement` from throwing an error if `Element` is not defined.
  • Loading branch information
fabianishere authored and TheSharpieOne committed Jan 30, 2019
1 parent 5cc9af5 commit eb4ee93
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/utils.js
Expand Up @@ -113,6 +113,9 @@ export function deprecated(propType, explanation) {
};
}

// Shim Element if needed (e.g. in Node environment)
const Element = typeof window === 'object' && window.Element || function() {};

export function DOMElement(props, propName, componentName) {
if (!(props[propName] instanceof Element)) {
return new Error(
Expand Down

0 comments on commit eb4ee93

Please sign in to comment.