When using Material-UI with server rendering, we must use the same environment for the server and client. This has two technical implications.
as you saw on the MaterialUI Documentation page
You need to provide the same user agent for both the server context and the browser, as you saw in the documentation, but I highly recommend that you provide the βallβ user agent as you will be serving a lot of unnecessary code to the end user.
Instead, you can easily follow the MaterialUI document and pass the user agent value contained in the http headers.
With express or koa server
global.navigator = global.navigator || {}; global.navigator.userAgent = req.headers['user-agent'] || 'all';
I just checked it was added in ReactStarterKit (did not check itself) in src/server.js
global.navigator = global.navigator || {}; global.navigator.userAgent = global.navigator.userAgent || 'all';
Antoine
source share