使用Next.js & Material-UI [closed] 在第一次加载时没有应用样式。

问题描述 投票:0回答:1

我用的是 Tabs, TabTabPanel 如上所述,从材料-UI中提取的 https:/material-ui.comcomponentstabs。. 我正在结合Next.js使用它。

这是我目前的代码(我去掉了GraphQLApollo调用,Next路由和内容,以简化一点)。https:/codesandbox.iosmaterial-demo-6mq4g?file=demo.js。

在Codesandbox上,它的渲染是正确的。然而,在本地,在Chrome浏览器中,我有以下内容。

enter image description here

这就是检查器 And this is the inspector:

enter image description here

如果我点击Alice,然后再点击Bob,现在一切看起来都很干净。

enter image description here

而检查器看起来是正确的(padding被相应地应用到了 "爱丽丝 "和 "鲍勃 "上)。<Box p={3}>):

enter image description here

我不明白为什么第一次加载时没有应用样式。

有什么建议吗?

谢谢你的建议

本杰明

reactjs material-ui next.js
1个回答
1
投票

这可能是由于Next.js的SSR(Server Side Rendering)支持,因为material-ui使用JSS进行样式设计,所以样式会在JS加载后才在浏览器中加载,这不是理想的行为。我们需要事先计算好样式,并在做SSR时将这些样式注入到页面中。指南 在Material-ui的官方文档上实现正确的行为。

© www.soinside.com 2019 - 2024. All rights reserved.