Search code examples
reactjsisomorphic-javascriptmaterial-uireact-starter-kit

React Starter Kit and Material UI: userAgent should be supplied in the muiTheme context for server-side rendering


With the React Starter Kit, I add Material UI as follows:

npm install material-ui --save

and the following import to a component:

import RaisedButton from 'material-ui/lib/raised-button';

and:

<RaisedButton label="Default" />

I get the following error:

Warning: Material-UI: userAgent should be supplied in the muiTheme context for server-side rendering.

According to Material UI's documentation, it says I'd need to address three things:

  1. autoprefixer and the user agent
  2. process.env.NODE_ENV

What code should I put in and where exactly, specifically with the React Starter Kit?

P.S. this solution does not work for me :-/


Solution

  • This works for me. Add this to server.js:

    global.navigator = { userAgent: 'all' };
    

    Then verify that you see multiple vendor prefixes used like in this screengrab showing -webkit and -ms both being used:

    enter image description here