From 99551471371352af0c447f8514dafed87b8bbc58 Mon Sep 17 00:00:00 2001 From: Andrew Stephens Date: Fri, 6 Dec 2019 14:15:16 -0500 Subject: [PATCH] Add warning if multiple versions are running (addresses #1470) --- packages/core/src/utils.js | 17 +++++++++++++++++ packages/utils/src/index.js | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/core/src/utils.js b/packages/core/src/utils.js index a7d96af4ac..62d6910a24 100644 --- a/packages/core/src/utils.js +++ b/packages/core/src/utils.js @@ -1,2 +1,19 @@ // @flow export let isBrowser = typeof document !== 'undefined' + +const globalKey = '__EMOTION_CORE__' +const globalContext = isBrowser ? window : global + +export function checkForMultipleVersions() { + if (process.env.NODE_ENV !== 'production') { + if (globalContext[globalKey]) { + console.warn( + 'You are loading @emotion/core when it is already loaded. Running' + + 'multiple instances may cause problems. This can happen if multiple ' + + 'versions are used, or if multiple builds of the same version are ' + + 'used.' + ) + } + globalContext[globalKey] = true + } +} diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index 2347bbd33d..62a86f817a 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -1,7 +1,7 @@ // @flow import type { RegisteredCache, EmotionCache, SerializedStyles } from './types' -let isBrowser = typeof document !== 'undefined' +const isBrowser = typeof document !== 'undefined' export function getRegisteredStyles( registered: RegisteredCache,