reactjs - Next.js 渲染问题

标签 reactjs frontend next.js netlify fouc

我已经构建了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/

相关文章:

javascript - 仅包含导出的文件会降低测试覆盖率 Jest

css - 设计比我的显示器视口(viewport)更宽的页面

mysql - TYPO3前端登录创建加密密码

javascript - React HTMLAudioElement 不会暂停

javascript - Next.js 与 Swagger

reactjs - 如何正确模拟 i18next

reactjs - 刷新 React 组件或 Flux/Redux 中的逻辑?

javascript - react app中 token 过期时如何注销用户

javascript - 如何动态调整自定义 CSS 属性?

javascript - 实现多语言 url nextjs 和 next-i18n-next