[docs] 0.x => 1.x migration guide
I apologize if this has been addressed already. I spent some time searching previous issues but didn't see anything obvious. It would be immensely helpful if a migration was published to help those heavily invested in the 0.x version of MUI migrate to 1.x.
@rsolomon That's a great question, thanks for asking.
I think that we should wait the beta or pre-releases version before starting working on a migration guide. Thing changes, I would rather keep the guide close to the v1.0.0 release.
I don't think that we will be able to get a migration guide covering everything, but, we can try our best to match 80% of it with 20% of the effort. Ideally, the migration guide would be written by someone how did that migration.
Personally, I have migrated my codebases a long time ago to the next branch, actually started two projects with it. So it's unlikely I work on it, but I will help anyone interested.
To ease the migration process, you can install both versions of the same time with yarn alias:
yarn add material-ui@latest
yarn add material-ui-next@npm:material-ui@next
then
import FlatButton from 'material-ui/FlatButton'; // v0.x
import Button from 'material-ui-next/Button'; // v1.x
A migration guide would be incredibly helpful, so I'm glad that this is being tracked for the v1.0.0-prerelease. Wondering kind of content will be included. I'd love to see:
- Component comparisons including:
- What's been renamed, condensed, deprecated
- How existing component instances need to be updated
- Theme or other core updates that need to be made
Is this in progress?
@oliviertassinari Installing both versions simultaneously sounds like a workable transition strategy, but in practice each version's MuiThemeProvider theme structure is different enough that I haven't had success in getting both versions to coexist peacefully in the same project.
Once solution to this could be including an MuiThemeProvider container for each interface section rather than a single container for the entire app, and migrating each section from v0.18 to v1 independently. Another potential solution could be nesting multiple MuiThemeProviders, which appears to be again supported after it's intentional deprecation in #4155. In my tests, the latter approach results in "Cannot read property 'floatingLabelColor' of undefined" errors or elements turning black when interacted, depending on whether I nest the v0.18 or v1 theme as a child of the other. Any thoughts on making this work successfully?
[edit] I now have elements from both V0.18 and V1 playing nicely together! For others who are interested, here's the approach that worked:
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import MuiThemeProviderNext from 'material-ui-next/styles/MuiThemeProvider';
import {muiThemev018, muiThemev1} from '../styles/AppStyle';
//...
<MuiThemeProviderNext theme={muiThemev1}>
<MuiThemeProvider muiTheme={muiThemev018}>
// ...
</MuiThemeProvider>
</MuiThemeProviderNext>
Another potential solution could be nesting multiple MuiThemeProviders
@AubreyF This is what I have been doing on SplitMe.
import FlatButton from 'material-ui/FlatButton'; // v0.x
import Button from 'material-ui-next/Button'; // v1.x
Works really well apart from where there is a peer-dependency on 'material-ui' when the wrong version can be resolved (particularly with material-ui-icons). This can be fixed with a webpack plugin to rewrite requests from the material-ui-icons (or any other module) and redirect them to material-ui-next.
Example plugin is here: https://gist.github.com/eyn/deda28b68390fc81cbe7145cc43513ea
Just add it to your webpack config and include it under the config's resolve key:
resolve: {
extensions: [".jsx", ".js", ".json"],
plugins: [MaterialUIIconResolver]
},
For those who wonder how to add webpack config to your create-react-app project check out react-app-rewired. Worked for me like a charm
Hi,
I would like to begin migration from v0.XX.X to v1 too, and I would like to install them both.
How can I do that using NPM please ? I couldn't find a way to alias material-ui-next and use both in my application.
Any help would be nice, thank you !
There is no longer a need to use the Webpack Plugin for material-ui-icons - see here: #8458
Just wanted to mention how I did it on a project using NPM's package.json, for those of you who do not wish to move from npm to yarn -
TL;DR: Clone the v1-beta branch, build it and push the build directory as a new git repository aliased under a new name. Then npm install directly from the git repository.
- Clone and cd into this repository and
git checkout v1-beta. - Run
yarn && yarn build - Copy all the contents inside the
/builddirectory into a new directory. - Change the package name inside the package.json of the built version to an alias of your choice, e.g.
material-ui-next. - Init a git repository and push it to convenient remote, say, Github.
npm i --save git+https://github.com/<your-username>/material-ui-next.gitshould install the aliased version of the repository, and you can use it along with your v0 installation as highlighted by @AubreyF.
package.json
"material-ui": "^0.19.4",
"material-ui-next": "git+https://github.com/uplevel-technology/material-ui-next.git",
"material-ui-icons": "^1.0.0-beta.17",
It's not the most ideal process as you have to manually keep updating your aliased repository from the remote branch, but I am willing to pay this price for a smooth transition from v0 to v1.
@oliviertassinari, Thank you for the solution! The Snackbar on V1 is awesome
But our build tools (jenkins) doesn't seem to understand 'material-ui-next': 'yarn:material-ui@next'
Any suggestions?
@Amol023 We had the same issue, and just used the
"material-ui-next": "git+https://github.com/uplevel-technology/material-ui-next.git",
suggested by @sagar-sm which appeased jenkins.
Hi everyone,
I am also migrating from material-ui 0.x to 1.x and the combination of the two version is working fine, thanks to the tip from @oliviertassinari.
Although I am struggling with the theme customization. I tried to merge the two objects generated respectively from getMuiTheme() and createMuiTheme(), although the result looks fine not all the components are adapting to the theme.
Here is the Theme code:
const appTheme = getMuiTheme({
fontFamily: 'Montserrat, sans-serif',
type: 'light',
palette: {
primary1Color: '#fdd835',
primary3Color: '#102027',
accent1Color: '#0097a7',
accent3Color: '#102027',
textColor: '#000000',
secondaryTextColor: '#000000',
alternateTextColor: '#102027',
disabledColor: '#AEAEAE',
canvasColor: '#FFFFFF',
},
userAgent: 'all',
});
// for migration to material-ui-next
const nextTheme = createMuiTheme({
palette: {
type: 'light',
primary: {
...
main: '#fdd835',
...
},
secondary: {
...
main: '#004a54',
...
},
background: {
paper: "#ffffff",
...
},
types: {
light: {
text: {
primary: '#ffffff',
},
background: {
paper: "#ffffff",
default: "#ffffff",
appBar: "#ffffff",
contentFrame: "#ffffff",
chip: "#ffffff",
avatar: "#ffffff",
},
...
},
},
},
typography: {
fontFamily: 'Montserrat, sans-serif',
},
});
const migrationTheme = Object.assign(appTheme, nextTheme);
export default migrationTheme;
Then I import it and feed it to the MuiThemeProvider:
/components/App.js
<MuiThemeProvider muiTheme={Theme} theme={Theme}>
<div>
{children}
</div>
</MuiThemeProvider>
Do you guys have an idea why it's not working?
UPDATE
For anyone who encountered the same problem I actually found a solution to this issue.
You just have to wrap the main component inside a MuiThemeProvider and pass to the theme prop the material-ui-next theme object.
<MuiThemeProvider theme={Theme}>
<MainComponent />
</MuiThemeProvider>
Hello,
When using typescript, is there a specific version of the @types/material-ui to use? ^0.20.7 seem to have some of the types.
Thanks,
Hi, I just updated to the latest and didn't see where or why Reboot got renamed or deprecated. I had to change the "material-ui/Reboot" import to "cssBaseline". There was no documentation on this on this page https://material-ui.com/style/css-baseline/.
Can you make note that Reboot is deprecated and needs to be replaced with CssBaseline? Also can you make note on the css-baseline page, that the CssBaseline must before you are using a BrowserRouter. Ex:
<MuiThemeProvider>
<CssBaseline/>
<BrowserRouter>
<!-- Main Component -->
</BrowserRouter>
</MuiThemeProvider>
@tqle You need to pay attention to the release notes.
@nWidart TypeScript definitions are hosted on Material-UI. You do no longer need the @types/material-ui dependency.
Thank you Olivier. I missed that in the release notes.
1.0 newbie question: Do I need to separately install jss and react-jss or are JSS features already built in to material-ui?
@devuxer Please try to avoid piling on to existing issues with unrelated questions. That being said, welcome!
The answer to your question is in the docs (and the README):
https://material-ui.com/getting-started/installation/ https://material-ui.com/getting-started/usage/#quick-start
@mbrookes,
Apologies for piling onto this issue, but I am in fact trying to migrate from 0.x to 1.0, and this was something I thought would be something of concern to others trying to make the same leap.
Thank you for those links, but I read both of those before posting, and "JSS" doesn't appear on either page. There are pages that discuss JSS, but I'm still not clear on whether I need additional JSS npm packages or if material-ui is all I need.
EDIT: Ahh, I think I found my answer in the FAQ. Don't know how I missed that the first time around.