Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: fix to #750 :enhance devtools container management with mutatio…
…n observer
  • Loading branch information
陆德靖 authored and 陆德靖 committed Dec 21, 2024
commit 06f5d4286f99d70ad0080305852248a63d75d67d
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()
}
Comment on lines +32 to +34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with createDevToolsContainer (line 21) appending the devtool app in the DOM, wouldn't this systematically trigger ? making the callback unmount and re-mount the app for nothing ?

createDevToolsContainer(App)
init = true
observer.disconnect()
}
}
}
Loading