Skip to content

Commit

Permalink
Add warning if multiple versions are running (addresses #1470)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs139 committed Dec 20, 2019
1 parent 456be9a commit e275b57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,18 @@ export { keyframes } from './keyframes'
export { ClassNames } from './class-names'
export { ThemeContext, useTheme, ThemeProvider, withTheme } from './theming'
export { default as css } from './css'

if (process.env.NODE_ENV !== 'production') {
const isBrowser = typeof document !== 'undefined'
const globalKey = '__EMOTION_CORE__'
const globalContext = isBrowser ? window : global
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
}
2 changes: 1 addition & 1 deletion packages/utils/src/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit e275b57

Please sign in to comment.