Skip to content

Commit 06f5d42

Browse files
陆德靖陆德靖
陆德靖
authored and
陆德靖
committed
feat: fix to vuejs#750 :enhance devtools container management with mutation observer
1 parent a9c56bd commit 06f5d42

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

packages/overlay/src/main.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import type { Component } from 'vue'
1+
import type { Component, App as VueAppType } from 'vue'
22
import { createApp, h } from 'vue'
3-
43
import App from './App.vue'
54

5+
let app: VueAppType
66
function createDevToolsContainer(App: Component) {
77
const CONTAINER_ID = '__vue-devtools-container__'
88
const el = document.createElement('div')
99
el.setAttribute('id', CONTAINER_ID)
1010
el.setAttribute('data-v-inspector-ignore', 'true')
1111
document.getElementsByTagName('body')[0].appendChild(el)
12-
const app = createApp({
12+
app = createApp({
1313
render: () => h(App),
1414
devtools: {
1515
hide: true,
@@ -19,3 +19,22 @@ function createDevToolsContainer(App: Component) {
1919
}
2020

2121
createDevToolsContainer(App)
22+
23+
const targetNode = document.body
24+
const config = { childList: true, attributes: false }
25+
const observer = new MutationObserver(callback)
26+
observer.observe(targetNode, config)
27+
28+
let init = false
29+
function callback(mutationsList, observer) {
30+
for (const mutation of mutationsList) {
31+
if (mutation.type === 'childList' && init === false) {
32+
if (app) {
33+
app.unmount()
34+
}
35+
createDevToolsContainer(App)
36+
init = true
37+
observer.disconnect()
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)