简体   繁体   English

Next.js 渲染问题

[英]Next.js rendering issue

I've built my website in Next.js, deployed statically via Netlify.我在 Next.js 中构建了我的网站,并通过 Netlify 静态部署。 Whenever I load it in a new tab, I get a white flash where the SVG logos are visible but nothing else, before the rest of the content loads in. I don't think this is a Flash Of Unstyled Content but it has a similar effect.每当我在新选项卡中加载它时,在加载其余内容之前,我会看到一个白色的闪光,其中 SVG 标志是可见的,但没有其他内容。我不认为这是无样式内容的闪光,但它有类似的影响。 I'm experiencing on desktop Chrome, Safari and Firefox, but doesn't seen to be happening on mobile.我在桌面 Chrome、Safari 和 Firefox 上体验过,但在移动设备上看不到。 I've been trouble shooting for hours and am no closer to solving.我已经解决了几个小时的问题,但离解决还很远。 Here's the repo if anyone wants to have a look.如果有人想看看,这里是 repo Any insights greatly appreciated.任何见解都非常感谢。

Quoting directly from styled-components' docs :直接引用样式组件的文档

Basically you need to add a custom pages/_document.js (if you don't have one).基本上你需要添加一个自定义 pages/_document.js (如果你没有)。 Then copy the logic for styled-components to inject the server side rendered styles into the .然后复制 styled-components 的逻辑以将服务器端呈现的样式注入到 .

Refer to our example in the Next.js repo for an up-to-date usage example.有关最新的使用示例,请参阅 Next.js 存储库中的示例。

When using styled-components with Next.js you need to do a little magic in the _document.js .在 Next.js 中使用styled-components ,您需要在_document.js做一些魔法。 There is a with-styled-components example in the Next.js' repository. Next.js 的存储库中有一个with-styled-components示例。 Please see here: https://github.com/vercel/next.js/blob/canary/examples/with-styled-components/pages/_document.js请看这里: https : //github.com/vercel/next.js/blob/canary/examples/with-styled-components/pages/_document.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM