From 4736cfe01dc71b6fa69b76ab946b6205447c3faa Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Fri, 8 Mar 2019 17:12:31 -0800 Subject: [PATCH] Remove use of eval in dev This violates Codesandbox' CSP which does not permit unsafe-eval. Instead, just use window to get the current global. Fixes #6611 --- packages/react-router/modules/index.js | 32 ++++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/react-router/modules/index.js b/packages/react-router/modules/index.js index 989a3fc3fe..6a2a40126f 100644 --- a/packages/react-router/modules/index.js +++ b/packages/react-router/modules/index.js @@ -1,22 +1,24 @@ if (__DEV__) { - const global = (1, eval)("this"); - const key = "__react_router_build__"; - const buildNames = { cjs: "CommonJS", esm: "ES modules", umd: "UMD" }; + if (typeof window !== "undefined") { + const global = window; + const key = "__react_router_build__"; + const buildNames = { cjs: "CommonJS", esm: "ES modules", umd: "UMD" }; - if (global[key] && global[key] !== process.env.BUILD_FORMAT) { - const initialBuildName = buildNames[global[key]]; - const secondaryBuildName = buildNames[process.env.BUILD_FORMAT]; + if (global[key] && global[key] !== process.env.BUILD_FORMAT) { + const initialBuildName = buildNames[global[key]]; + const secondaryBuildName = buildNames[process.env.BUILD_FORMAT]; - // TODO: Add link to article that explains in detail how to avoid - // loading 2 different builds. - throw new Error( - `You are loading the ${secondaryBuildName} build of React Router ` + - `on a page that is already running the ${initialBuildName} ` + - `build, so things won't work right.` - ); - } + // TODO: Add link to article that explains in detail how to avoid + // loading 2 different builds. + throw new Error( + `You are loading the ${secondaryBuildName} build of React Router ` + + `on a page that is already running the ${initialBuildName} ` + + `build, so things won't work right.` + ); + } - global[key] = process.env.BUILD_FORMAT; + global[key] = process.env.BUILD_FORMAT; + } } export { default as MemoryRouter } from "./MemoryRouter";