gpt4 book ai didi

webpack - 下一个 sass : Flash of unstyled content only when building for production

转载 作者:行者123 更新时间:2023-12-02 17:29:06 25 4
gpt4 key购买 nike

✅ 已解决,请参阅下面我的回复!

我正在将 Next.js 与 next-sass 一起使用。我一整天都在与一闪而过的无样式内容“FOUC”问题作斗争,测试了我在网上找到的各种解决方案,但似乎没有一个对我有用。当使用 CSS 转换时,这个问题尤其明显,因为组件将在没有任何样式的情况下可见,然后转换为其 CSS 样式。

仅当使用next build 然后使用next start 进行生产构建时,此信息才可见。在开发模式下,使用next,不存在FOUC问题。

最小示例:

// next.config.js
const withSass = require('@zeit/next-sass');
module.exports = withSass();
// scss/style.scss
body {
background-color: red;
transition: 2s all ease;
}
// pages/index.js
import React from "react";
import "../scss/style.scss";

const Home = () => (
<div>Test</div>
);

export default Home;

GitHub 存储库:https://github.com/jesperlindstrom/next-sass-fouc/

问题视频:https://drive.google.com/file/d/12yukgmgsuPKRs0TD2yYZK9F7fBC7oSkF/view?usp=sharing

我做错了什么?谢谢!

最佳答案

所以......这个问题原来是一个浏览器错误,与 Next 或 Webpack 完全无关。设法使用普通 CSS 和 HTML 进行复制,其中在加载时触发转换。该解决方案听起来很愚蠢,但解决了它:在您的 .js 文件中导入一个空的 .js 文件。我猜测它会使两个资源“阻塞”,因此等待第一次渲染......

如果有人在 Next.js 中遇到同样的问题,我会将其添加到我的 _document.js 中:

<Head>
...
<script src="/static/chrome-fix.js" />
</Head>

...并将 chrome-fix.js 作为空文件放入我的/static 中。

更多信息:https://bugs.chromium.org/p/chromium/issues/detail?id=332189

关于webpack - 下一个 sass : Flash of unstyled content only when building for production,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55316262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com