材料样式未在生产中加载
我目前正在从事一个带有NextJ和材料UI的项目。在开发模式下一切都很好。当我构建项目时,第一页加载正常,但是当我导航到第二页时,许多组件加载而无需造型,例如对话框。
在开发模式下:
在生产构建中:
我猜想这是情感cache无法正确注入SSR的问题,或者与我的方式注入使用链接组件:
//Link from next/link
<Link href={href}>
<ButtonBase sx={{ width: "100%" }}>
<CardContent item={item} />
</ButtonBase>
</Link
如此示例一样实现情感缓存: https://github.com/mui/material-ui/tree/master/master/examples/nextjs-with-typescript
react版本:18.1.0(我已经尝试了版本17.0.2和18.0 AS出色地) 下一步:12.1.6 MUI:5.7
这个问题建议使用serverstylesheets,该片MUI5。
还有其他人经历过同样的问题吗?
I'm currently working on a project with Nextjs and Material UI. Everything works great in development mode. When I build the project, the first page loads just fine but when I navigate to a second page, a lot of the components load without styling, such as a Dialog.
In dev mode:
In the production build:
I'm guessing it's either a problem with the emotion cache not being injected properly with SSR or with the way I'm using the Link component:
//Link from next/link
<Link href={href}>
<ButtonBase sx={{ width: "100%" }}>
<CardContent item={item} />
</ButtonBase>
</Link
The emotion cache is implemented like this example: https://github.com/mui/material-ui/tree/master/examples/nextjs-with-typescript
React version: 18.1.0 (I've tried with versions 17.0.2 and 18.0 as well)
Next: 12.1.6
MUI: 5.7
This question suggests using ServerStyleSheets, which is not included in MUI5.
Has anyone else experienced the same issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经通过将这些软件包撞到最新版本来解决问题:
,我在将项目与示例repo 发现我缺少这一点:
我不确定这些动作中的哪一个实际上解决了问题,但我猜是后者。
如果您遇到类似问题,则可以尝试将其添加到Tsconfig中,看看它是否修复了问题。
I've managed to solve the issue myself by first bumping these packages to their latest versions:
Then I added a property to tsconfig.json after thoroughly comparing my project with the example repo and finding out I was missing this:
I'm not entirely sure which one of these actions actually solved the issue but I'm guessing the latter.
If you're running into a similar problem, you could try adding it to your tsconfig and see if it fixes things.
尝试更新这样的_document文件:
您可以使用默认的_个文件文件,只需添加getInitialProps Part
Try update the _document file like this:
You can use the default _document file just add the getInitialProps part