-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
Hot Module Replacement with MuiThemeProvider always errors #9287
Comments
@jackjwilliams Could you set up a reproduction repository so we can dig into it? |
I'll go ahead and close this, at some point I made a bunch of changes and this started working fine with HMR. |
I am experiencing exactly this same issue with material-ui@next -- even with this patch in place. |
@jackjwilliams Mind sharing what changes might have fixed this? |
@chaddjohnson, I wish I knew :/. I reorganized a bunch of stuff and after a few days I happened to notice the error went away. Sorry! I hate it when an error goes away and I don't know why lol. |
I will say that at some point I realized that asp.net core 2's HMR was conflicting with my HotModuleReplacementPlugin, so I removed it from my webpack config. I'm not sure if that's what it was, it was just a realization that I came to (that the two plugins are mutually exclusive, not complimentary). |
I changed
to
in my component wrapped by |
I had a similar issue recently (same error message but different setup). I was using express + webpack-hot-middleware + react-hot-loader. It was working fine when I was using it with Mui v0.xx, but when I was tring to migrate to Mui next something broke. And it is also the same with me that if I don't use MuiThemeprovider, or if I don't pass theme to styles, there's no error, and the setup would work. I ended up ditching react-hot-loader, and only use webpack-hot-middleware for hmr |
Using react hot loader v4 (possibly 3), I think this can be solved by moving the MuiThemeProvider one level up. eg Then having be the hot reload root component. |
So do I.. now the error log is gone 🙏🏼
export default withStyles(styles, {withTheme: true})(Navigation); export default withTheme()(withStyles(styles)(Navigation)); |
@ilhambrata I was able to get around the problem using
and moving 'use strict';
import React from 'react';
import ReactDOM from 'react-dom';
import {AppContainer} from 'react-hot-loader';
import {Provider} from 'react-redux';
import {MuiThemeProvider} from 'material-ui/styles';
import theme from './theme';
import store from './store';
import App from './app';
const render = (Component) => {
ReactDOM.render(
<MuiThemeProvider theme={theme}>
<Provider store={store}>
<AppContainer>
<Component />
</AppContainer>
</Provider>
</MuiThemeProvider>,
document.getElementById('root')
);
};
function bootstrap() {
// Render the app now that the token is fetched.
render(App);
// Initialize hot module reloading.
if (module.hot) {
module.hot.accept('./app', () => {
render(require('./app').default);
});
}
}
// Make it so.
bootstrap(); and my 'use strict';
import React from 'react';
import {CookiesProvider} from 'react-cookie';
import AppRouter from './components/appRouter';
const App = () => (
<CookiesProvider>
<AppRouter />
</CookiesProvider>
);
export default App; |
First of all thanks for the great hints. |
Is there a solution for this if your I've got an npm package doing Webpack rendering, and I'm simply passing my themed app into the render function which wraps it in I also tried doing From my testing, the only time I get these errors are when using |
Error Message: "cannot read property refs of undefined" Solution: mui/material-ui#9287 (comment)
Possibly related:
#8353
#8878
Expected Behavior
Whenever I change a value in my const styles = theme => ({..}) in Drawer (or anything else in the application), material-ui withStyles should not throw an error.
Current Behavior
Anytime I change a value in my styles definition (or anything for that matter), after a hot module replacement, the following error occurs. The UI still updates as expected, but the errors start stacking up.
Steps to Reproduce (for bugs)
Unfortunately this is a HMR issue, and I can't workup a codesandbox.io example. Here is my relevant setup (maybe I am doing something wrong?)
Steps
App.js
Drawer.js
Context
If I remove MuiThemeProvider from App.js, all works as expected with the default theme.
Doing some debugging, it looks like this line, at some point returns undefined / null:
var sheetManagerTheme = sheetManager.get(theme)
https://github.com/mui-org/material-ui/blob/023fee9092571e98814e64221015c6b669353fbe/src/styles/withStyles.js#L267
in the detach method.
Your Environment
The text was updated successfully, but these errors were encountered: