From 00eb0e3ebd42a03900d6b0cb44d0c4bd94360111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Wed, 8 Jan 2025 15:52:30 +0800 Subject: [PATCH] chore: move trace to async (#52300) --- .dumi/theme/builtins/Previewer/CodeBlockButton.tsx | 12 ++++++++++++ .dumirc.ts | 7 ------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.dumi/theme/builtins/Previewer/CodeBlockButton.tsx b/.dumi/theme/builtins/Previewer/CodeBlockButton.tsx index 1c50a538cc..5c5828ad37 100644 --- a/.dumi/theme/builtins/Previewer/CodeBlockButton.tsx +++ b/.dumi/theme/builtins/Previewer/CodeBlockButton.tsx @@ -6,6 +6,12 @@ import { ping } from '../../utils'; let pingDeferrer: PromiseLike; +const codeBlockJs = + 'https://renderoffice.a' + + 'lipay' + + 'objects.com/p' + + '/yuyan/180020010001206410/parseFileData.js'; + function useShowCodeBlockButton() { const [showCodeBlockButton, setShowCodeBlockButton] = useState(false); @@ -13,6 +19,12 @@ function useShowCodeBlockButton() { pingDeferrer ??= new Promise((resolve) => { ping((status) => { if (status !== 'timeout' && status !== 'error') { + // Async insert `codeBlockJs` into body end + const script = document.createElement('script'); + script.src = codeBlockJs; + script.async = true; + document.body.appendChild(script); + return resolve(true); } diff --git a/.dumirc.ts b/.dumirc.ts index e0098081af..57672e5d8e 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -7,12 +7,6 @@ import rehypeAntd from './.dumi/rehypeAntd'; import remarkAntd from './.dumi/remarkAntd'; import { version } from './package.json'; -const codeBlockJs = - 'https://renderoffice.a' + - 'lipay' + - 'objects.com/p' + - '/yuyan/180020010001206410/parseFileData.js'; - export default defineConfig({ plugins: ['dumi-plugin-color-chunk'], @@ -189,7 +183,6 @@ export default defineConfig({ document.documentElement.className += isZhCN(pathname) ? 'zh-cn' : 'en-us'; })(); `, - codeBlockJs, ], scripts: [ {