From b9ae32a46e3f3acb8b512040956a79a80dff934d Mon Sep 17 00:00:00 2001 From: Daybrush <3433062+younkue@users.noreply.github.com> Date: Mon, 15 Oct 2018 15:56:19 +0900 Subject: [PATCH] fix(browser): remove global.window for node.js (#233) fix(browser): remove global.window for node.js Close #232 --- packages/react-infinitegrid/src/consts.js | 2 +- src/Watcher.js | 3 +++ src/browser.js | 8 ++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/react-infinitegrid/src/consts.js b/packages/react-infinitegrid/src/consts.js index bb5a08aa5..d3983a6ab 100644 --- a/packages/react-infinitegrid/src/consts.js +++ b/packages/react-infinitegrid/src/consts.js @@ -19,4 +19,4 @@ export const CHECK_ONLY_ERROR = 2; export const CONTAINER_CLASSNAME = "_eg-infinitegrid-container_"; export const LAYOUT_ID = "__REACT_LAYOUT_DATA_ID__"; export const DUMMY_POSITION = -999999; -export const SUPPORT_COMPUTEDSTYLE = !!("getComputedStyle" in window); +export const SUPPORT_COMPUTEDSTYLE = typeof window === "undefined" ? false : !!("getComputedStyle" in window); diff --git a/src/Watcher.js b/src/Watcher.js index 248733de2..7e15bb367 100644 --- a/src/Watcher.js +++ b/src/Watcher.js @@ -1,6 +1,9 @@ import { IS_IOS, } from "./consts"; +import { + window, +} from "./browser"; import { addEvent, removeEvent, diff --git a/src/browser.js b/src/browser.js index 4ebfe2958..0f655d0ba 100644 --- a/src/browser.js +++ b/src/browser.js @@ -1,14 +1,18 @@ /* eslint-disable no-new-func, no-nested-ternary */ +let win; + if (typeof window === "undefined") { - global.window = { + // window is undefined in node.js + win = { document: {}, navigator: { userAgent: "", }, }; +} else { + win = window; } -const win = window; /* eslint-enable no-new-func, no-nested-ternary */ export {win as window};