我已经构建了my website在 Next.js 中,通过 Netlify 静态部署。每当我将其加载到新选项卡中时,在加载其余内容之前,我都会看到白色的闪光,其中 SVG Logo 可见,但没有其他内容。我不认为这是无样式内容的闪光,但它有类似的效果影响。我在桌面版 Chrome、Safari 和 Firefox 上遇到了这种情况,但在移动设备上却没有遇到这种情况。我已经排查了几个小时的问题,但距离解决还很远。 Here's the repo如果有人想看的话。非常感谢任何见解。
最佳答案
直接引用styled-components' docs :
Basically you need to add a custom pages/_document.js (if you don't have one). Then copy the logic for styled-components to inject the server side rendered styles into the .
Refer to our example in the Next.js repo for an up-to-date usage example.
在 Next.js 中使用 styled-components
时,您需要在 _document.js
中施展一些魔法。 Next.js 存储库中有一个 with-styled-components
示例。请看这里:https://github.com/vercel/next.js/blob/canary/examples/with-styled-components/pages/_document.js
关于reactjs - Next.js 渲染问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64710554/