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

[core] Create new @material-ui/private-theming package #25986

Merged
merged 27 commits into from
Apr 28, 2021

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented Apr 26, 2021

This PR will serve as a POC that we can remove the dependency of @material-ui/styles in @material-ui/core. Things planned to be done:

  • extract ThemeProvider, ThemeContext and useTheme hook in a new @material-ui/theming package
  • add dependency to this package in @material-ui/styles & @material-ui/core for using the context from the new package
  • duplicate utilities used in both @material-ui/styles & @material-ui/core

After this we have two options:

Option 1

Makes the use of ThemeProvider required for the @material-ui/styles. In that case we will need to:

  • remove the re-exported utilities in @material-ui/core/styles: makeStyles, styled withStyles & withTheme in favor of the ones in @material-ui/styles that will use the theme from the context
  • update docs & demos

Option 2

Make everything work as previously by extracting more things in the @material-ui/theming package

  • extract createMuiTheme in the new package, so that we can create defaultTheme outside of the core (are we fine with this?)
  • safely remove the duplicated utilities in @material-ui/core/styles: makeStyles, styled withStyles & withTheme in favor of the ones in @material-ui/styles that will use the defaultTheme

I would go with Option 1 as a follow up PR.

@mui-pr-bot
Copy link

mui-pr-bot commented Apr 26, 2021

Details of bundle changes

@material-ui/core: parsed: +0.09% , gzip: +0.02%
@material-ui/lab: parsed: +0.11% , gzip: +0.10%
@material-ui/private-theming: parsed: +Infinity% , gzip: +Infinity%

Generated by 🚫 dangerJS against ae8e265

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 26, 2021

I'm not too keen on the idea of @material-ui/theming as it seems to only fix a migration issue that is not relevant in the long term.

Regarding the different options available, I tried to poor more thoughts into it (and not reading this PR description to not be biased). Is Option A, viable?

  • @material-ui/styles has its own ThemeProvider. Only relevant for devs that can't migrate, so it lives as a custom styling solution.
  • @material-ui/core has its own ThemeProvider, for our own components, the main one we document.
  • @material-ui/styled-engne has its own ThemeProvider, for emotion or sc.
  • Developers that want to keep on using @material-ui/styles would be forced to use its ThemeProvider, in addition to the core. They would also be forced to import from @material-ui/styles.

It actually seems to be Option 1.

@mnajdova
Copy link
Member Author

I'm not too keen on the idea of @material-ui/theming as it seems to only fix a migration issue that is not relevant in the long term.

How about we make this package private, and maybe rename it to @material-ui/theming-internal. I extracted there things that are used in both packages. It has only few dependencies, and none of the JSS dependencies.

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 26, 2021

@mnajdova This could work, the advantage would be that developers that depend on @material-ui/styles will only need to change the import paths, but not the theme provider, correct? Then, I think that we will need to drop this package in v6.

I would personally vote for no extra packages if possible.

@mnajdova
Copy link
Member Author

@mnajdova This could work, the advantage would be that developers that depend on @material-ui/styles will only need to change the import paths, but not the theme provider, correct? Then, I think that we will need to drop this package in v6.

Correct.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 27, 2021
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 27, 2021
@mnajdova mnajdova changed the title [WIP][core] Create new @material-ui/theming package [core] Create new @material-ui/theming package Apr 27, 2021
@mnajdova
Copy link
Member Author

mnajdova commented Apr 27, 2021

@oliviertassinari @eps1lon are we onboard that we are good to go with Option 1 - making the use of ThemeProvider required for @material-ui/styles?

If that is the case, we can go with reviewing with this PR, and as a follow up I would remove all dependencies of @material-ui/styles from @material-ui/core. I would probably do it in multiple PRs removing one dependency at a time. I will update the docs for @material-ui/styles regarding the ThemeProvider being required in the first breaking change.

Edit: Should we name the new package to @material-ui/theming-internal?

@mnajdova mnajdova marked this pull request as ready for review April 27, 2021 15:19
@oliviertassinari oliviertassinari added the package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5. label Apr 27, 2021
@oliviertassinari
Copy link
Member

Option 1 - making the use of ThemeProvider required for @material-ui/styles?

👍 for it (BC on ThemeProvider and the import paths). This will require most of the existing projects in v4 to make the change, but the proposed alternative doesn't seem practical.

Edit: Should we name the new package to @material-ui/theming-internal?

@material-ui/private-theming? Assuming we do the above, does this package still solve a problem?

@mnajdova
Copy link
Member Author

@material-ui/private-theming? Assuming we do the above, does this package still solve a problem?

Agree on the name. The package will at least allow us to have common theme context and utils between the two packages without requiring developers to have both @material-ui/styles and @material-ui/core. Long term if we drop @material-ui/styles we can just move the utils in core.

@mnajdova
Copy link
Member Author

@material-ui/theming => @material-ui/private-theming rename done.

@@ -0,0 +1,8 @@
export { default as getThemeProps } from './getThemeProps';
Copy link
Member

Choose a reason for hiding this comment

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

For the content of the package, did you consider keeping to its bare minimum, the React context singleton, and then, duplicate all the other modules? For instance, this one, it looks like we will want to duplicate it between the core and the legacy styles package.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense, the only thing really required to be singleton is the React context. Let me update 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, I've duplicated the utilities, the only things left in the new package, are the ThemeProvider, useTheme hook and the interface for the DefaultTheme.

@mnajdova mnajdova changed the title [core] Create new @material-ui/theming package [core] Create new @material-ui/private-theming package Apr 28, 2021
expect(text()).to.equal('foobar');
expect(themes).to.have.length(1);
});

it('does not allow setting mui.nested manually', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

All tests except this one are moved to the @material-ui/private-theming package. This test had to stay here as it uses the makeStyles() utility which is not available there.

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
@mnajdova mnajdova merged commit d7c0ae5 into mui:next Apr 28, 2021
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

4 participants