]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore(repl): avoid duplicate formatter mounts (#10472)
author白雾三语 <32354856+baiwusanyu-c@users.noreply.github.com>
Thu, 11 Jul 2024 09:30:41 +0000 (17:30 +0800)
committerGitHub <noreply@github.com>
Thu, 11 Jul 2024 09:30:41 +0000 (17:30 +0800)
close #10466

packages/runtime-core/src/customFormatter.ts
packages/sfc-playground/src/App.vue

index abd3a329922677c81763a5c3147298395f7397bf..9cda478345c7a9c66a1e5a23041e77671e45ec16 100644 (file)
@@ -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)) {
index 4b62519ce6ecf1cb9d06dc37302155ed44129409..7501b200ce839fbec7494cab3d5d97afa2ab814f 100644 (file)
@@ -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()
+  }`,
       },
     }"
   />