React-apollo + material-ui:服务器端渲染不适用于 express

React-apollo + material-ui: server side rendering not work with express

我在使用 graphql (react-apollo) 和 material-ui 为完整的 React 应用程序制作样板时遇到了一个大问题。 我尝试了很多狗屎,但我总是遇到同样的问题:

Warning: Prop "className" did not match. Server: "MuiSvgIcon-root-60 MuiListItemIcon-root-127" Client: "MuiSvgIcon-root-60 MuiListItemIcon-root-123"

如果我登录了(问题明显来自抽屉组件),并且:

Warning: Did not expect server HTML to contain a <h1> in <div>.

如果我注销(抽屉未显示)。

您可以在此处找到完整的示例:https://github.com/CocoJr/docker-sf4-elasticsearch-graphql-react-express/tree/master/volumes/node

这是我的 server.js 文件:https://github.com/CocoJr/docker-sf4-elasticsearch-graphql-react-express/blob/master/volumes/node/src/server.js

非常感谢,伙计。

我解决了我的错误:

https://github.com/mui-org/material-ui/issues/10649#issuecomment-408624288

只需在您的 bash 中使用它即可:sed -i 's/material-ui\/core\/SvgIcon/material-ui\/core\/es\/SvgIcon/' 'node_modules/@material-ui/icons/es/utils/createSvgIcon.js'

并且一定要始终使用 material-ui 的 /es 版本,特别是对于带有 @material-ui/icons/... => @[=20= 的 SvgIcon ]/es/...