Closed davalapar closed 6 years ago
Reproduction repo: https://github.com/davalapar/template
yarn run dev
yarn run prod
yarn run final
yarn run nodemon
When you build the client with production settings, you need to run the server also with NODE_ENV='production'
as it changes the generated class names.
Thanks for responding, will look into it.
Hi @evik42, I tried running it with that var set but I'm still getting the same disappearing css.
NODE_ENV=production node dist/server/main.js
$ NODE_ENV=production node dist/server/main.js
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Listening @ localhost:80
Listening @ localhost:443
Same NODE_ENV setting approach at https://github.com/mui-org/material-ui/commit/956e59e7fec2466596e7f3238fc7332ea99bfa74
Update:
dangerouslyUseGlobalCSS
being true
right?@evik42's analysis is correct. You need to make the server render in production mode. NODE_ENV=production yarn run nodemon
to the trick.
@oliviertassinari thanks for responding. I tried it but unfortunately the css still disappears once the js files are loaded.
Screenshot here: https://i.imgur.com/BIjA7mk.png
Tried it with changes in webpack.config.js
too :
I also tested the generateClassName to ensure they're working on server and client side and they're indeed producing matching name of classes.
Same result of css disappearing when js loads, while the component's onClick work without problems.. Could there be anything else I've overlooked here?
It was working all fine on my side with your reproduction. webpack has nothing to do with it. It's about using the same generator on the client and the sever (same options, same node env, same version).
Adding NODE_ENV=production
to my server script has fixed the issue for me. Script command is now NODE_ENV=production run-s build start-prod
Expected Behavior
The
css
must not disappear when thejs
was loaded.Current Behavior
The
css
disappears. This does not happen in webpack development, but only in production.Steps to Reproduce
I was following the examples from the docs.
I noticed that the one from our docs here at https://material-ui.com/guides/server-rendering/ is different from the one from this github repo which is https://github.com/mui-org/material-ui/blob/master/docs/src/pages/guides/server-rendering/server-rendering.md, in which case I ended up following the latter since it solved some initial problems such as css name mismatches between the server & client. I also ensured that I've read the Troubleshooting part and didn't miss what's documented already.
The
webpack.config.js
I'm using is provided below, and I also tried commenting out the following parts related to splitChunks and runtimeChunk, but thecss
still disappears when the bundlejs
is loaded in the production build:App.jsx:
Client.jsx:
SSR.jsx:
webpack.config.js:
Context
Nothing much special just
App.jsx
with a button.When the bundle
js
is loaded, the components work great. Their styling just disappears, that's the problem.(preparing the reproduction repo right now!)
Your Environment