Skip to content

Commit

Permalink
fix(repl): Avoid duplicate formatter mounts
Browse files Browse the repository at this point in the history
  • Loading branch information
baiwusanyu-c committed Mar 7, 2024
1 parent e76d743 commit 7d1226f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/runtime-core/src/customFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
__formater_key: 'vue-custom-formatter',
header(obj: unknown) {
// TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
if (!isObject(obj)) {
Expand Down Expand Up @@ -198,7 +199,12 @@ export function initCustomFormatter() {
}

if ((window as any).devtoolsFormatters) {
;(window as any).devtoolsFormatters.push(formatter)
const has = (window as any).devtoolsFormatters.some(
(v: typeof formatter) => {
return v.__formater_key && v.__formater_key === formatter.__formater_key
},
)
!has && (window as any).devtoolsFormatters.push(formatter)
} else {
;(window as any).devtoolsFormatters = [formatter]
}
Expand Down

0 comments on commit 7d1226f

Please sign in to comment.