From eb4ee93a3eb1df0467809026131a01c4b84864c7 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 30 Jan 2019 18:54:53 +0100 Subject: [PATCH] fix(utils): Shim Element in non-DOM environments (#1387) 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. --- src/utils.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils.js b/src/utils.js index 209ab4f9b..c1c8effb1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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(