Skip to content

Commit

Permalink
Fix error in alternative JS environments (#2500)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Oct 8, 2021
1 parent 84522de commit eda5e68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/hip-cherries-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/react': patch
---

Fix error loading @emotion/react in alternative JS environments
9 changes: 8 additions & 1 deletion packages/react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ if (process.env.NODE_ENV !== 'production') {
const isJest = typeof jest !== 'undefined'

if (isBrowser && !isJest) {
const globalContext = isBrowser ? window : global
// globalThis has wide browser support - https://caniuse.com/?search=globalThis, Node.js 12 and later
const globalContext =
// $FlowIgnore
typeof globalThis !== 'undefined'
? globalThis // eslint-disable-line no-undef
: isBrowser
? window
: global
const globalKey = `__EMOTION_REACT_${pkg.version.split('.')[0]}__`
if (globalContext[globalKey]) {
console.warn(
Expand Down

0 comments on commit eda5e68

Please sign in to comment.