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

[styled] Specify emotion & styled-components as optional peer dependencies #22808

Merged
merged 10 commits into from Oct 5, 2020

Conversation

mnajdova
Copy link
Member

@@ -41,6 +41,14 @@
"@emotion/core": "^10.0.27",
"@emotion/styled": "^10.0.27"
},
"peerDependenciesMeta": {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we specify these as regular peer dependencies here and as optional peer dependencies only in the core? Same would apply for the @material-ui/styled-engine-sc

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving conversation from #22788 (review) here

image

@oliviertassinari @eps1lon

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objection, no strong point of view either:

Pros:

  • Avoid warning with styled-components (counter-argument: nobody looks at these warnings anymore, I don't.)

Cons:

  • Force to run the code to realize you forgot to install the emotion peer dependency (counter-argument: nobody looks at these warnings anymore, I don't.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with optional everywhere for now and see how it will go then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(counter-argument: nobody looks at these warnings anymore, I don't.)

You're also part of the problem why "nobody" looks at these. It's pretty straight forward to fix them but many (especially library authors) just ignore them right from the start because "it works on my machine". Apart from hoisted peer dependencies I've never seen a peer dep warnings that's not an actual issue and just works with the exact same declared dependencies (which rarely happens because lib consumers don't pull in dev deps).

So peer dep warnings are important. It's ok to ignore them as an app dev but as a library author you actually ship problems to your users.

These are required peer deps as far as I can tell so they shouldn't be marked as optional. Hoisting them just isn't supported in yarn v1. A proper test to verify correctness of the tree would be installing with pnpm or yarn v2 (with and without PnP).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If developers have configured correctly styled-engine-sc in their bundler as alias, the warning are not meaningful. The question is then, should we try to fix these warnings, or should we consider that they should know that once that the alias is configured they no longer need emotion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eps1lon Agree, I think that npm warnings should be avoided as much as possible.

We haven't that many great options, the one I cant think of outside the changes proposed (1.):

  1. We can make emotion a direct dependency. But then, this can lead to the duplicated version installed. This would be completely fine if it wasn't for the singletons. If we use our own ThemeProvider the singleton on the theme context is solved. However, I imagine would still have issues with the cache, and the CSS injection order.
  2. We can make @material-ui/styled-engine a peer dependency. But it adds to the complexity of getting started.
  3. We do nothing

Happy to try 1. out.

Copy link
Member Author

@mnajdova mnajdova Sep 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologizes I am a bit confused at this moment. What exactly is the plan? Should we add these as optional or not?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for the options in this order of preference: 1 > 3 > 4 > 2. @eps1lon what would you recommend?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then, this can lead to the duplicated version installed. This would be completely fine if it wasn't for the singletons.

I can not stress this enough: This would not be fine. It causes bundle bundle bloat.

I'll need to think about this a bit more and will talk to some package manager folks how they would recommend we move forward. We probably should need to mark the styled-engine as peer not the underlying style library. That's not that big of an issue since we already have to install peers anyway. And with npm 7 that won't be an issue at all anyway. This PR is fine for now.

@mui-pr-bot
Copy link

mui-pr-bot commented Sep 29, 2020

No bundle size changes comparing 1240860...d774066

Generated by 🚫 dangerJS against d774066

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
@mnajdova mnajdova merged commit 4b56084 into mui:next Oct 5, 2020
@oliviertassinari oliviertassinari changed the title [styled-engine] Specify emotion & styled-components as optional peer dependencies [styled] Specify emotion & styled-components as optional peer dependencies Oct 10, 2020
@zannager zannager added the package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5. label Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants