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] Remove createStyles from @material-ui/core #26018

Merged
merged 43 commits into from
Apr 29, 2021

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented Apr 28, 2021

Deprecations

  • The createStyles function from @material-ui/core/styles was moved to @material-ui/styles. This helps use remove JSS from the core package.
-import { createStyles } from '@material-ui/core/styles';
+import { createStyles } from '@material-ui/styles';

One of the PRs that is necessary for removing @material-ui/styles as a dependency of @material-ui/core.

@eps1lon
Copy link
Member

eps1lon commented Apr 28, 2021

On second thought, let's not go that way. Too many possible opinionated discussions. Let's keep it as function createStyles(): never; in the declarations and identity function at runtime.

@mnajdova
Copy link
Member Author

mnajdova commented Apr 28, 2021

On second thought, let's not go that way. Too many possible opinionated discussions. Let's keep it as function createStyles(): never; in the declarations and identity function at runtime.

Just to make sure I understand, are you saying I should add it back to @material-ui/core, just not to reference it from @material-ui/styles?

Edit: @eps1lon does this look correct e5ea6c2


// let warnOnce = false;

// To remove in v5
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this to v6

Copy link
Member

Choose a reason for hiding this comment

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

Should we add a deprecation notice now? It was mentioned that it's only needed for notistack. notistack could clone this helper.

Also, with #1824 and #18098 we will likely roll out our own solution to the problem, so this demo https://next.material-ui.com/components/snackbars/#notistack is likely on its way out, in the long term.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added back warning

docs/src/pages/styles/advanced/ThemeNesting.tsx Outdated Show resolved Hide resolved
@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 28, 2021

Just to make sure I understand, are you saying I should add it back to @material-ui/core, just not to reference it from @material-ui/styles?

I understood this as: it's too early to remove the module from the codebase, moving it from the core to styles should be enough.

@mnajdova
Copy link
Member Author

I understood this as: it's too early to remove the module from the codebase, moving it from the core to styles should be enough.

Alright, but I cannot remove it from core completely because of the failing issue with notistack. So far I just replaced the imports, but looks like it’s better to just remove the usages of createStyles. Correct?

@eps1lon
Copy link
Member

eps1lon commented Apr 29, 2021

but looks like it’s better to just remove the usages of createStyles. Correct?

Yes. We'll just keep it at runtime to not cause crashes needlessly.

Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

If the docs demos don't use createStyles we can drop the babel plugin as well. That was only used for internal usage.

@@ -179,7 +179,8 @@ interface Props {
However this isn't very [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) because it requires you to maintain the class names (`'root'`, `'paper'`, `'button'`, ...) in two different places. We provide a type operator `WithStyles` to help with this, so that you can just write:

```ts
import { WithStyles, createStyles } from '@material-ui/core';
import { createStyles } from '@material-ui/styles';
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove the usage here as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like if we remove this we should update the whole page, as it actually talks about how to solve typescript issues for withStyles. Should we recommend casting to const there too?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, let's do this another time.

@mnajdova
Copy link
Member Author

@eps1lon how should we fix the type errors? There are issues on each file I touched. There are types issues on classes.root as well as on withStyles args.

@eps1lon
Copy link
Member

eps1lon commented Apr 29, 2021

Where removal of createStyles causes types issues use as const assertions:

-const styles = createStyles({});
+const styles = {} as const;

@mnajdova
Copy link
Member Author

If the docs demos don't use createStyles we can drop the babel plugin as well. That was only used for internal usage.

Removed.


// let warnOnce = false;

// To remove in v5
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a deprecation notice now? It was mentioned that it's only needed for notistack. notistack could clone this helper.

Also, with #1824 and #18098 we will likely roll out our own solution to the problem, so this demo https://next.material-ui.com/components/snackbars/#notistack is likely on its way out, in the long term.

docs/src/pages/guides/migration-v4/migration-v4.md Outdated Show resolved Hide resolved
mnajdova and others added 2 commits April 29, 2021 12:28
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

+291 −716

😍

@eps1lon eps1lon added breaking change package: material-ui Specific to @mui/material package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5. labels Apr 29, 2021
@mnajdova mnajdova merged commit 14a4289 into mui:next Apr 29, 2021
@oliviertassinari oliviertassinari added deprecation New deprecation message and removed breaking change labels Apr 29, 2021
@oliviertassinari
Copy link
Member

I have updated the label as it seems to only be a depreciation now (there are no breaking changes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation New deprecation message package: material-ui Specific to @mui/material 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