Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error in alternative JS environments #2500

Conversation

Jarred-Sumner
Copy link
Contributor

@Jarred-Sumner Jarred-Sumner commented Oct 8, 2021

Use globalThis instead of window || global when checking if multiple copies of @emotion/react are running

Why:

Bun.js, a new JS runtime environment I'm working on - one quirk is it reads from the "browser" field in package.json. This improves compatibility for many npm packages, but sometimes breaks stuff.

@emotion/react is one case where that doesn't work, but the fix is simple and also improves @emotion/react's compatibility with web workers (if there is a usecase for that)

CleanShot 2021-10-07 at 18 39 17@2x

How:

globalThis is the global context identifier available in all major JavaScript engines newer than Internet Explorer 11. It works in Deno, Node.js 12.0.0+, web workers, web browsers, etc. caniuse

For maximum compatibility, the code checks globalThis is not undefined before falling back to either window or global (as before).

Checklist:

  • Documentation N/A
  • Tests (manually)
  • Code complete
  • Changeset

Also I'm not actually sure if a changeset is appropriate here

@changeset-bot
Copy link

changeset-bot bot commented Oct 8, 2021

🦋 Changeset detected

Latest commit: ef0f17a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@emotion/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 8, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ef0f17a:

Sandbox Source
Emotion Configuration

@Jarred-Sumner
Copy link
Contributor Author

Error: 26:11 error 'globalThis' is not defined no-undef

Looks like eslint is unaware of globalThis. I'll google how to fix that

@codecov
Copy link

codecov bot commented Oct 8, 2021

Codecov Report

Merging #2500 (ef0f17a) into main (84522de) will decrease coverage by 0.14%.
The diff coverage is 0.00%.

Impacted Files Coverage Δ
packages/react/src/index.js 30.76% <0.00%> (-13.68%) ⬇️

@emmatown emmatown merged commit eda5e68 into emotion-js:main Oct 8, 2021
This was referenced Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants