question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Re-export `Global` from `@emotion/react`

See original GitHub issue

Is your feature request related to a problem? Please describe.

  • We need Global from @emotion/react.
  • Our monorepo uses eslint-plugin-import/no-extraneous-dependencies to help us ensure we don’t import from any package not defined as a dependency in package.json. Without this, we’ve learned the hard way that Yarn installs and Webpack builds can break without notice.
  • This means we should define @emotion/react as a dependency to import Global from it.
  • Because Yarn v1 is a broken piece of 💩, yet also the only Yarn version supported by Gatsby Cloud, sometimes this leads to multiple copies of @emotion/react in our dependency tree.
  • When this happens, Emotion breaks.

Describe the solution you’d like

Since it’s poor practice to import from a transitive dependency, but unsafe to add @emotion/react as a direct dependency beside theme-ui, I think the right solution is for theme-ui to re-export Global.

<opinions> Users should never be asked to import from any transitive dependency. If we were meant to use @emotion/react directly alongside theme-ui, then @emotion/react would be a peer dependency we would install alongside theme-ui. Since it’s a direct dependency managed by theme-ui, it’s the responsibility of the theme-ui API to re-expose the right parts of it to userland. </opinions>

Describe alternatives you’ve considered

There are probably many alternatives! Futzing around with our ESLint configs, tweaking our dependency models, convincing Emotion not to be so damn fragile, finally selling the Gatsby crew on supporting actual working versions of Yarn… but I really think re-exporting Global is the right move for the project in general.

For now we’re using eslint-disable-next-line import/no-extraneous-dependencies, but the rule exists for a reason 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
lachlanjccommented, Nov 11, 2021

Appreciate the thorough explanation! Makes sense to me, so would totally accept a PR for this.

1reaction
aaronadamsCAcommented, Dec 30, 2021

Ha, I just came to close this - agreed it’s no longer relevant!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global Styles - Emotion
You can use the Global component to do this. It accepts a styles prop which accepts the same values as the css prop...
Read more >
Styling Global component using styled approach is not possible.
I found a solution! I hope this helps the next who need it. import { Global, css } from "@emotion/react"; const GlobalStyles = ......
Read more >
Enable Global Theming with Emotion? - Stack Overflow
Update for folks who uses emotion 10: import React from 'react' import { useTheme, ThemeProvider } from 'emotion-theming' import { css, ...
Read more >
How to update or remove global styles in Emotion
Re -using styles that have already been inserted whenever we use cx or interpolations. When we use the @emotion/css or @emotion/react packages, ...
Read more >
Styling a React TypeScript application with Emotion - Elliot Laws
Summary. Setup; Using the CSS prop with TypeScript; Theming; Global Styles; Conclusion. Setup. To install into the project:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found