尝试禁用react_devtools_backend.js nextjs

发布于 2025-02-07 16:56:13 字数 908 浏览 2 评论 0原文

最近,我添加了react devtools后端扩展程序,我注意到它会导致2个附加组件渲染(我正在使用nextjs框架),这并不是什么问题在开发中,当发布时,这确实会达到网站的性能,并且我正在尝试将其禁用,并且我已经在_document.js文件中添加了以下代码:

import { Html, Head, Main, NextScript } from "next/document";
import Script from "next/script";

export default function Document() {
    return (
        <Html lang="en-US">
            <Head />
            <body>
                <Main />
                <NextScript />
                <Script
                    strategy="beforeInteractive"
                    dangerouslySetInnerHTML={{
                        __html: `if(typeof window.__REACT_DEVTOOLS_GLOBAL_HOOK__ === 'object'){ __REACT_DEVTOOLS_GLOBAL_HOOK__.inject = function() {}; }`,
                    }}
                />
            </body>
        </Html>
    );
}

但是没有更改任何事物。

recently I've added the react devtools backend extension which I noticed is causing 2 additional component renders (I'm using Nextjs framework) which isn't so much of a problem in development however when published this would really hit the websites performance and I'm trying to disable it, and to do so I've adding the following code in _document.js file:

import { Html, Head, Main, NextScript } from "next/document";
import Script from "next/script";

export default function Document() {
    return (
        <Html lang="en-US">
            <Head />
            <body>
                <Main />
                <NextScript />
                <Script
                    strategy="beforeInteractive"
                    dangerouslySetInnerHTML={{
                        __html: `if(typeof window.__REACT_DEVTOOLS_GLOBAL_HOOK__ === 'object'){ __REACT_DEVTOOLS_GLOBAL_HOOK__.inject = function() {}; }`,
                    }}
                />
            </body>
        </Html>
    );
}

But hasn't changed anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文