From: 白雾三语 <32354856+baiwusanyu-c@users.noreply.github.com> Date: Thu, 11 Jul 2024 09:30:41 +0000 (+0800) Subject: chore(repl): avoid duplicate formatter mounts (#10472) X-Git-Tag: v3.4.32~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=23cd61423c1201eb948a21d6be0a8b9049080ce0;p=thirdparty%2Fvuejs%2Fcore.git chore(repl): avoid duplicate formatter mounts (#10472) close #10466 --- diff --git a/packages/runtime-core/src/customFormatter.ts b/packages/runtime-core/src/customFormatter.ts index abd3a32992..9cda478345 100644 --- a/packages/runtime-core/src/customFormatter.ts +++ b/packages/runtime-core/src/customFormatter.ts @@ -24,6 +24,7 @@ export function initCustomFormatter() { // custom formatter for Chrome // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html const formatter = { + __vue_custom_formatter: true, header(obj: unknown) { // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup if (!isObject(obj)) { diff --git a/packages/sfc-playground/src/App.vue b/packages/sfc-playground/src/App.vue index 4b62519ce6..7501b200ce 100644 --- a/packages/sfc-playground/src/App.vue +++ b/packages/sfc-playground/src/App.vue @@ -129,7 +129,13 @@ onMounted(() => { :preview-options="{ customCode: { importCode: `import { initCustomFormatter } from 'vue'`, - useCode: `initCustomFormatter()`, + useCode: `if (window.devtoolsFormatters) { + const index = window.devtoolsFormatters.findIndex((v) => v.__vue_custom_formatter) + window.devtoolsFormatters.splice(index, 1) + initCustomFormatter() + } else { + initCustomFormatter() + }`, }, }" />