Skip to content

Commit

Permalink
feat: fix to #750 :enhance devtools container management with mutatio…
Browse files Browse the repository at this point in the history
…n observer
  • Loading branch information
陆德靖 authored and 陆德靖 committed Dec 21, 2024
1 parent a9c56bd commit 06f5d42
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/overlay/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Component } from 'vue'
import type { Component, App as VueAppType } from 'vue'
import { createApp, h } from 'vue'

import App from './App.vue'

let app: VueAppType
function createDevToolsContainer(App: Component) {
const CONTAINER_ID = '__vue-devtools-container__'
const el = document.createElement('div')
el.setAttribute('id', CONTAINER_ID)
el.setAttribute('data-v-inspector-ignore', 'true')
document.getElementsByTagName('body')[0].appendChild(el)
const app = createApp({
app = createApp({
render: () => h(App),
devtools: {
hide: true,
Expand All @@ -19,3 +19,22 @@ function createDevToolsContainer(App: Component) {
}

createDevToolsContainer(App)

const targetNode = document.body
const config = { childList: true, attributes: false }
const observer = new MutationObserver(callback)
observer.observe(targetNode, config)

let init = false
function callback(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList' && init === false) {
if (app) {
app.unmount()
}
createDevToolsContainer(App)
init = true
observer.disconnect()
}
}
}

0 comments on commit 06f5d42

Please sign in to comment.